Skip to content

Commit 85fd02c

Browse files
committed
api: Configuration modification support (if enabled in conf file)
1 parent befc307 commit 85fd02c

15 files changed

+973
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ set(WEB_RESOURCES
2727
www/home.html
2828
www/clients_top.html
2929
www/coinbaser_top.html
30+
www/config.html
31+
www/config_errors.html
32+
www/config_restart.html
3033
www/threads_top.html
3134
www/foot.html
3235
www/assets/style.css

src/datum_api.c

Lines changed: 568 additions & 0 deletions
Large diffs are not rendered by default.

src/datum_blocktemplates.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,15 @@ void *datum_gateway_template_thread(void *args) {
404404
{
405405
unsigned char dummy[64];
406406
if (!addr_2_output_script(datum_config.mining_pool_address, &dummy[0], 64)) {
407-
DLOG_FATAL("Could not generate output script for pool addr! Perhaps invalid? This is bad.");
408-
panic_from_thread(__LINE__);
407+
if (datum_config.api_modify_conf) {
408+
DLOG_ERROR("Could not generate output script for pool addr! Perhaps invalid? Configure via API/dashboard.");
409+
} else {
410+
DLOG_FATAL("Could not generate output script for pool addr! Perhaps invalid? This is bad.");
411+
panic_from_thread(__LINE__);
412+
}
413+
}
414+
while (!addr_2_output_script(datum_config.mining_pool_address, &dummy[0], 64)) {
415+
usleep(50000);
409416
}
410417
}
411418

src/datum_conf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ const T_DATUM_CONFIG_ITEM datum_config_options[] = {
111111
.required = false, .ptr = datum_config.api_admin_password, .default_string[0] = "", .max_string_len = sizeof(datum_config.api_admin_password) },
112112
{ .var_type = DATUM_CONF_INT, .category = "api", .name = "listen_port", .description = "Port to listen for API/dashboard requests (0=disabled)",
113113
.required = false, .ptr = &datum_config.api_listen_port, .default_int = 0 },
114+
{ .var_type = DATUM_CONF_BOOL, .category = "api", .name = "modify_conf", .description = "Enable modifying the config file from API/dashboard",
115+
.required = false, .ptr = &datum_config.api_modify_conf, .default_int = 0 },
114116

115117
// extra block submissions list
116118
{ .var_type = DATUM_CONF_STRING_ARRAY, .category = "extra_block_submissions", .name = "urls", .description = "Array of bitcoind RPC URLs to submit our blocks to directly. Include auth info: http://user:pass@IP",
@@ -322,7 +324,9 @@ int datum_read_config(const char *conffile) {
322324
}
323325
}
324326

325-
if (config) {
327+
if (datum_config.api_modify_conf) {
328+
datum_config.config_json = config;
329+
} else {
326330
json_decref(config);
327331
}
328332

src/datum_conf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include <stdbool.h>
4444
#include <stdint.h>
4545

46+
#include <jansson.h>
47+
4648
#define DATUM_CONF_BOOL 1
4749
#define DATUM_CONF_INT 2
4850
#define DATUM_CONF_STRING 3
@@ -107,6 +109,8 @@ typedef struct {
107109
size_t api_admin_password_len;
108110
char api_csrf_token[65];
109111
int api_listen_port;
112+
bool api_modify_conf;
113+
json_t *config_json;
110114

111115
int extra_block_submissions_count;
112116
char extra_block_submissions_urls[DATUM_MAX_BLOCK_SUBMITS][DATUM_MAX_SUBMIT_URL_LEN];

src/datum_jsonrpc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ bool update_rpc_cookie(global_config_t * const cfg) {
250250
return true;
251251
}
252252

253+
void update_rpc_auth(global_config_t * const cfg) {
254+
if (datum_config.bitcoind_rpccookiefile[0] && !cfg->bitcoind_rpcuser[0]) {
255+
update_rpc_cookie(cfg);
256+
} else {
257+
snprintf(datum_config.bitcoind_rpcuserpass, sizeof(datum_config.bitcoind_rpcuserpass), "%s:%s", datum_config.bitcoind_rpcuser, datum_config.bitcoind_rpcpassword);
258+
}
259+
}
260+
253261
json_t *bitcoind_json_rpc_call(CURL * const curl, global_config_t * const cfg, const char * const rpc_req) {
254262
long http_resp_code = -1;
255263
json_t *j = json_rpc_call_full(curl, cfg->bitcoind_rpcurl, cfg->bitcoind_rpcuserpass, rpc_req, NULL, &http_resp_code);

src/datum_jsonrpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct upload_buffer {
6666
json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, const char *rpc_req);
6767
char *basic_http_call(CURL *curl, const char *url);
6868
bool update_rpc_cookie(global_config_t *cfg);
69+
void update_rpc_auth(global_config_t *cfg);
6970
json_t *bitcoind_json_rpc_call(CURL *curl, global_config_t *cfg, const char *rpc_req);
7071

7172
#endif

src/datum_utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <stdint.h>
5252
#include <sys/time.h>
5353
#include <inttypes.h>
54+
#include <unistd.h>
5455

5556
#include "datum_gateway.h"
5657
#include "datum_logger.h"

www/clients_top.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h1><img src="/assets/icons/datum_logo.svg" alt="(DATUM Logo)" style="vertical-a
1414
</div>
1515
<div class="menu-container">
1616
<a href="/">Status</a>
17+
<a href="/config">Config</a>
1718
<a href="/clients" style="background-color: darkslategrey;">Clients</a>
1819
<a href="/threads">Threads</a>
1920
<a href="/coinbaser">Coinbaser</a>

www/coinbaser_top.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ <h1><img src="/assets/icons/datum_logo.svg" alt="(DATUM Logo)" style="vertical-a
3131
</div>
3232
<div class="menu-container">
3333
<a href="/">Status</a>
34+
<a href="/config">Config</a>
3435
<a href="/clients">Clients</a>
3536
<a href="/threads">Threads</a>
3637
<a href="/coinbaser" style="background-color: darkslategrey;">Coinbaser</a>

0 commit comments

Comments
 (0)