From 8af64746bf92971c5f57e59e44ccf3b5aae9b1be Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 16 May 2014 10:06:27 +1000 Subject: [PATCH] Change config format to take url auth and pass for both btcd and proxy and choose which to use in the generator based on proxy bool --- src/ckpool.c | 12 ++++++------ src/generator.c | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 1a2d19a6..3b760211 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -292,9 +292,9 @@ static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size) ckp->btcdpass = ckzalloc(sizeof(char *) * arr_size); for (i = 0; i < arr_size; i++) { val = json_array_get(arr_val, i); - json_get_string(&ckp->btcdurl[i], val, "btcdurl"); - json_get_string(&ckp->btcdauth[i], val, "btcdauth"); - json_get_string(&ckp->btcdpass[i], val, "btcdpass"); + json_get_string(&ckp->btcdurl[i], val, "url"); + json_get_string(&ckp->btcdauth[i], val, "auth"); + json_get_string(&ckp->btcdpass[i], val, "pass"); } } @@ -309,9 +309,9 @@ static void parse_proxies(ckpool_t *ckp, json_t *arr_val, int arr_size) ckp->proxypass = ckzalloc(sizeof(char *) * arr_size); for (i = 0; i < arr_size; i++) { val = json_array_get(arr_val, i); - json_get_string(&ckp->proxyurl[i], val, "proxyurl"); - json_get_string(&ckp->proxyauth[i], val, "proxyauth"); - json_get_string(&ckp->proxypass[i], val, "proxypass"); + json_get_string(&ckp->proxyurl[i], val, "url"); + json_get_string(&ckp->proxyauth[i], val, "auth"); + json_get_string(&ckp->proxypass[i], val, "pass"); } } diff --git a/src/generator.c b/src/generator.c index e7c01f4d..adc4645e 100644 --- a/src/generator.c +++ b/src/generator.c @@ -101,10 +101,11 @@ out: return ret; } +/* FIXME: Hard wired to just use config 0 for now */ int generator(proc_instance_t *pi) { + char *url, *auth, *pass, *userpass = NULL; ckpool_t *ckp = pi->ckp; - char *userpass = NULL; gbtbase_t gbt; connsock_t cs; int ret = 1; @@ -112,13 +113,22 @@ int generator(proc_instance_t *pi) memset(&cs, 0, sizeof(cs)); memset(&gbt, 0, sizeof(gbt)); - if (!extract_sockaddr(ckp->btcdurl[0], &cs.url, &cs.port)) { - LOGWARNING("Failed to extract address from %s", ckp->btcdurl[0]); + if (!ckp->proxy) { + url = ckp->btcdurl[0]; + auth = ckp->btcdauth[0]; + pass = ckp->btcdpass[0]; + } else { + url = ckp->proxyurl[0]; + auth = ckp->proxyauth[0]; + pass = ckp->proxypass[0]; + } + if (!extract_sockaddr(url, &cs.url, &cs.port)) { + LOGWARNING("Failed to extract address from %s", url); goto out; } - userpass = strdup(ckp->btcdauth[0]); + userpass = strdup(auth); realloc_strcat(&userpass, ":"); - realloc_strcat(&userpass, ckp->btcdpass[0]); + realloc_strcat(&userpass, pass); cs.auth = http_base64(userpass); if (!cs.auth) { LOGWARNING("Failed to create base64 auth from %s", userpass);