From 4d72f49061b92a625388a85fce5324b721ae7f34 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 16 Jan 2015 09:41:50 +1100 Subject: [PATCH] Preauth workers for the first 10 minutes after a user first authorises --- src/stratifier.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index 0b974d5f..bb189934 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -180,6 +180,7 @@ struct user_instance { double dsps1440; double dsps10080; tv_t last_share; + time_t auth_time; }; /* Combined data from workers with the same workername */ @@ -1953,6 +1954,8 @@ static int send_recv_auth(stratum_instance_t *client) json_get_string(&secondaryuserid, val, "secondaryuserid"); json_get_int(&worker->mindiff, val, "difficultydefault"); client->suggest_diff = worker->mindiff; + if (!user_instance->auth_time) + user_instance->auth_time = time(NULL); } if (secondaryuserid && (!safecmp(response, "ok.authorise") || !safecmp(response, "ok.addrauth"))) { @@ -2054,7 +2057,13 @@ static json_t *parse_authorise(stratum_instance_t *client, json_t *params_val, j if (CKP_STANDALONE(ckp)) ret = true; else { - *errnum = send_recv_auth(client); + /* Preauth workers for the first 10 minutes after the user is + * first authorised by ckdb to avoid floods of worker auths. + * *errnum is implied zero already so ret will be set true */ + if (user_instance->auth_time && time(NULL) - user_instance->auth_time < 600) + queue_delayed_auth(client); + else + *errnum = send_recv_auth(client); if (!*errnum) ret = true; else if (*errnum < 0 && user_instance->secondaryuserid) {