diff --git a/README.txt b/README.txt index bc9fed1..4c0b3b5 100644 --- a/README.txt +++ b/README.txt @@ -225,6 +225,7 @@ features. >>> RELEASE HISTORY <<< August 2015... + Allow to load remote config with curl (-c http://...) Add Lyra2REv2 algo (Vertcoin/Zoom) Restore WhirlpoolX algo (VNL) Drop Animecoin support diff --git a/ccminer.cpp b/ccminer.cpp index 2bc231b..398d639 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -2522,13 +2522,15 @@ void parse_arg(int key, char *arg) break; case 'c': { json_error_t err; - if (opt_config) + if (opt_config) { json_decref(opt_config); -#if JANSSON_VERSION_HEX >= 0x020000 - opt_config = json_load_file(arg, 0, &err); -#else - opt_config = json_load_file(arg, &err); -#endif + opt_config = NULL; + } + if (arg && strstr(arg, "://")) { + opt_config = json_load_url(arg, &err); + } else { + opt_config = JSON_LOADF(arg, &err); + } if (!json_is_object(opt_config)) { applog(LOG_ERR, "JSON decode of %s failed", arg); proper_exit(EXIT_CODE_USAGE); diff --git a/configure.ac b/configure.ac index 775371f..9ccf7f2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([ccminer], [1.6.6-dev]) +AC_INIT([ccminer], [1.6.6]) AC_PREREQ([2.59c]) AC_CANONICAL_SYSTEM diff --git a/miner.h b/miner.h index 7f1ea7b..3491a54 100644 --- a/miner.h +++ b/miner.h @@ -245,10 +245,14 @@ void aligned_free(void *ptr); #if JANSSON_MAJOR_VERSION >= 2 #define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr)) +#define JSON_LOADF(str, err_ptr) json_load_file((str), 0, (err_ptr)) #else #define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr)) +#define JSON_LOADF(str, err_ptr) json_load_file((str), (err_ptr)) #endif +json_t * json_load_url(char* cfg_url, json_error_t *err); + #define USER_AGENT PACKAGE_NAME "/" PACKAGE_VERSION void sha256_init(uint32_t *state); diff --git a/util.cpp b/util.cpp index 27e667f..41d6fda 100644 --- a/util.cpp +++ b/util.cpp @@ -603,6 +603,51 @@ json_t *json_rpc_longpoll(CURL *curl, char *lp_url, struct pool_infos *pool, con return json_rpc_call(curl, lp_url, userpass, req, false, true, keepalive, curl_err); } +json_t *json_load_url(char* cfg_url, json_error_t *err) +{ + char err_str[CURL_ERROR_SIZE] = { 0 }; + struct data_buffer all_data = { 0 }; + int rc = 0; json_t *cfg = NULL; + CURL *curl = curl_easy_init(); + if (unlikely(!curl)) { + applog(LOG_ERR, "Remote config init failed!"); + return NULL; + } + curl_easy_setopt(curl, CURLOPT_URL, cfg_url); + curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_str); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data); + if (opt_proxy) { + curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy); + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type); + } else if (getenv("http_proxy")) { + if (getenv("all_proxy")) + curl_easy_setopt(curl, CURLOPT_PROXY, getenv("all_proxy")); + else if (getenv("ALL_PROXY")) + curl_easy_setopt(curl, CURLOPT_PROXY, getenv("ALL_PROXY")); + else + curl_easy_setopt(curl, CURLOPT_PROXY, ""); + } + rc = curl_easy_perform(curl); + if (rc) { + applog(LOG_ERR, "Remote config read failed: %s", err_str); + goto err_out; + } + if (!all_data.buf || !all_data.len) { + applog(LOG_ERR, "Empty data received for config"); + goto err_out; + } + + cfg = JSON_LOADS((char*)all_data.buf, err); +err_out: + curl_easy_cleanup(curl); + return cfg; +} + /** * Unlike malloc, calloc set the memory to zero */