Add API commands and modify output to support pool quota displaying and changing.
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
diff --git a/API-README b/API-README
index 58f185e..0898da0 100644
--- a/API-README
+++ b/API-README
@@ -188,6 +188,10 @@ The list of requests - a (*) means it requires privileged access - and replies:
stating the results of changing pool priorities
See usage below
+ poolquota|N,Q (*)
+ none There is no reply section just the STATUS section
+ stating the results of changing pool quota to Q
+
disablepool|N (*)
none There is no reply section just the STATUS section
stating the results of disabling pool N
@@ -486,6 +490,16 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
+API V1.30 (cgminer v3.4.3)
+
+Added API command:
+ 'poolquota' - Set pool quota for load-balance strategy.
+
+Modified API command:
+ 'pools' - add 'Quota'
+
+---------
+
API V1.29 (cgminer v3.4.1)
Muticast identification added to the API
@@ -578,7 +592,7 @@ Added API commands:
Modified API commands:
'summary' - add 'Best Share'
-Modifed output:
+Modified output:
each MMQ shows up as 4 devices, each with it's own stats
----------
diff --git a/api.c b/api.c
index cb9df4a..cc769ab 100644
--- a/api.c
+++ b/api.c
@@ -1,6 +1,6 @@
/*
* Copyright 2011-2013 Andrew Smith
- * Copyright 2011-2012 Con Kolivas
+ * Copyright 2011-2013 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -135,7 +135,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.29";
+static const char *APIVERSION = "1.30";
static const char *DEAD = "Dead";
#if defined(HAVE_OPENCL) || defined(HAVE_AN_FPGA) || defined(HAVE_AN_ASIC)
static const char *SICK = "Sick";
@@ -422,6 +422,9 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_ASCSETERR 120
#endif
+#define MSG_INVNEG 121
+#define MSG_SETQUOTA 122
+
enum code_severity {
SEVERITY_ERR,
SEVERITY_WARN,
@@ -582,6 +585,8 @@ struct CODES {
{ SEVERITY_SUCC, MSG_SETCONFIG,PARAM_SET, "Set config '%s' to %d" },
{ SEVERITY_ERR, MSG_UNKCON, PARAM_STR, "Unknown config '%s'" },
{ SEVERITY_ERR, MSG_INVNUM, PARAM_BOTH, "Invalid number (%d) for '%s' range is 0-9999" },
+ { SEVERITY_ERR, MSG_INVNEG, PARAM_BOTH, "Invalid negative number (%d) for '%s'" },
+ { SEVERITY_SUCC, MSG_SETQUOTA,PARAM_SET, "Set pool '%s' to quota %d'" },
{ SEVERITY_ERR, MSG_CONPAR, PARAM_NONE, "Missing config parameters 'name,N'" },
{ SEVERITY_ERR, MSG_CONVAL, PARAM_STR, "Missing config value N for '%s,N'" },
{ SEVERITY_SUCC, MSG_USBSTA, PARAM_NONE, "USB Statistics" },
@@ -2145,6 +2150,7 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
root = api_add_escape(root, "URL", pool->rpc_url, false);
root = api_add_string(root, "Status", status, false);
root = api_add_int(root, "Priority", &(pool->prio), false);
+ root = api_add_int(root, "Quota", &pool->quota, false);
root = api_add_string(root, "Long Poll", lp, false);
root = api_add_uint(root, "Getworks", &(pool->getwork_requested), false);
root = api_add_int(root, "Accepted", &(pool->accepted), false);
@@ -2617,6 +2623,47 @@ static void poolpriority(struct io_data *io_data, __maybe_unused SOCKETTYPE c, c
message(io_data, MSG_POOLPRIO, 0, NULL, isjson);
}
+static void poolquota(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+ struct pool *pool;
+ int quota, id;
+ char *comma;
+
+ if (total_pools == 0) {
+ message(io_data, MSG_NOPOOL, 0, NULL, isjson);
+ return;
+ }
+
+ if (param == NULL || *param == '\0') {
+ message(io_data, MSG_MISPID, 0, NULL, isjson);
+ return;
+ }
+
+ comma = strchr(param, ',');
+ if (!comma) {
+ message(io_data, MSG_CONVAL, 0, param, isjson);
+ return;
+ }
+
+ *(comma++) = '\0';
+
+ id = atoi(param);
+ if (id < 0 || id >= total_pools) {
+ message(io_data, MSG_INVPID, id, NULL, isjson);
+ return;
+ }
+ pool = pools[id];
+
+ quota = atoi(comma);
+ if (quota < 0) {
+ message(io_data, MSG_INVNEG, quota, pool->rpc_url, isjson);
+ return;
+ }
+
+ pool->quota = quota;
+ message(io_data, MSG_SETQUOTA, quota, pool->rpc_url, isjson);
+}
+
static void disablepool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
{
struct pool *pool;
@@ -3831,6 +3878,7 @@ struct CMDS {
{ "switchpool", switchpool, true },
{ "addpool", addpool, true },
{ "poolpriority", poolpriority, true },
+ { "poolquota", poolquota, true },
{ "enablepool", enablepool, true },
{ "disablepool", disablepool, true },
{ "removepool", removepool, true },