Add support for Stratum over TLS
This commit is contained in:
parent
07fb67e8af
commit
ef6f5beeae
3 changed files with 30 additions and 10 deletions
|
@ -1617,7 +1617,8 @@ static void parse_arg(int key, char *arg, char *pname)
|
||||||
if (ap != arg) {
|
if (ap != arg) {
|
||||||
if (strncasecmp(arg, "http://", 7) &&
|
if (strncasecmp(arg, "http://", 7) &&
|
||||||
strncasecmp(arg, "https://", 8) &&
|
strncasecmp(arg, "https://", 8) &&
|
||||||
strncasecmp(arg, "stratum+tcp://", 14)) {
|
strncasecmp(arg, "stratum+tcp://", 14) &&
|
||||||
|
strncasecmp(arg, "stratum+tcps://", 15)) {
|
||||||
fprintf(stderr, "%s: unknown protocol -- '%s'\n",
|
fprintf(stderr, "%s: unknown protocol -- '%s'\n",
|
||||||
pname, arg);
|
pname, arg);
|
||||||
show_usage_and_exit(1);
|
show_usage_and_exit(1);
|
||||||
|
@ -1828,7 +1829,8 @@ int main(int argc, char *argv[])
|
||||||
pthread_mutex_init(&stratum.sock_lock, NULL);
|
pthread_mutex_init(&stratum.sock_lock, NULL);
|
||||||
pthread_mutex_init(&stratum.work_lock, NULL);
|
pthread_mutex_init(&stratum.work_lock, NULL);
|
||||||
|
|
||||||
flags = !opt_benchmark && strncmp(rpc_url, "https:", 6)
|
flags = opt_benchmark || (strncasecmp(rpc_url, "https://", 8) &&
|
||||||
|
strncasecmp(rpc_url, "stratum+tcps://", 15))
|
||||||
? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)
|
? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)
|
||||||
: CURL_GLOBAL_ALL;
|
: CURL_GLOBAL_ALL;
|
||||||
if (curl_global_init(flags)) {
|
if (curl_global_init(flags)) {
|
||||||
|
|
3
minerd.1
3
minerd.1
|
@ -137,7 +137,8 @@ Do not switch to Stratum, even if the server advertises support for it.
|
||||||
.TP
|
.TP
|
||||||
\fB\-o\fR, \fB\-\-url\fR=[\fISCHEME\fR://][\fIUSERNAME\fR[:\fIPASSWORD\fR]@]\fIHOST\fR:\fIPORT\fR[/\fIPATH\fR]
|
\fB\-o\fR, \fB\-\-url\fR=[\fISCHEME\fR://][\fIUSERNAME\fR[:\fIPASSWORD\fR]@]\fIHOST\fR:\fIPORT\fR[/\fIPATH\fR]
|
||||||
Set the URL of the mining server to connect to.
|
Set the URL of the mining server to connect to.
|
||||||
Supported schemes are \fBhttp\fR, \fBhttps\fR and \fBstratum+tcp\fR.
|
Supported schemes are \fBhttp\fR, \fBhttps\fR, \fBstratum+tcp\fR
|
||||||
|
and \fBstratum+tcps\fR.
|
||||||
If no scheme is specified, http is assumed.
|
If no scheme is specified, http is assumed.
|
||||||
Specifying a \fIPATH\fR is only supported for HTTP and HTTPS.
|
Specifying a \fIPATH\fR is only supported for HTTP and HTTPS.
|
||||||
Specifying credentials has the same effect as using the \fB\-O\fR option.
|
Specifying credentials has the same effect as using the \fB\-O\fR option.
|
||||||
|
|
31
util.c
31
util.c
|
@ -770,7 +770,7 @@ void diff_to_target(uint32_t *target, double diff)
|
||||||
#define socket_blocks() (errno == EAGAIN || errno == EWOULDBLOCK)
|
#define socket_blocks() (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool send_line(curl_socket_t sock, char *s)
|
static bool send_line(struct stratum_ctx *sctx, char *s)
|
||||||
{
|
{
|
||||||
ssize_t len, sent = 0;
|
ssize_t len, sent = 0;
|
||||||
|
|
||||||
|
@ -783,12 +783,18 @@ static bool send_line(curl_socket_t sock, char *s)
|
||||||
fd_set wd;
|
fd_set wd;
|
||||||
|
|
||||||
FD_ZERO(&wd);
|
FD_ZERO(&wd);
|
||||||
FD_SET(sock, &wd);
|
FD_SET(sctx->sock, &wd);
|
||||||
if (select(sock + 1, NULL, &wd, NULL, &timeout) < 1)
|
if (select(sctx->sock + 1, NULL, &wd, NULL, &timeout) < 1)
|
||||||
return false;
|
return false;
|
||||||
n = send(sock, s + sent, len, 0);
|
#if LIBCURL_VERSION_NUM >= 0x071202
|
||||||
|
CURLcode rc = curl_easy_send(sctx->curl, s + sent, len, (size_t *)&n);
|
||||||
|
if (rc != CURLE_OK) {
|
||||||
|
if (rc != CURLE_AGAIN)
|
||||||
|
#else
|
||||||
|
n = send(sctx->sock, s + sent, len, 0);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (!socket_blocks())
|
if (!socket_blocks())
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
@ -807,7 +813,7 @@ bool stratum_send_line(struct stratum_ctx *sctx, char *s)
|
||||||
applog(LOG_DEBUG, "> %s", s);
|
applog(LOG_DEBUG, "> %s", s);
|
||||||
|
|
||||||
pthread_mutex_lock(&sctx->sock_lock);
|
pthread_mutex_lock(&sctx->sock_lock);
|
||||||
ret = send_line(sctx->sock, s);
|
ret = send_line(sctx, s);
|
||||||
pthread_mutex_unlock(&sctx->sock_lock);
|
pthread_mutex_unlock(&sctx->sock_lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -867,6 +873,15 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
memset(s, 0, RBUFSIZE);
|
memset(s, 0, RBUFSIZE);
|
||||||
|
#if LIBCURL_VERSION_NUM >= 0x071202
|
||||||
|
CURLcode rc = curl_easy_recv(sctx->curl, s, RECVSIZE, (size_t *)&n);
|
||||||
|
if (rc == CURLE_OK && !n) {
|
||||||
|
ret = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (rc != CURLE_OK) {
|
||||||
|
if (rc != CURLE_AGAIN || !socket_full(sctx->sock, 1)) {
|
||||||
|
#else
|
||||||
n = recv(sctx->sock, s, RECVSIZE, 0);
|
n = recv(sctx->sock, s, RECVSIZE, 0);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
ret = false;
|
ret = false;
|
||||||
|
@ -874,6 +889,7 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||||
}
|
}
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (!socket_blocks() || !socket_full(sctx->sock, 1)) {
|
if (!socket_blocks() || !socket_full(sctx->sock, 1)) {
|
||||||
|
#endif
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -945,7 +961,7 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url)
|
||||||
}
|
}
|
||||||
free(sctx->curl_url);
|
free(sctx->curl_url);
|
||||||
sctx->curl_url = malloc(strlen(url));
|
sctx->curl_url = malloc(strlen(url));
|
||||||
sprintf(sctx->curl_url, "http%s", strstr(url, "://"));
|
sprintf(sctx->curl_url, "http%s", url + 11);
|
||||||
|
|
||||||
if (opt_protocol)
|
if (opt_protocol)
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||||
|
@ -1289,7 +1305,8 @@ static bool stratum_reconnect(struct stratum_ctx *sctx, json_t *params)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
url = malloc(32 + strlen(host));
|
url = malloc(32 + strlen(host));
|
||||||
sprintf(url, "stratum+tcp://%s:%d", host, port);
|
strncpy(url, sctx->url, 15);
|
||||||
|
sprintf(strstr(url, "://") + 3, "%s:%d", host, port);
|
||||||
|
|
||||||
if (!opt_redirect) {
|
if (!opt_redirect) {
|
||||||
applog(LOG_INFO, "Ignoring request to reconnect to %s", url);
|
applog(LOG_INFO, "Ignoring request to reconnect to %s", url);
|
||||||
|
|
Loading…
Reference in a new issue