Detect stratum in common place when adding urls, and use a bool to tell us when it's active.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
diff --git a/api.c b/api.c
index 361375a..f8171e0 100644
--- a/api.c
+++ b/api.c
@@ -2101,6 +2101,7 @@ exitsama:
static void addpool(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
{
char *url, *user, *pass;
+ struct pool *pool;
char *ptr;
if (param == NULL || *param == '\0') {
@@ -2117,7 +2118,9 @@ static void addpool(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __may
return;
}
- add_pool_details(true, url, user, pass);
+ pool = add_pool();
+ detect_stratum(pool, url);
+ add_pool_details(pool, true, url, user, pass);
ptr = escape_string(url, isjson);
strcpy(io_buffer, message(MSG_ADDPOOL, 0, ptr, isjson));
diff --git a/cgminer.c b/cgminer.c
index 63412c1..85574ac 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -403,7 +403,7 @@ static void sharelog(const char*disposition, const struct work*work)
}
/* Return value is ignored if not called from add_pool_details */
-static struct pool *add_pool(void)
+struct pool *add_pool(void)
{
struct pool *pool;
@@ -543,6 +543,25 @@ static char *set_rr(enum pool_strategy *strategy)
return NULL;
}
+/* Detect that url is for a stratum protocol either via the presence of
+ * stratum+tcp or by detecting a stratum server response */
+bool detect_stratum(struct pool *pool, char *url)
+{
+ bool stratum;
+
+ if (!extract_sockaddr(pool, url))
+ return false;
+
+ stratum = initiate_stratum(pool);
+
+ if (!strncasecmp(url, "stratum+tcp://", 14) || stratum) {
+ pool->has_stratum = true;
+ return true;
+ }
+
+ return false;
+}
+
static char *set_url(char *arg)
{
struct pool *pool;
@@ -554,10 +573,8 @@ static char *set_url(char *arg)
arg = get_proxy(arg, pool);
- if (!extract_sockaddr(pool, arg))
- return "Failed to extract address from parsed url";
-
- initiate_stratum(pool);
+ if (detect_stratum(pool, arg))
+ return NULL;
opt_set_charp(arg, &pool->rpc_url);
if (strncmp(arg, "http://", 7) &&
@@ -5160,12 +5177,8 @@ char *curses_input(const char *query)
}
#endif
-void add_pool_details(bool live, char *url, char *user, char *pass)
+void add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass)
{
- struct pool *pool;
-
- pool = add_pool();
-
url = get_proxy(url, pool);
pool->rpc_url = url;
@@ -5187,6 +5200,7 @@ void add_pool_details(bool live, char *url, char *user, char *pass)
static bool input_pool(bool live)
{
char *url = NULL, *user = NULL, *pass = NULL;
+ struct pool *pool;
bool ret = false;
immedok(logwin, true);
@@ -5196,7 +5210,18 @@ static bool input_pool(bool live)
if (!url)
goto out;
- if (strncmp(url, "http://", 7) &&
+ user = curses_input("Username");
+ if (!user)
+ goto out;
+
+ pass = curses_input("Password");
+ if (!pass)
+ goto out;
+
+ pool = add_pool();
+
+ if (!detect_stratum(pool, url) &&
+ strncmp(url, "http://", 7) &&
strncmp(url, "https://", 8)) {
char *httpinput;
@@ -5209,15 +5234,7 @@ static bool input_pool(bool live)
url = httpinput;
}
- user = curses_input("Username");
- if (!user)
- goto out;
-
- pass = curses_input("Password");
- if (!pass)
- goto out;
-
- add_pool_details(live, url, user, pass);
+ add_pool_details(pool, live, url, user, pass);
ret = true;
out:
immedok(logwin, false);
diff --git a/miner.h b/miner.h
index f1a284e..1fb7181 100644
--- a/miner.h
+++ b/miner.h
@@ -646,7 +646,9 @@ extern void api(int thr_id);
extern struct pool *current_pool(void);
extern int enabled_pools;
-extern void add_pool_details(bool live, char *url, char *user, char *pass);
+extern bool detect_stratum(struct pool *pool, char *url);
+extern struct pool *add_pool(void);
+extern void add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
#define MAX_GPUDEVICES 16
@@ -818,6 +820,8 @@ struct pool {
char *subscription;
char *nonce1;
int nonce2;
+ bool has_stratum;
+ bool stratum_active;
};
#define GETWORK_MODE_TESTPOOL 'T'
diff --git a/util.c b/util.c
index c5d0f76..ae2063d 100644
--- a/util.c
+++ b/util.c
@@ -972,9 +972,13 @@ out:
CLOSESOCKET(pool->sock);
if (val)
json_decref(val);
- } else if (opt_protocol)
- applog(LOG_DEBUG, "Pool %d confirmed mining.notify with subscription %s extranonce1 %s extranonce2 %d",
- pool->pool_no, pool->subscription, pool->nonce1, pool->nonce2);
+ } else {
+ pool->stratum_active = true;
+ if (opt_protocol) {
+ applog(LOG_DEBUG, "Pool %d confirmed mining.notify with subscription %s extranonce1 %s extranonce2 %d",
+ pool->pool_no, pool->subscription, pool->nonce1, pool->nonce2);
+ }
+ }
return ret;
}