Commit 0121b75a4e17819f9f0eb7bee516bc8a63de59d1

Con Kolivas 2013-09-07T11:33:07

Provide a mechanism for setting a pool quota to be used by load-balance.

diff --git a/cgminer.c b/cgminer.c
index 892c6cf..d210520 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -512,6 +512,7 @@ struct pool *add_pool(void)
 
 	pool->rpc_req = getwork_req;
 	pool->rpc_proxy = NULL;
+	pool->quota = 1;
 
 	return pool;
 }
@@ -697,19 +698,20 @@ bool detect_stratum(struct pool *pool, char *url)
 	return false;
 }
 
-static char *set_url(char *arg)
+static struct pool *add_url(void)
 {
-	struct pool *pool;
-
 	total_urls++;
 	if (total_urls > total_pools)
 		add_pool();
-	pool = pools[total_urls - 1];
+	return pools[total_urls - 1];
+}
 
+static void setup_url(struct pool *pool, char *arg)
+{
 	arg = get_proxy(arg, pool);
 
 	if (detect_stratum(pool, arg))
-		return NULL;
+		return;
 
 	opt_set_charp(arg, &pool->rpc_url);
 	if (strncmp(arg, "http://", 7) &&
@@ -723,6 +725,39 @@ static char *set_url(char *arg)
 		strncat(httpinput, arg, 248);
 		pool->rpc_url = httpinput;
 	}
+}
+
+static char *set_url(char *arg)
+{
+	struct pool *pool = add_url();
+
+	setup_url(pool, arg);
+	return NULL;
+}
+
+static char *set_quota(char *arg)
+{
+	char *semicolon = strchr(arg, ';'), *url;
+	int len, qlen, quota;
+	struct pool *pool;
+
+	if (!semicolon)
+		return "No semicolon separated quota;URL pair found";
+	len = strlen(arg);
+	*semicolon = '\0';
+	qlen = strlen(arg);
+	if (!qlen)
+		return "No parameter for quota found";
+	len -= qlen + 1;
+	if (len < 1)
+		return "No parameter for URL found";
+	quota = atoi(arg);
+	if (quota < 0)
+		return "Invalid negative parameter for quota set";
+	url = arg + qlen + 1;
+	pool = add_url();
+	setup_url(pool, url);
+	pool->quota = quota;
 
 	return NULL;
 }
@@ -1201,6 +1236,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITHOUT_ARG("--quiet|-q",
 			opt_set_bool, &opt_quiet,
 			"Disable logging output, display status and errors"),
+	OPT_WITH_ARG("--quota|-U",
+		     set_quota, NULL, NULL,
+		     "quota;URL combination for server with load-balance strategy quotas"),
 	OPT_WITHOUT_ARG("--real-quiet",
 			opt_set_bool, &opt_realquiet,
 			"Disable all output"),
diff --git a/miner.h b/miner.h
index d160406..8fd3f78 100644
--- a/miner.h
+++ b/miner.h
@@ -1120,6 +1120,7 @@ struct pool {
 	int solved;
 	int diff1;
 	char diff[8];
+	int quota;
 
 	double diff_accepted;
 	double diff_rejected;