diff --git a/src/ckpool.h b/src/ckpool.h index b5cda264..eb78eb55 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -256,7 +256,9 @@ struct ckpool_instance { char **redirectport; /* Private data for each process */ - void *data; + void *gdata; + void *sdata; + void *cdata; }; enum stratum_msgtype { diff --git a/src/connector.c b/src/connector.c index bb3fea45..65819160 100644 --- a/src/connector.c +++ b/src/connector.c @@ -569,7 +569,7 @@ static void client_event_processor(ckpool_t *ckp, struct epoll_event *event) { const uint32_t events = event->events; const uint64_t id = event->data.u64; - cdata_t *cdata = ckp->data; + cdata_t *cdata = ckp->cdata; client_instance_t *client; client = ref_client_by_id(cdata, id); @@ -825,7 +825,7 @@ static int add_redirect(ckpool_t *ckp, cdata_t *cdata, client_instance_t *client static void redirect_client(ckpool_t *ckp, client_instance_t *client) { sender_send_t *sender_send; - cdata_t *cdata = ckp->data; + cdata_t *cdata = ckp->cdata; json_t *val; char *buf; int num; @@ -1089,7 +1089,7 @@ out: static void usend_process(ckpool_t *ckp, char *buf) { - cdata_t *cdata = ckp->data; + cdata_t *cdata = ckp->cdata; connsock_t *cs = &cdata->upstream_cs; int len, sent; @@ -1139,7 +1139,7 @@ static void ping_upstream(cdata_t *cdata) static void *urecv_process(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - cdata_t *cdata = ckp->data; + cdata_t *cdata = ckp->cdata; connsock_t *cs = &cdata->upstream_cs; bool alive = true; @@ -1246,7 +1246,7 @@ static void client_message_processor(ckpool_t *ckp, char *buf) json_object_set_new_nocheck(json_msg, "client_id", json_integer(client_id & 0xffffffffll)); msg = json_dumps(json_msg, JSON_EOL | JSON_COMPACT); - send_client(ckp->data, client_id, msg); + send_client(ckp->cdata, client_id, msg); json_decref(json_msg); out: free(buf); @@ -1474,7 +1474,7 @@ int connector(proc_instance_t *pi) const int on = 1; LOGWARNING("%s connector starting", ckp->name); - ckp->data = cdata; + ckp->cdata = cdata; cdata->ckp = ckp; if (!ckp->serverurls) @@ -1590,6 +1590,6 @@ int connector(proc_instance_t *pi) ret = connector_loop(pi, cdata); out: - dealloc(ckp->data); + dealloc(ckp->cdata); return process_exit(ckp, pi, ret); } diff --git a/src/generator.c b/src/generator.c index f5fa7f2d..3efff2da 100644 --- a/src/generator.c +++ b/src/generator.c @@ -793,7 +793,7 @@ static void reconnect_generator(const ckpool_t *ckp) static bool parse_notify(ckpool_t *ckp, proxy_instance_t *proxi, json_t *val) { const char *prev_hash, *bbversion, *nbit, *ntime; - gdata_t *gdata = proxi->ckp->data; + gdata_t *gdata = proxi->ckp->gdata; char *coinbase1, *coinbase2; const char *jobidbuf; bool clean, ret = false; @@ -1026,7 +1026,7 @@ static bool parse_reconnect(proxy_instance_t *proxy, json_t *val) { bool sameurl = false, ret = false; ckpool_t *ckp = proxy->ckp; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; proxy_instance_t *parent; const char *new_url; int new_port; @@ -1318,7 +1318,7 @@ out: LOGNOTICE("Disabling userproxy %d:%d %s that failed authorisation as %s", proxi->id, proxi->subid, proxi->url, proxi->auth); proxi->disabled = true; - disable_subproxy(ckp->data, proxi->parent, proxi); + disable_subproxy(ckp->gdata, proxi->parent, proxi); } return ret; } @@ -1626,7 +1626,7 @@ static void add_json_msgq(cs_msg_t **csmsgq, proxy_instance_t *proxy, json_t **v static void *proxy_send(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; stratum_msg_t *msg = NULL; cs_msg_t *csmsgq = NULL; @@ -1837,7 +1837,7 @@ static void *proxy_recruit(void *arg) { proxy_instance_t *proxy, *parent = (proxy_instance_t *)arg; ckpool_t *ckp = parent->ckp; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; bool recruit, alive; pthread_detach(pthread_self()); @@ -1996,7 +1996,7 @@ static void *proxy_recv(void *arg) connsock_t *cs = &proxi->cs; proxy_instance_t *subproxy; ckpool_t *ckp = proxi->ckp; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; struct epoll_event event; bool alive; int epfd; @@ -2112,7 +2112,7 @@ static void *proxy_recv(void *arg) static void *userproxy_recv(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; struct epoll_event event; int epfd; @@ -2683,7 +2683,7 @@ static int proxy_loop(proc_instance_t *pi) proxy_instance_t *proxi = NULL, *cproxy; server_instance_t *si = NULL, *old_si; ckpool_t *ckp = pi->ckp; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; unix_msg_t *umsg = NULL; connsock_t *cs = NULL; bool started = false; @@ -2799,7 +2799,7 @@ out: static void *server_watchdog(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; while (42) { server_instance_t *best = NULL; @@ -2890,7 +2890,7 @@ static proxy_instance_t *__add_proxy(ckpool_t *ckp, gdata_t *gdata, const int id static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) { - gdata_t *gdata = ckp->data; + gdata_t *gdata = ckp->gdata; proxy_instance_t *proxy; int i, ret; @@ -2929,7 +2929,7 @@ int generator(proc_instance_t *pi) LOGWARNING("%s generator starting", ckp->name); gdata = ckzalloc(sizeof(gdata_t)); - ckp->data = gdata; + ckp->gdata = gdata; gdata->ckp = ckp; create_unix_receiver(pi); @@ -2950,6 +2950,6 @@ int generator(proc_instance_t *pi) } else ret = server_mode(ckp, pi); out: - dealloc(ckp->data); + dealloc(ckp->gdata); return process_exit(ckp, pi, ret); } diff --git a/src/stratifier.c b/src/stratifier.c index 766d3c97..c6cd4214 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -569,7 +569,7 @@ static void info_msg_entries(char_entry_t **entries) static void generate_coinbase(const ckpool_t *ckp, workbase_t *wb) { uint64_t *u64, g64, d64 = 0; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char header[228]; int len, ofs = 0; ts_t now; @@ -773,7 +773,7 @@ static void _ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val, const char const char *func, const int line) { static time_t time_counter; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; static int counter = 0; char *json_msg; time_t now_t; @@ -986,7 +986,7 @@ static void send_ageworkinfo(ckpool_t *ckp, const int64_t id) static void add_base(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, bool *new_block) { workbase_t *tmp, *tmpa, *aged = NULL; - sdata_t *ckp_sdata = ckp->data; + sdata_t *ckp_sdata = ckp->sdata; int len, ret; ts_realtime(&wb->gentime); @@ -1065,7 +1065,7 @@ static void add_base(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, bool *new_bl * read the wrong priority but occasional wrong values are harmless. */ static char *__send_recv_generator(ckpool_t *ckp, const char *msg, const int prio) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char *buf = NULL; bool set; @@ -1088,7 +1088,7 @@ static char *__send_recv_generator(ckpool_t *ckp, const char *msg, const int pri * processed for priority reasons, "failed" for an actual failure. */ static char *send_recv_generator(ckpool_t *ckp, const char *msg, const int prio) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char *buf = NULL; if (prio >= sdata->gen_priority) @@ -1098,7 +1098,7 @@ static char *send_recv_generator(ckpool_t *ckp, const char *msg, const int prio) static void send_generator(const ckpool_t *ckp, const char *msg, const int prio) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; bool set; if (prio > sdata->gen_priority) { @@ -1316,7 +1316,7 @@ static void *do_update(void *arg) struct update_req *ur = (struct update_req *)arg; int prio = ur->prio, retries = 0; ckpool_t *ckp = ur->ckp; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; json_t *val, *txn_array; bool new_block = false; bool ret = false; @@ -1458,7 +1458,7 @@ out_unlock: static void add_node_base(ckpool_t *ckp, json_t *val) { workbase_t *wb = ckzalloc(sizeof(workbase_t)); - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; bool new_block = false; json_t *txnhashes; char header[228]; @@ -1658,7 +1658,7 @@ static void upstream_blocksubmit(ckpool_t *ckp, const char *gbt_block) static void downstream_blocksubmits(ckpool_t *ckp, const char *gbt_block, const stratum_instance_t *source) { stratum_instance_t *client; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; ckmsg_t *bulk_send = NULL; int messages = 0; @@ -1933,7 +1933,7 @@ static void connector_drop_client(ckpool_t *ckp, const int64_t id) static void drop_allclients(ckpool_t *ckp) { stratum_instance_t *client, *tmp; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; int kills = 0; ck_wlock(&sdata->instance_lock); @@ -2323,7 +2323,7 @@ static void dead_proxyid(sdata_t *sdata, const int id, const int subid, const bo static void update_subscribe(ckpool_t *ckp, const char *cmd) { - sdata_t *sdata = ckp->data, *dsdata; + sdata_t *sdata = ckp->sdata, *dsdata; int id = 0, subid = 0, userid = 0; proxy_t *proxy, *old = NULL; const char *buf; @@ -2486,7 +2486,7 @@ static proxy_t *best_proxy(sdata_t *sdata) static void update_notify(ckpool_t *ckp, const char *cmd) { - sdata_t *sdata = ckp->data, *dsdata; + sdata_t *sdata = ckp->sdata, *dsdata; bool new_block = false, clean; int i, id = 0, subid = 0; char header[228]; @@ -2591,7 +2591,7 @@ static void stratum_send_diff(sdata_t *sdata, const stratum_instance_t *client); static void update_diff(ckpool_t *ckp, const char *cmd) { - sdata_t *sdata = ckp->data, *dsdata; + sdata_t *sdata = ckp->sdata, *dsdata; stratum_instance_t *client, *tmp; double old_diff, diff; int id = 0, subid = 0; @@ -2834,7 +2834,7 @@ static stratum_instance_t *__stratum_add_instance(ckpool_t *ckp, const int64_t i const char *address, int server) { stratum_instance_t *client; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; client = __recruit_stratum_instance(sdata); client->start_time = time(NULL); @@ -2912,7 +2912,7 @@ static void connector_test_client(ckpool_t *ckp, const int64_t id) 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; + sdata_t *ckp_sdata = ckp->sdata; stratum_instance_t *client, *tmp; ckmsg_t *bulk_send = NULL; int messages = 0; @@ -3158,7 +3158,7 @@ static void block_solve(ckpool_t *ckp, const char *blockhash) { ckmsg_t *block, *tmp, *found = NULL; char *msg, *workername = NULL; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char cdfield[64]; double diff = 0; int height = 0; @@ -3939,7 +3939,7 @@ static void ckdbq_flush(sdata_t *sdata) static int stratum_loop(ckpool_t *ckp, proc_instance_t *pi) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; unix_msg_t *umsg = NULL; int ret = 0; char *buf; @@ -4114,7 +4114,7 @@ out: static void *blockupdate(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char *buf = NULL; char request[8]; @@ -4343,7 +4343,7 @@ out_unlock: static json_t *parse_subscribe(stratum_instance_t *client, const int64_t client_id, const json_t *params_val) { ckpool_t *ckp = client->ckp; - sdata_t *sdata, *ckp_sdata = ckp->data; + sdata_t *sdata, *ckp_sdata = ckp->sdata; int session_id = 0, userid = -1; bool old_match = false; char sessionid[12]; @@ -4747,7 +4747,7 @@ static user_instance_t *generate_user(ckpool_t *ckp, stratum_instance_t *client, { char *base_username = strdupa(workername), *username; bool new_user = false, new_worker = false; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; worker_instance_t *worker; user_instance_t *user; int len; @@ -4807,7 +4807,7 @@ static int send_recv_auth(stratum_instance_t *client) { user_instance_t *user = client->user_instance; ckpool_t *ckp = client->ckp; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; char *buf = NULL, *json_msg; bool contended = false; size_t responselen = 0; @@ -4951,7 +4951,7 @@ static void queue_delayed_auth(stratum_instance_t *client) static void check_global_user(ckpool_t *ckp, user_instance_t *user, stratum_instance_t *client) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; proxy_t *proxy = best_proxy(sdata); int proxyid = proxy->id; char buf[256]; @@ -5127,7 +5127,7 @@ static void upstream_shares(ckpool_t *ckp, const char *workername, const int64_t static void add_submit(ckpool_t *ckp, stratum_instance_t *client, const double diff, const bool valid, const bool submit, const double sdiff) { - sdata_t *ckp_sdata = ckp->data, *sdata = client->sdata; + sdata_t *ckp_sdata = ckp->sdata, *sdata = client->sdata; worker_instance_t *worker = client->worker_instance; double tdiff, bdiff, dsps, drr, network_diff, bias; user_instance_t *user = client->user_instance; @@ -5765,7 +5765,7 @@ static json_params_t static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindiff) { stratum_instance_t *client; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; worker_instance_t *worker; user_instance_t *user; @@ -5810,7 +5810,7 @@ static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindif static void suggest_diff(stratum_instance_t *client, const char *method, const json_t *params_val) { json_t *arr_val = json_array_get(params_val, 0); - sdata_t *sdata = client->ckp->data; + sdata_t *sdata = client->ckp->sdata; int64_t sdiff; if (unlikely(!client_active(client))) { @@ -6164,7 +6164,7 @@ out: static user_instance_t *generate_remote_user(ckpool_t *ckp, const char *workername) { char *base_username = strdupa(workername), *username; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; bool new_user = false; user_instance_t *user; int len; @@ -6385,7 +6385,7 @@ static void node_client_msg(ckpool_t *ckp, json_t *val, const char *buf, stratum { json_t *params, *method, *res_val, *id_val, *err_val = NULL; int msg_type = node_msg_type(val); - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; json_params_t *jp; int errnum; @@ -6513,7 +6513,7 @@ static void srecv_process(ckpool_t *ckp, char *buf) { bool noid = false, dropped = false; char address[INET6_ADDRSTRLEN]; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; stratum_instance_t *client; smsg_t *msg; json_t *val; @@ -6629,7 +6629,7 @@ static void sshare_process(ckpool_t *ckp, json_params_t *jp) { json_t *result_val, *json_msg, *err_val = NULL; stratum_instance_t *client; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; int64_t client_id; client_id = jp->client_id; @@ -6680,7 +6680,7 @@ static void sauth_process(ckpool_t *ckp, json_params_t *jp) { json_t *result_val, *json_msg, *err_val = NULL; stratum_instance_t *client; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; int mindiff, errnum = 0; int64_t client_id; @@ -6782,7 +6782,7 @@ static bool test_and_clear(bool *val, mutex_t *lock) static void ckdbq_process(ckpool_t *ckp, char *msg) { - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; size_t responselen; char *buf = NULL; @@ -6862,7 +6862,7 @@ static void send_transactions(ckpool_t *ckp, json_params_t *jp) const char *msg = json_string_value(jp->method), *params = json_string_value(json_array_get(jp->params, 0)); stratum_instance_t *client = NULL; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; json_t *val, *hashes; int64_t job_id = 0; time_t now_t; @@ -7055,7 +7055,7 @@ static void upstream_workers(ckpool_t *ckp, user_instance_t *user) static void *statsupdate(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; pool_stats_t *stats = &sdata->stats; pthread_detach(pthread_self()); @@ -7396,7 +7396,7 @@ static void *statsupdate(void *arg) static void *ckdb_heartbeat(void *arg) { ckpool_t *ckp = (ckpool_t *)arg; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; pthread_detach(pthread_self()); rename_proc("heartbeat"); @@ -7426,7 +7426,7 @@ static void *ckdb_heartbeat(void *arg) static void read_poolstats(ckpool_t *ckp) { char *s = alloca(4096), *pstats, *dsps, *sps; - sdata_t *sdata = ckp->data; + sdata_t *sdata = ckp->sdata; pool_stats_t *stats = &sdata->stats; int tvsec_diff = 0, ret; tv_t now, last; @@ -7530,7 +7530,7 @@ int stratifier(proc_instance_t *pi) LOGWARNING("%s stratifier starting", ckp->name); sdata = ckzalloc(sizeof(sdata_t)); - ckp->data = sdata; + ckp->sdata = sdata; sdata->ckp = ckp; sdata->verbose = true; @@ -7634,6 +7634,6 @@ out: } mutex_unlock(&sdata->proxy_lock); } - dealloc(ckp->data); + dealloc(ckp->sdata); return process_exit(ckp, pi, ret); }