Browse Source

Fix passthrough breakage, keeping passthrough parent client reference around, flagged as such.

master
Con Kolivas 8 years ago
parent
commit
5aa4b2bd10
  1. 44
      src/stratifier.c

44
src/stratifier.c

@ -314,6 +314,7 @@ struct stratum_instance {
int proxyid; /* Which proxy id */ int proxyid; /* Which proxy id */
int subproxyid; /* Which subproxy */ int subproxyid; /* Which subproxy */
bool passthrough; /* Is this a passthrough */
bool trusted; /* Is this a trusted remote server */ bool trusted; /* Is this a trusted remote server */
bool remote; /* Is this a remote client on a trusted remote server */ bool remote; /* Is this a remote client on a trusted remote server */
}; };
@ -890,9 +891,6 @@ static void send_postponed(sdata_t *sdata)
mutex_unlock(ssends->lock); mutex_unlock(ssends->lock);
} }
static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_id,
const int msg_type);
/* Strip fields that will be recreated upstream or won't be used to minimise /* Strip fields that will be recreated upstream or won't be used to minimise
* bandwidth. */ * bandwidth. */
static void strip_fields(ckpool_t *ckp, json_t *val) static void strip_fields(ckpool_t *ckp, json_t *val)
@ -1783,7 +1781,7 @@ share_diff(char *coinbase, const uchar *enonce1bin, const workbase_t *wb, const
} }
/* passthrough subclients have client_ids in the high bits */ /* passthrough subclients have client_ids in the high bits */
static inline bool passthrough_subclient(const int64_t client_id) static inline bool subclient(const int64_t client_id)
{ {
return (client_id > 0xffffffffll); return (client_id > 0xffffffffll);
} }
@ -1799,7 +1797,7 @@ static void send_node_block(sdata_t *sdata, const char *enonce1, const char *non
/* Don't send the block back to a remote node if that's where it was /* Don't send the block back to a remote node if that's where it was
* found. */ * found. */
if (passthrough_subclient(client_id)) if (subclient(client_id))
skip = client_id >> 32; skip = client_id >> 32;
else else
skip = 0; skip = 0;
@ -3092,21 +3090,24 @@ static stratum_instance_t *__stratum_add_instance(ckpool_t *ckp, int64_t id, con
/* Points to ckp sdata in ckpool mode, but is changed later in proxy /* Points to ckp sdata in ckpool mode, but is changed later in proxy
* mode . */ * mode . */
client->sdata = sdata; client->sdata = sdata;
if (passthrough_subclient(id)) { if (subclient(id)) {
stratum_instance_t *passthrough; stratum_instance_t *remote;
int64_t pass_id = id >> 32; int64_t pass_id = id >> 32;
id &= 0xffffffffll; id &= 0xffffffffll;
passthrough = __instance_by_id(sdata, pass_id); remote = __instance_by_id(sdata, pass_id);
if (passthrough && passthrough->node) { if (remote && remote->node) {
client->latency = passthrough->latency; client->latency = remote->latency;
LOGINFO("Client %s inherited node latency of %d", LOGINFO("Client %s inherited node latency of %d",
client->identity, client->latency); client->identity, client->latency);
sprintf(client->identity, "node:%"PRId64" subclient:%"PRId64, sprintf(client->identity, "node:%"PRId64" subclient:%"PRId64,
pass_id, id); pass_id, id);
} else { } else if (remote && remote->trusted) {
sprintf(client->identity, "remote:%"PRId64" subclient:%"PRId64, sprintf(client->identity, "remote:%"PRId64" subclient:%"PRId64,
pass_id, id); pass_id, id);
} else { /* remote->passthrough remaining */
sprintf(client->identity, "passthrough:%"PRId64" subclient:%"PRId64,
pass_id, id);
} }
} else } else
sprintf(client->identity, "%"PRId64, id); sprintf(client->identity, "%"PRId64, id);
@ -3191,7 +3192,7 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val, const int msg_type)
client_msg = ckalloc(sizeof(ckmsg_t)); client_msg = ckalloc(sizeof(ckmsg_t));
msg = ckzalloc(sizeof(smsg_t)); msg = ckzalloc(sizeof(smsg_t));
if (passthrough_subclient(client->id)) if (subclient(client->id))
json_set_string(val, "node.method", stratum_msgs[msg_type]); json_set_string(val, "node.method", stratum_msgs[msg_type]);
msg->json_msg = json_deep_copy(val); msg->json_msg = json_deep_copy(val);
msg->client_id = client->id; msg->client_id = client->id;
@ -3222,7 +3223,7 @@ static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_i
return; return;
} }
if (passthrough_subclient(client_id)) { if (subclient(client_id)) {
int64_t remote_id = client_id >> 32; int64_t remote_id = client_id >> 32;
stratum_instance_t *remote; stratum_instance_t *remote;
@ -3231,10 +3232,10 @@ static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_i
json_decref(val); json_decref(val);
return; return;
} }
if (remote->node) if (remote->trusted)
json_set_string(val, "node.method", stratum_msgs[msg_type]);
else if (remote->trusted)
json_set_string(val, "method", stratum_msgs[msg_type]); json_set_string(val, "method", stratum_msgs[msg_type]);
else /* Both remote->node and remote->passthrough */
json_set_string(val, "node.method", stratum_msgs[msg_type]);
dec_instance_ref(sdata, remote); dec_instance_ref(sdata, remote);
} }
LOGDEBUG("Sending stratum message %s", stratum_msgs[msg_type]); LOGDEBUG("Sending stratum message %s", stratum_msgs[msg_type]);
@ -4688,7 +4689,7 @@ static json_t *parse_subscribe(stratum_instance_t *client, const int64_t client_
session_id = int_from_sessionid(buf); session_id = int_from_sessionid(buf);
LOGDEBUG("Found old session id %d", session_id); LOGDEBUG("Found old session id %d", session_id);
} }
if (!ckp->proxy && session_id && !passthrough_subclient(client_id)) { if (!ckp->proxy && session_id && !subclient(client_id)) {
if ((client->enonce1_64 = disconnected_sessionid_exists(sdata, session_id, client_id))) { if ((client->enonce1_64 = disconnected_sessionid_exists(sdata, session_id, client_id))) {
sprintf(client->enonce1, "%016lx", client->enonce1_64); sprintf(client->enonce1, "%016lx", client->enonce1_64);
old_match = true; old_match = true;
@ -6377,14 +6378,13 @@ static void parse_method(ckpool_t *ckp, sdata_t *sdata, stratum_instance_t *clie
connector_drop_client(ckp, client_id); connector_drop_client(ckp, client_id);
drop_client(ckp, sdata, client_id); drop_client(ckp, sdata, client_id);
} else { } else {
/* We need to inform the connector process that this client /* We need is a passthrough and to manage its messages
* is a passthrough and to manage its messages accordingly. No * accordingly. No data from this client id should ever
* data from this client id should ever come back to this * come directly back to this stratifier. */
* stratifier after this so drop the client in the stratifier. */
LOGNOTICE("Adding passthrough client %s %s", client->identity, client->address); LOGNOTICE("Adding passthrough client %s %s", client->identity, client->address);
client->passthrough = true;
snprintf(buf, 255, "passthrough=%"PRId64, client_id); snprintf(buf, 255, "passthrough=%"PRId64, client_id);
send_proc(ckp->connector, buf); send_proc(ckp->connector, buf);
drop_client(ckp, sdata, client_id);
sprintf(client->identity, "passthrough:%"PRId64, client_id); sprintf(client->identity, "passthrough:%"PRId64, client_id);
} }
return; return;

Loading…
Cancel
Save