Browse Source

Merge branch 'cherry_kanoi_rpc' into bfgminer

Luke Dashjr 13 years ago
parent
commit
6e4f9e35d1
5 changed files with 118 additions and 21 deletions
  1. 21 1
      API-README
  2. 62 4
      api.c
  3. 1 1
      miner.c
  4. 2 0
      miner.h
  5. 32 15
      miner.php

+ 21 - 1
API-README

@@ -124,7 +124,10 @@ The list of requests - a (*) means it requires privileged access - and replies a
                               Log Interval=N, <- log interval (--log N)
                               Device Code=GPU ICA , <- spaced list of compiled devices
                               OS=Linux/Apple/..., <- operating System
-                              Failover-Only=true/false | <- failover-only setting
+                              Failover-Only=true/false, <- failover-only setting
+                              ScanTime=N, <- --scan-time setting
+                              Queue=N, <- --queue setting
+                              Expiry=N| <- --expiry setting
 
  summary       SUMMARY        The status summary of the miner
                               e.g. Elapsed=NNN,Found Blocks=N,Getworks=N,...|
@@ -303,6 +306,13 @@ The list of requests - a (*) means it requires privileged access - and replies a
                               RPCProto=true/false,
                               PerDevice=true/false|
 
+ setconfig|name,N (*)
+               none           There is no reply section just the STATUS section
+                              stating the results of setting 'name' to N
+                              The valid values for name are currently:
+                              queue, scantime, expiry
+                              N is an integer in the range 0 to 9999
+
 When you enable, disable or restart a GPU or PGA, you will also get Thread messages
 in the BFGMiner status window
 
@@ -359,12 +369,14 @@ API V1.19
 
 Added API commands:
  'debug'
+ 'setconfig|name,N'
 
 Modified API commands:
  Change pool field name 'Diff1 Shares' to 'Diff1 Work'
  'devs' - add 'Diff1 Work' to all devices
  'gpu|N' - add 'Diff1 Work'
  'pga|N' - add 'Diff1 Work'
+ 'config' - add 'Queue', 'Expiry'
 
 ----------
 
@@ -904,6 +916,14 @@ e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
 
 ---------
 
+Default:
+ $rigipsecurity = true;
+
+Set $rigipsecurity to false to show the IP/Port of the rig
+in the socket error messages and also show the full socket message
+
+---------
+
 Default:
  $rigtotals = true;
  $forcerigtotals = false;

+ 62 - 4
api.c

@@ -260,6 +260,7 @@ static const char *OSINFO =
 #define _CHECK		"CHECK"
 #define _MINECOIN	"COIN"
 #define _DEBUGSET	"DEBUG"
+#define _SETCONFIG	"SETCONFIG"
 
 static const char ISJSON = '{';
 #define JSON0		"{"
@@ -298,6 +299,7 @@ static const char ISJSON = '{';
 #define JSON_CHECK	JSON1 _CHECK JSON2
 #define JSON_MINECOIN	JSON1 _MINECOIN JSON2
 #define JSON_DEBUGSET	JSON1 _DEBUGSET JSON2
+#define JSON_SETCONFIG	JSON1 _SETCONFIG JSON2
 #define JSON_END	JSON4 JSON5
 
 static const char *JSON_COMMAND = "command";
@@ -395,6 +397,12 @@ static const char *JSON_PARAMETER = "parameter";
 #define MSG_MINECOIN 78
 #define MSG_DEBUGSET 79
 
+#define MSG_SETCONFIG 82
+#define MSG_UNKCON 83
+#define MSG_INVNUM 84
+#define MSG_CONPAR 85
+#define MSG_CONVAL 86
+
 enum code_severity {
 	SEVERITY_ERR,
 	SEVERITY_WARN,
@@ -422,6 +430,7 @@ enum code_parameters {
 	PARAM_STR,
 	PARAM_BOTH,
 	PARAM_BOOL,
+	PARAM_SET,
 	PARAM_NONE
 };
 
@@ -548,6 +557,12 @@ struct CODES {
  { SEVERITY_SUCC,  MSG_FOO,	PARAM_BOOL,	"Failover-Only set to %s" },
  { SEVERITY_SUCC,  MSG_MINECOIN,PARAM_NONE,	"BFGMiner coin" },
  { SEVERITY_SUCC,  MSG_DEBUGSET,PARAM_STR,	"Debug settings" },
+
+ { 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_CONPAR,	PARAM_NONE,	"Missing config parameters 'name,N'" },
+ { SEVERITY_ERR,   MSG_CONVAL,	PARAM_STR,	"Missing config value N for '%s,N'" },
  { SEVERITY_FAIL, 0, 0, NULL }
 };
 
@@ -1180,6 +1195,9 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
 				case PARAM_BOOL:
 					sprintf(buf, codes[i].description, paramid ? TRUESTR : FALSESTR);
 					break;
+				case PARAM_SET:
+					sprintf(buf, codes[i].description, param2, paramid);
+					break;
 				case PARAM_NONE:
 				default:
 					strcpy(buf, codes[i].description);
@@ -1188,8 +1206,8 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
 			root = api_add_string(root, _STATUS, severity, false);
 			root = api_add_time(root, "When", &when, false);
 			root = api_add_int(root, "Code", &messageid, false);
-			root = api_add_string(root, "Msg", buf, false);
-			root = api_add_string(root, "Description", opt_api_description, false);
+			root = api_add_escape(root, "Msg", buf, false);
+			root = api_add_escape(root, "Description", opt_api_description, false);
 
 			root = print_data(root, ptr, isjson);
 			if (isjson)
@@ -1203,8 +1221,8 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
 	int id = -1;
 	root = api_add_int(root, "Code", &id, false);
 	sprintf(buf, "%d", messageid);
-	root = api_add_string(root, "Msg", buf, false);
-	root = api_add_string(root, "Description", opt_api_description, false);
+	root = api_add_escape(root, "Msg", buf, false);
+	root = api_add_escape(root, "Description", opt_api_description, false);
 
 	root = print_data(root, ptr, isjson);
 	if (isjson)
@@ -1282,6 +1300,8 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
 	root = api_add_const(root, "OS", OSINFO, false);
 	root = api_add_bool(root, "Failover-Only", &opt_fail_only, false);
 	root = api_add_int(root, "ScanTime", &opt_scantime, false);
+	root = api_add_int(root, "Queue", &opt_queue, false);
+	root = api_add_int(root, "Expiry", &opt_expiry, false);
 
 	root = print_data(root, buf, isjson);
 	if (isjson)
@@ -2789,6 +2809,43 @@ static void debugstate(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __
 	strcat(io_buffer, buf);
 }
 
+static void setconfig(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
+{
+	char *comma;
+	int value;
+
+	if (param == NULL || *param == '\0') {
+		strcpy(io_buffer, message(MSG_CONPAR, 0, NULL, isjson));
+		return;
+	}
+
+	comma = strchr(param, ',');
+	if (!comma) {
+		strcpy(io_buffer, message(MSG_CONVAL, 0, param, isjson));
+		return;
+	}
+
+	*(comma++) = '\0';
+	value = atoi(comma);
+	if (value < 0 || value > 9999) {
+		strcpy(io_buffer, message(MSG_INVNUM, value, param, isjson));
+		return;
+	}
+
+	if (strcasecmp(param, "queue") == 0)
+		opt_queue = value;
+	else if (strcasecmp(param, "scantime") == 0)
+		opt_scantime = value;
+	else if (strcasecmp(param, "expiry") == 0)
+		opt_expiry = value;
+	else {
+		strcpy(io_buffer, message(MSG_UNKCON, 0, param, isjson));
+		return;
+	}
+
+	strcpy(io_buffer, message(MSG_SETCONFIG, value, param, isjson));
+}
+
 static void checkcommand(__maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
 
 struct CMDS {
@@ -2843,6 +2900,7 @@ struct CMDS {
 	{ "failover-only",	failoveronly,	true },
 	{ "coin",		minecoin,	false },
 	{ "debug",		debugstate,	true },
+	{ "setconfig",		setconfig,	true },
 	{ NULL,			NULL,		false }
 };
 

+ 1 - 1
miner.c

@@ -98,7 +98,7 @@ const int opt_cutofftemp = 95;
 static int opt_retries = -1;
 int opt_fail_pause = 5;
 int opt_log_interval = 5;
-static int opt_queue = 1;
+int opt_queue = 1;
 int opt_scantime = 60;
 int opt_expiry = 120;
 int opt_bench_algo = -1;

+ 2 - 0
miner.h

@@ -654,7 +654,9 @@ typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
 
 extern bool fulltest(const unsigned char *hash, const unsigned char *target);
 
+extern int opt_queue;
 extern int opt_scantime;
+extern int opt_expiry;
 
 extern pthread_mutex_t console_lock;
 extern pthread_mutex_t ch_lock;

+ 32 - 15
miner.php

@@ -2,7 +2,7 @@
 session_start();
 #
 global $title, $miner, $port, $readonly, $notify, $rigs;
-global $rigtotals, $forcerigtotals;
+global $rgisecurity, $rigtotals, $forcerigtotals;
 global $socksndtimeoutsec, $sockrcvtimeoutsec;
 global $checklastshare, $poolinputs, $hidefields;
 global $ignorerefresh, $changerefresh, $autorefresh;
@@ -40,6 +40,10 @@ $poolinputs = false;
 #  format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
 $rigs = array('127.0.0.1:4028');
 #
+# Set $rigipsecurity to false to show the IP/Port of the rig
+# in the socket error messages and also show the full socket message
+$rigipsecurity = true;
+#
 # Set $rigtotals to true to display totals on the single rig page
 # 'false' means no totals (and ignores $forcerigtotals)
 # You can force it to always show rig totals when there is only
@@ -226,7 +230,7 @@ function htmlhead($checkapi, $rig, $pg = null)
  if ($readonly === false && $checkapi === true)
  {
 	$error = null;
-	$access = api('privileged');
+	$access = api($rig, 'privileged');
 	if ($error != null
 	||  !isset($access['STATUS']['STATUS'])
 	||  $access['STATUS']['STATUS'] != 'S')
@@ -275,8 +279,9 @@ global $haderror, $error;
 $haderror = false;
 $error = null;
 #
-function getsock($addr, $port)
+function getsock($rig, $addr, $port)
 {
+ global $rigipsecurity;
  global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
 
  $error = null;
@@ -285,9 +290,15 @@ function getsock($addr, $port)
  if ($socket === false || $socket === null)
  {
 	$haderror = true;
-	$error = socket_strerror(socket_last_error());
-	$msg = "socket create(TCP) failed";
-	$error = "ERR: $msg '$error'\n";
+	if ($rigipsecurity === false)
+	{
+		$error = socket_strerror(socket_last_error());
+		$msg = "socket create(TCP) failed";
+		$error = "ERR: $msg '$error'\n";
+	}
+	else
+		$error = "ERR: socket create(TCP) failed\n";
+
 	return null;
  }
 
@@ -301,9 +312,15 @@ function getsock($addr, $port)
  if ($res === false)
  {
 	$haderror = true;
-	$error = socket_strerror(socket_last_error());
-	$msg = "socket connect($addr,$port) failed";
-	$error = "ERR: $msg '$error'\n";
+	if ($rigipsecurity === false)
+	{
+		$error = socket_strerror(socket_last_error());
+		$msg = "socket connect($addr,$port) failed";
+		$error = "ERR: $msg '$error'\n";
+	}
+	else
+		$error = "ERR: socket connect($rig) failed\n";
+
 	socket_close($socket);
 	return null;
  }
@@ -365,12 +382,12 @@ function revert($str)
  return str_replace(array("\1", "\2", "\3", "\4"), array("|", "\\", "=", ","), $str);
 }
 #
-function api($cmd)
+function api($rig, $cmd)
 {
  global $haderror, $error;
  global $miner, $port, $hidefields;
 
- $socket = getsock($miner, $port);
+ $socket = getsock($rig, $miner, $port);
  if ($socket != null)
  {
 	socket_write($socket, $cmd, strlen($cmd));
@@ -1060,7 +1077,7 @@ function processgpus($rig)
  global $error;
  global $warnfont, $warnoff;
 
- $gpus = api('gpucount');
+ $gpus = api($rig, 'gpucount');
 
  if ($error != null)
 	otherrow("<td>Error getting GPU count: $warnfont$error$warnoff</td>");
@@ -1129,7 +1146,7 @@ function process($cmds, $rig)
  $count = count($cmds);
  foreach ($cmds as $cmd => $des)
  {
-	$process = api($cmd);
+	$process = api($rig, $cmd);
 
 	if ($error != null)
 	{
@@ -1244,7 +1261,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
 		else
 			$name = $num;
 
-		$ans = api($cmd);
+		$ans = api($name, $cmd);
 
 		if ($error != null)
 		{
@@ -1756,7 +1773,7 @@ function processcustompage($pagename, $sections, $sum, $namemap)
 
 		foreach ($cmds as $cmd => $one)
 		{
-			$process = api($cmd);
+			$process = api($name, $cmd);
 
 			if ($error != null)
 			{