diff --git a/src/ckpool.h b/src/ckpool.h index 5c4529c0..0829d36c 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -257,6 +257,7 @@ enum stratum_msgtype { SM_AUTHRESULT, SM_TXNS, SM_TXNSRESULT, + SM_PING, SM_WORKINFO, SM_NONE }; @@ -275,6 +276,7 @@ static const char __maybe_unused *stratum_msgs[] = { "auth.result", "txns", "txns.result", + "ping", "workinfo", "" }; diff --git a/src/stratifier.c b/src/stratifier.c index 66b9bd33..e87fc7e4 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2253,10 +2253,16 @@ static void connector_test_client(ckpool_t *ckp, const int64_t id) send_proc(ckp->connector, buf); } +/* passthrough subclients have client_ids in the high bits */ +static inline bool passthrough_subclient(const int64_t client_id) +{ + return (client_id > 0xffffffffll); +} + /* For creating a list of sends without locking that can then be concatenated * to the stratum_sends list. Minimises locking and avoids taking recursive * locks. Sends only to sdata bound clients (everyone in ckpool) */ -static void stratum_broadcast(sdata_t *sdata, json_t *val) +static void stratum_broadcast(sdata_t *sdata, json_t *val, const int msg_type) { ckpool_t *ckp = sdata->ckp; sdata_t *ckp_sdata = ckp->data; @@ -2307,6 +2313,8 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val) continue; client_msg = ckalloc(sizeof(ckmsg_t)); msg = ckzalloc(sizeof(smsg_t)); + if (passthrough_subclient(client->id)) + json_set_string(val, "node.method", stratum_msgs[msg_type]); msg->json_msg = json_deep_copy(val); msg->client_id = client->id; client_msg->data = msg; @@ -2330,12 +2338,6 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val) mutex_unlock(ssends->lock); } -/* passthrough subclients have client_ids in the high bits */ -static inline bool passthrough_subclient(const int64_t client_id) -{ - return (client_id > 0xffffffffll); -} - static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_id, const int msg_type) { @@ -2390,7 +2392,7 @@ static void stratum_broadcast_message(sdata_t *sdata, const char *msg) JSON_CPACK(json_msg, "{sosss[s]}", "id", json_null(), "method", "client.show_message", "params", msg); - stratum_broadcast(sdata, json_msg); + stratum_broadcast(sdata, json_msg, SM_MSG); } /* Send a generic reconnect to all clients without parameters to make them @@ -2410,7 +2412,7 @@ static void request_reconnect(sdata_t *sdata, const char *cmd) } else JSON_CPACK(json_msg, "{sosss[]}", "id", json_null(), "method", "client.reconnect", "params"); - stratum_broadcast(sdata, json_msg); + stratum_broadcast(sdata, json_msg, SM_RECONNECT); /* Tag all existing clients as dropped now so they can be removed * lazily */ @@ -2655,7 +2657,7 @@ static void broadcast_ping(sdata_t *sdata) "id", 42, "method", "mining.ping"); - stratum_broadcast(sdata, json_msg); + stratum_broadcast(sdata, json_msg, SM_PING); } static void ckmsgq_stats(ckmsgq_t *ckmsgq, const int size, json_t **val) @@ -5037,7 +5039,7 @@ static void stratum_broadcast_update(sdata_t *sdata, const workbase_t *wb, const json_msg = __stratum_notify(wb, clean); ck_runlock(&sdata->workbase_lock); - stratum_broadcast(sdata, json_msg); + stratum_broadcast(sdata, json_msg, SM_UPDATE); } /* For sending a single stratum template update */