-
Notifications
You must be signed in to change notification settings - Fork 55
Replace pool_pass_full_users/pool_pass_workers with pool_username_behaviour and add "strip_worker" option #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9463f72
4c85eeb
bb9b25a
d613935
3148e7e
da7b267
deab68d
d7ada48
1405f3f
cd4248c
aea7417
ddfdbf5
b9627b8
aa2bd4b
1e33e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -964,6 +964,8 @@ size_t datum_api_fill_config_var(const char *var_start, const size_t var_name_le | |||||||||
| var_start = "readonly:"; | ||||||||||
| colon_pos = &var_start[8]; | ||||||||||
| } | ||||||||||
| } else if (var_name_len_2 == 27 && 0 == strncmp(var_start_2, "*datum_pool_pass_full_users", 27)) { | ||||||||||
| val = datum_config.datum_pool_pass_workers && datum_config.datum_pool_pass_full_users; | ||||||||||
| } else if (var_name_len_2 == 24 && 0 == strncmp(var_start_2, "*datum_pool_pass_workers", 24)) { | ||||||||||
| val = datum_config.datum_pool_pass_workers && !datum_config.datum_pool_pass_full_users; | ||||||||||
| } else if (var_name_len_2 == 16 && 0 == strncmp(var_start_2, "*datum_pool_host", 16)) { | ||||||||||
|
|
@@ -986,6 +988,8 @@ size_t datum_api_fill_config_var(const char *var_start, const size_t var_name_le | |||||||||
| if (copy_sz >= replacement_max_len) copy_sz = replacement_max_len - 1; | ||||||||||
| memcpy(replacement, s, copy_sz); | ||||||||||
| return copy_sz; | ||||||||||
| } else if (var_name_len_2 == 32 && 0 == strncmp(var_start_2, "*username_behaviour_strip_worker", 32)) { | ||||||||||
| val = datum_config.datum_pool_pass_full_users && !datum_config.datum_pool_pass_workers; | ||||||||||
| } else if (var_name_len_2 == 27 && 0 == strncmp(var_start_2, "*username_behaviour_private", 27)) { | ||||||||||
| val = !(datum_config.datum_pool_pass_workers || datum_config.datum_pool_pass_full_users); | ||||||||||
| } else if (var_name_len_2 == 22 && 0 == strncmp(var_start_2, "*reward_sharing_prefer", 22)) { | ||||||||||
|
|
@@ -1036,6 +1040,10 @@ size_t datum_api_fill_config_var(const char *var_start, const size_t var_name_le | |||||||||
| DLOG_ERROR("%s: %s not implemented", __func__, "DATUM_CONF_USERNAME_MODS"); | ||||||||||
| break; | ||||||||||
| } | ||||||||||
| case DATUM_CONF_FUNC: { | ||||||||||
| DLOG_ERROR("%s: %s not implemented", __func__, "DATUM_CONF_FUNC"); | ||||||||||
| break; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| DLOG_ERROR("%s: '%.*s' not implemented", __func__, (int)(var_end - var_start_2), var_start_2); | ||||||||||
|
|
@@ -1160,25 +1168,52 @@ bool datum_api_config_set(const char * const key, const char * const val, struct | |||||||||
| strcpy(datum_config.mining_pool_address, val); | ||||||||||
| datum_api_json_modify_new("mining", "pool_address", json_string(val)); | ||||||||||
| } else if (0 == strcmp(key, "username_behaviour")) { | ||||||||||
| json_t * const config = datum_config.config_json; | ||||||||||
| assert(config); | ||||||||||
|
|
||||||||||
| const char *nv; | ||||||||||
| if (0 == strcmp(val, "datum_pool_pass_full_users")) { | ||||||||||
| if (datum_config.datum_pool_pass_full_users) return true; | ||||||||||
| if (datum_config.datum_pool_pass_full_users && datum_config.datum_pool_pass_workers) return true; | ||||||||||
| nv = "passthrough"; | ||||||||||
| datum_config.datum_pool_pass_full_users = true; | ||||||||||
| // datum_pool_pass_workers doesn't matter with datum_pool_pass_full_users enabled | ||||||||||
| datum_config.datum_pool_pass_workers = true; | ||||||||||
| } else if (0 == strcmp(val, "datum_pool_pass_workers")) { | ||||||||||
|
luke-jr marked this conversation as resolved.
|
||||||||||
| if (datum_config.datum_pool_pass_workers && !datum_config.datum_pool_pass_full_users) return true; | ||||||||||
| nv = "worker"; | ||||||||||
| datum_config.datum_pool_pass_full_users = false; | ||||||||||
| datum_config.datum_pool_pass_workers = true; | ||||||||||
| } else if (0 == strcmp(val, "strip_worker")) { | ||||||||||
| if (datum_config.datum_pool_pass_full_users && !datum_config.datum_pool_pass_workers) return true; | ||||||||||
| nv = val; | ||||||||||
| datum_config.datum_pool_pass_full_users = true; | ||||||||||
| datum_config.datum_pool_pass_workers = false; | ||||||||||
| } else if (0 == strcmp(val, "private")) { | ||||||||||
| if (!(datum_config.datum_pool_pass_workers || datum_config.datum_pool_pass_full_users)) return true; | ||||||||||
| nv = "ignore"; | ||||||||||
| datum_config.datum_pool_pass_full_users = false; | ||||||||||
| datum_config.datum_pool_pass_workers = false; | ||||||||||
| } else { | ||||||||||
| json_array_append_new(errors, json_string_nocheck("Invalid option for \"Send Miner Usernames To Pool\"")); | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
| datum_api_json_modify_new("datum", "pool_pass_full_users", json_boolean(datum_config.datum_pool_pass_full_users)); | ||||||||||
| if (!datum_config.datum_pool_pass_full_users) { | ||||||||||
| datum_api_json_modify_new("datum", "pool_pass_workers", json_boolean(datum_config.datum_pool_pass_workers)); | ||||||||||
| datum_api_json_modify_new("datum", "pool_username_behaviour", json_string_nocheck(nv)); | ||||||||||
|
|
||||||||||
| json_t *j = json_object_get(config, "datum"); | ||||||||||
| if (j && (json_object_get(j, "pool_pass_full_users") | ||||||||||
| || json_object_get(j, "pool_pass_workers") | ||||||||||
| || json_object_get(j, "_legacy_username_behaviour"))) { | ||||||||||
| if (nv[0] == 's') { // strip_worker, not supported by legacy config | ||||||||||
| // Must delete legacy keys or we will trigger a warning at startup | ||||||||||
| json_object_del(j, "pool_pass_full_users"); | ||||||||||
| json_object_del(j, "pool_pass_workers"); | ||||||||||
| datum_api_json_modify_new("datum", "_legacy_username_behaviour", json_true()); | ||||||||||
| } else { | ||||||||||
| json_object_del(j, "_legacy_username_behaviour"); | ||||||||||
| datum_api_json_modify_new("datum", "pool_pass_full_users", json_boolean(datum_config.datum_pool_pass_full_users)); | ||||||||||
| if (!datum_config.datum_pool_pass_full_users) { | ||||||||||
| datum_api_json_modify_new("datum", "pool_pass_workers", json_boolean(datum_config.datum_pool_pass_workers)); | ||||||||||
| } | ||||||||||
|
Comment on lines
+1213
to
+1215
|
||||||||||
| if (!datum_config.datum_pool_pass_full_users) { | |
| datum_api_json_modify_new("datum", "pool_pass_workers", json_boolean(datum_config.datum_pool_pass_workers)); | |
| } | |
| datum_api_json_modify_new("datum", "pool_pass_workers", json_boolean(datum_config.datum_pool_pass_workers)); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,8 +57,58 @@ const char *datum_conf_var_type_text[] = { | |||||
| "string", | ||||||
| "string_array", | ||||||
| "{\"modname\":{\"address\":proportion,...},...}", | ||||||
| NULL, // func | ||||||
| }; | ||||||
|
|
||||||
| static int datum_conf_username_behaviour(const T_DATUM_CONFIG_ITEM * const c, const json_t * const j, const char ** const out_type) { | ||||||
|
luke-jr marked this conversation as resolved.
|
||||||
| if (out_type) { | ||||||
| *out_type = "string"; | ||||||
| } | ||||||
| if (json_is_string(j)) { | ||||||
| const char * const s = json_string_value(j); | ||||||
| switch (json_string_length(j)) { | ||||||
| case 4: | ||||||
| if (0 == strcasecmp("pass", s)) break; | ||||||
| return -1; | ||||||
| case 6: | ||||||
| if (0 == strcasecmp("worker", s)) { | ||||||
|
Comment on lines
+67
to
+74
|
||||||
| datum_config.datum_pool_pass_full_users = false; | ||||||
| datum_config.datum_pool_pass_workers = true; | ||||||
| return 0; | ||||||
| } | ||||||
| if (0 == strcasecmp("ignore", s)) { | ||||||
| datum_config.datum_pool_pass_full_users = false; | ||||||
| datum_config.datum_pool_pass_workers = false; | ||||||
| return 0; | ||||||
| } | ||||||
| return -1; | ||||||
| case 8: | ||||||
| if (0 == strcasecmp("passthru", s)) break; | ||||||
| return -1; | ||||||
| case 11: | ||||||
| if (0 == strcasecmp("passthrough", s)) break; | ||||||
| return -1; | ||||||
| case 12: | ||||||
| if (0 == strcasecmp("strip_worker", s)) { | ||||||
| datum_config.datum_pool_pass_full_users = true; | ||||||
| datum_config.datum_pool_pass_workers = false; | ||||||
| return 0; | ||||||
| } | ||||||
| return -1; | ||||||
| default: | ||||||
| return -1; | ||||||
| } | ||||||
| } else if (json_is_null(j) || !j) { | ||||||
| // fallthrough | ||||||
| } else { | ||||||
| return -1; | ||||||
| } | ||||||
| // Only "passthrough" and variants reach here | ||||||
| datum_config.datum_pool_pass_full_users = true; | ||||||
| datum_config.datum_pool_pass_workers = true; | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| const T_DATUM_CONFIG_ITEM datum_config_options[] = { | ||||||
| // Bitcoind configs | ||||||
| { .var_type = DATUM_CONF_STRING, .category = "bitcoind", .name = "rpccookiefile", .description = "Path to file to read RPC cookie from, for communication with local bitcoind.", | ||||||
|
|
@@ -177,12 +227,15 @@ const T_DATUM_CONFIG_ITEM datum_config_options[] = { | |||||
| .required = false, .ptr = &datum_config.datum_pool_port, .default_int = 28915 }, | ||||||
| { .var_type = DATUM_CONF_STRING, .category = "datum", .name = "pool_pubkey", .description = "Public key of the DATUM server for initiating encrypted connection. Get from secure location, or set to empty to auto-fetch.", | ||||||
| .required = false, .ptr = datum_config.datum_pool_pubkey, .default_string[0] = "f21f2f0ef0aa1970468f22bad9bb7f4535146f8e4a8f646bebc93da3d89b1406f40d032f09a417d94dc068055df654937922d2c89522e3e8f6f0e649de473003", .max_string_len = sizeof(datum_config.datum_pool_pubkey) }, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "pool_pass_workers", .description = "Pass stratum miner usernames as sub-worker names to the pool (pool_username.miner's username)", | ||||||
| .example_default = true, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "pool_pass_workers", | ||||||
| // DEPRECATED (but CAUTION if removing - this currently is responsible for initialising the default value!) | ||||||
| .required = false, .ptr = &datum_config.datum_pool_pass_workers, .default_bool = true }, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "pool_pass_full_users", .description = "Pass stratum miner usernames as raw usernames to the pool (use if putting multiple payout addresses on miners behind this gateway)", | ||||||
| .example_default = true, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "pool_pass_full_users", | ||||||
| // DEPRECATED (but CAUTION if removing - this currently is responsible for initialising the default value!) | ||||||
| .required = false, .ptr = &datum_config.datum_pool_pass_full_users, .default_bool = true }, | ||||||
| { .var_type = DATUM_CONF_FUNC, .category = "datum", .name = "pool_username_behaviour", .description = "Whether and how to Pass stratum miner usernames to the pool: \"passthrough\" sends it as-is (overriding mining.pool_address), \"worker\" appends it after mining.pool_address, \"ignore\" disregards it entirely, and \"strip_worker\" passes only the username up until the first period character", | ||||||
| .example_default = true, | ||||||
| .required = false, .ptr_func = &datum_conf_username_behaviour, .default_string[0] = "\"passthrough\"" }, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "always_pay_self", .description = "Always include my datum.pool_username payout in my blocks if possible", | ||||||
| .required = false, .ptr = &datum_config.datum_always_pay_self, .default_bool = true }, | ||||||
| { .var_type = DATUM_CONF_BOOL, .category = "datum", .name = "pooled_mining_only", .description = "If the DATUM pool server becomes unavailable, terminate miner connections (otherwise, 100% of any blocks you find pay mining.pool_address)", | ||||||
|
|
@@ -221,6 +274,15 @@ json_t *load_json_from_file(const char *file_path) { | |||||
| return root; | ||||||
| } | ||||||
|
|
||||||
| const char *datum_config_get_type_string(const T_DATUM_CONFIG_ITEM * const c) { | ||||||
| if (c->var_type == DATUM_CONF_FUNC) { | ||||||
| const char *expected_type; | ||||||
| c->ptr_func(c, NULL, &expected_type); | ||||||
| return expected_type; | ||||||
| } | ||||||
|
luke-jr marked this conversation as resolved.
|
||||||
| return datum_conf_var_type_text[c->var_type]; | ||||||
| } | ||||||
|
|
||||||
| void datum_config_set_default(const T_DATUM_CONFIG_ITEM *c) { | ||||||
| // set the default | ||||||
| switch(c->var_type) { | ||||||
|
|
@@ -252,6 +314,13 @@ void datum_config_set_default(const T_DATUM_CONFIG_ITEM *c) { | |||||
| *umods_p = NULL; | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| case DATUM_CONF_FUNC: { | ||||||
| json_t * const j_null = json_null(); | ||||||
| c->ptr_func(c, j_null, NULL); | ||||||
| json_decref(j_null); | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -410,6 +479,10 @@ int datum_config_parse_value(const T_DATUM_CONFIG_ITEM *c, json_t *item) { | |||||
| case DATUM_CONF_USERNAME_MODS: { | ||||||
| return datum_config_parse_username_mods(c->ptr, item, true); | ||||||
| } | ||||||
|
|
||||||
| case DATUM_CONF_FUNC: { | ||||||
| return c->ptr_func(c, item, NULL); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return -1; | ||||||
|
|
@@ -452,17 +525,45 @@ int datum_read_config(const char *conffile) { | |||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| // item might be valid | ||||||
| // item might be valid* | ||||||
| j = datum_config_parse_value(&datum_config_options[i], item); | ||||||
| if (j == -1) { | ||||||
| DLOG_ERROR("Could not parse configuration option %s.%s. Type should be %s", datum_config_options[i].category, datum_config_options[i].name, datum_conf_var_type_text[datum_config_options[i].var_type]); | ||||||
| const T_DATUM_CONFIG_ITEM * const c = &datum_config_options[i]; | ||||||
| const char * const expected_type = datum_config_get_type_string(c); | ||||||
| DLOG_ERROR("Could not parse configuration option %s.%s. Type should be %s", | ||||||
| c->category, c->name, expected_type); | ||||||
| return -1; | ||||||
| } else if (j == -2) { | ||||||
| DLOG_ERROR("Configuration option %s.%s exceeds maximum length of %d", datum_config_options[i].category, datum_config_options[i].name, datum_config_options[i].max_string_len - 1); | ||||||
| return -1; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| cat = json_object_get(config, "datum"); | ||||||
| if (json_is_object(cat)) { | ||||||
| item = json_object_get(cat, "pool_pass_full_users"); | ||||||
| if (item && (!json_is_false(item)) ? !(datum_config.datum_pool_pass_full_users && datum_config.datum_pool_pass_workers) : datum_config.datum_pool_pass_full_users) { | ||||||
|
||||||
| if (item && (!json_is_false(item)) ? !(datum_config.datum_pool_pass_full_users && datum_config.datum_pool_pass_workers) : datum_config.datum_pool_pass_full_users) { | |
| if (item && (((!json_is_false(item)) ? !(datum_config.datum_pool_pass_full_users && datum_config.datum_pool_pass_workers) : datum_config.datum_pool_pass_full_users))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc still says there are “three different ways” to pass usernames, but this PR adds a fourth (
strip_worker). Update that sentence/count to match the newly documented behaviors.