Merge pull request #490 from kanoi/master miner.php mcast changes
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 180 181 182 183 184
diff --git a/API-README b/API-README
index 2829b95..58f185e 100644
--- a/API-README
+++ b/API-README
@@ -1248,6 +1248,28 @@ N.B. the accuracy of the timing used to wait for the replies is
---------
Default:
+ $mcastretries = 0;
+
+Set $mcastretries to the number of times to retry the multicast
+
+If $mcastexpect is 0, this is simply the number of extra times
+that it will send the multicast request
+N.B. cgminer doesn't listen for multicast requests for 1000ms after
+each one it hears
+
+If $mcastexpect is > 0, it will stop looking for replies once it
+has found at least $mcastexpect rigs, but it only checks this rig
+limit each time it reaches the $mcasttimeout limit, thus it can find
+more than $mcastexpect rigs if more exist
+It will send the multicast message up to $mcastretries extra times or
+until it has found at least $mcastexpect rigs
+However, when using $mcastretries, it is possible for it to sometimes
+ignore some rigs on the network if $mcastexpect is less than the
+number of rigs on the network and some rigs are too slow to reply
+
+---------
+
+Default:
$allowgen = false;
Set $allowgen to true to allow customsummarypages to use 'gen'
diff --git a/miner.php b/miner.php
index fdb9e52..a43d9af 100644
--- a/miner.php
+++ b/miner.php
@@ -3,7 +3,7 @@ session_start();
#
global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
-global $mcastlistport, $mcasttimeout, $allowgen;
+global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
global $rigipsecurity, $rigtotals, $forcerigtotals;
global $socksndtimeoutsec, $sockrcvtimeoutsec;
global $checklastshare, $poolinputs, $hidefields;
@@ -70,6 +70,9 @@ $mcastlistport = 4027;
# to wait for replies to the Multicast message
$mcasttimeout = 1.5;
#
+# Set $mcastretries to the number of times to retry the multicast
+$mcastretries = 0;
+#
# Set $allowgen to true to allow customsummarypages to use 'gen'
# false means ignore any 'gen' options
$allowgen = false;
@@ -373,10 +376,10 @@ global $haderror, $error;
$haderror = false;
$error = null;
#
-function getrigs()
+function mcastrigs()
{
- global $rigs, $mcastaddr, $mcastport, $mcastcode;
- global $mcastlistport, $mcasttimeout, $error;
+ global $rigs, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
+ global $mcastlistport, $mcasttimeout, $mcastretries, $error;
$listname = "0.0.0.0";
@@ -414,56 +417,78 @@ function getrigs()
return;
}
- $mcast_soc = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- if ($mcast_soc === false || $mcast_soc == null)
+ $retries = $mcastretries;
+ $doretry = ($retries > 0);
+ do
{
- $msg = "ERR: mcast send socket create(UDP) failed";
- if ($rigipsecurity === false)
+ $mcast_soc = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ if ($mcast_soc === false || $mcast_soc == null)
{
- $error = socket_strerror(socket_last_error());
- $error = "$msg '$error'\n";
- }
- else
- $error = "$msg\n";
+ $msg = "ERR: mcast send socket create(UDP) failed";
+ if ($rigipsecurity === false)
+ {
+ $error = socket_strerror(socket_last_error());
+ $error = "$msg '$error'\n";
+ }
+ else
+ $error = "$msg\n";
- socket_close($rep_soc);
- return;
- }
+ socket_close($rep_soc);
+ return;
+ }
- $buf = "cgminer-$mcastcode-$mcastlistport";
- socket_sendto($mcast_soc, $buf, strlen($buf), 0, $mcastaddr, $mcastport);
- socket_close($mcast_soc);
+ $buf = "cgminer-$mcastcode-$mcastlistport";
+ socket_sendto($mcast_soc, $buf, strlen($buf), 0, $mcastaddr, $mcastport);
+ socket_close($mcast_soc);
- $stt = microtime(true);
- while (true)
- {
- $got = @socket_recvfrom($rep_soc, $buf, 32, MSG_DONTWAIT, $ip, $p);
- if ($got !== false && $got > 0)
+ $stt = microtime(true);
+ while (true)
{
- $ans = explode('-', $buf, 4);
- if (count($ans) >= 3 && $ans[0] == 'cgm' && $ans[1] == 'FTW')
+ $got = @socket_recvfrom($rep_soc, $buf, 32, MSG_DONTWAIT, $ip, $p);
+ if ($got !== false && $got > 0)
{
- $rp = intval($ans[2]);
+ $ans = explode('-', $buf, 4);
+ if (count($ans) >= 3 && $ans[0] == 'cgm' && $ans[1] == 'FTW')
+ {
+ $rp = intval($ans[2]);
- if (count($ans) > 3)
- $mdes = str_replace("\0", '', $ans[3]);
- else
- $mdes = '';
+ if (count($ans) > 3)
+ $mdes = str_replace("\0", '', $ans[3]);
+ else
+ $mdes = '';
- if (strlen($mdes) > 0)
- $rigs[] = "$ip:$rp:$mdes";
- else
- $rigs[] = "$ip:$rp";
+ if (strlen($mdes) > 0)
+ $rig = "$ip:$rp:$mdes";
+ else
+ $rig = "$ip:$rp";
+
+ if (!in_array($rig, $rigs))
+ $rigs[] = $rig;
+ }
}
+ if ((microtime(true) - $stt) >= $mcasttimeout)
+ break;
+
+ usleep(100000);
}
- if ((microtime(true) - $stt) >= $mcasttimeout)
- break;
- usleep(100000);
- }
+ if ($mcastexpect > 0 && count($rigs) >= $mcastexpect)
+ $doretry = false;
+
+ } while ($doretry && --$retries > 0);
+
socket_close($rep_soc);
}
#
+function getrigs()
+{
+ global $rigs;
+
+ mcastrigs();
+
+ sort($rigs);
+}
+#
function getsock($rig, $addr, $port)
{
global $rigipsecurity;