|
|
@ -83,7 +83,12 @@ static pthread_mutex_t stats_lock; |
|
|
|
/* Serialises sends/receives to ckdb if possible */ |
|
|
|
/* Serialises sends/receives to ckdb if possible */ |
|
|
|
static pthread_mutex_t ckdb_lock; |
|
|
|
static pthread_mutex_t ckdb_lock; |
|
|
|
|
|
|
|
|
|
|
|
static uint64_t enonce1_64; |
|
|
|
static union { |
|
|
|
|
|
|
|
uint64_t u64; |
|
|
|
|
|
|
|
uint32_t u32; |
|
|
|
|
|
|
|
uint16_t u16; |
|
|
|
|
|
|
|
uint8_t u8; |
|
|
|
|
|
|
|
} enonce1u; |
|
|
|
|
|
|
|
|
|
|
|
struct workbase { |
|
|
|
struct workbase { |
|
|
|
/* Hash table data */ |
|
|
|
/* Hash table data */ |
|
|
@ -978,11 +983,12 @@ static stratum_instance_t *__stratum_add_instance(ckpool_t *ckp, int64_t id) |
|
|
|
return instance; |
|
|
|
return instance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Only supports a full ckpool instance sessionid with an 8 byte sessionid */ |
|
|
|
static bool disconnected_sessionid_exists(const char *sessionid, int64_t id) |
|
|
|
static bool disconnected_sessionid_exists(const char *sessionid, int64_t id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool connected_exists = false, ret = false; |
|
|
|
|
|
|
|
stratum_instance_t *instance, *tmp; |
|
|
|
stratum_instance_t *instance, *tmp; |
|
|
|
uint64_t session64; |
|
|
|
uint64_t session64; |
|
|
|
|
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
|
|
if (!sessionid) |
|
|
|
if (!sessionid) |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
@ -997,12 +1003,9 @@ static bool disconnected_sessionid_exists(const char *sessionid, int64_t id) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
if (instance->enonce1_64 == session64) { |
|
|
|
if (instance->enonce1_64 == session64) { |
|
|
|
/* Only allow one connected instance per enonce1 */ |
|
|
|
/* Only allow one connected instance per enonce1 */ |
|
|
|
connected_exists = true; |
|
|
|
goto out_unlock; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (connected_exists) |
|
|
|
|
|
|
|
goto out_unlock; |
|
|
|
|
|
|
|
instance = NULL; |
|
|
|
instance = NULL; |
|
|
|
HASH_FIND(hh, disconnected_instances, &session64, sizeof(uint64_t), instance); |
|
|
|
HASH_FIND(hh, disconnected_instances, &session64, sizeof(uint64_t), instance); |
|
|
|
if (instance) |
|
|
|
if (instance) |
|
|
@ -1345,10 +1348,6 @@ out: |
|
|
|
* unused enonce1 value and reject clients instead if there is no space left */ |
|
|
|
* unused enonce1 value and reject clients instead if there is no space left */ |
|
|
|
static bool new_enonce1(stratum_instance_t *client) |
|
|
|
static bool new_enonce1(stratum_instance_t *client) |
|
|
|
{ |
|
|
|
{ |
|
|
|
void *enoncev = &enonce1_64; |
|
|
|
|
|
|
|
uint32_t *enonce1_32 = enoncev; |
|
|
|
|
|
|
|
uint16_t *enonce1_16 = enoncev; |
|
|
|
|
|
|
|
uint8_t *enonce1_8 = enoncev; |
|
|
|
|
|
|
|
bool ret = false; |
|
|
|
bool ret = false; |
|
|
|
workbase_t *wb; |
|
|
|
workbase_t *wb; |
|
|
|
int i; |
|
|
|
int i; |
|
|
@ -1357,30 +1356,32 @@ static bool new_enonce1(stratum_instance_t *client) |
|
|
|
wb = current_workbase; |
|
|
|
wb = current_workbase; |
|
|
|
switch(wb->enonce1varlen) { |
|
|
|
switch(wb->enonce1varlen) { |
|
|
|
case 8: |
|
|
|
case 8: |
|
|
|
enonce1_64++; |
|
|
|
enonce1u.u64++; |
|
|
|
ret = true; |
|
|
|
ret = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
++(*enonce1_32); |
|
|
|
enonce1u.u32++; |
|
|
|
ret = true; |
|
|
|
ret = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
i = 0; |
|
|
|
for (i = 0; i < 65536; i++) { |
|
|
|
do { |
|
|
|
enonce1u.u16++; |
|
|
|
++(*enonce1_16); |
|
|
|
ret = enonce1_free(enonce1u.u64); |
|
|
|
ret = enonce1_free(enonce1_64); |
|
|
|
if (ret) |
|
|
|
} while (++i < 65536 && !ret); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
i = 0; |
|
|
|
for (i = 0; i < 256; i++) { |
|
|
|
do { |
|
|
|
enonce1u.u8++; |
|
|
|
++(*enonce1_8); |
|
|
|
ret = enonce1_free(enonce1u.u64); |
|
|
|
ret = enonce1_free(enonce1_64); |
|
|
|
if (ret) |
|
|
|
} while (++i < 256 && !ret); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret) |
|
|
|
if (ret) |
|
|
|
client->enonce1_64 = enonce1_64; |
|
|
|
client->enonce1_64 = enonce1u.u64; |
|
|
|
if (wb->enonce1constlen) |
|
|
|
if (wb->enonce1constlen) |
|
|
|
memcpy(client->enonce1bin, wb->enonce1constbin, wb->enonce1constlen); |
|
|
|
memcpy(client->enonce1bin, wb->enonce1constbin, wb->enonce1constlen); |
|
|
|
memcpy(client->enonce1bin + wb->enonce1constlen, &client->enonce1_64, wb->enonce1varlen); |
|
|
|
memcpy(client->enonce1bin + wb->enonce1constlen, &client->enonce1_64, wb->enonce1varlen); |
|
|
|