@@ -59,9 +59,10 @@ private function x($r) {
5959 $ this ->l ($ k .' gets: ' .$ _d );
6060 socket_write ($ this ->s [$ k ], $ _d );
6161 }
62- if (isset ($ d ['method ' ]) && $ d ['method ' ]=='mining.set_difficulty ' && isset ($ d ['params ' ]) && isset ($ d ['params ' ][0 ]))
62+ if (isset ($ d ['method ' ]) && $ d ['method ' ]=='mining.set_difficulty ' && isset ($ d ['params ' ]) && isset ($ d ['params ' ][0 ]))
6363 $ this ->o [$ k ]->F = $ d ['params ' ][0 ];
64- $ this ->o [$ k ]->t ();
64+ if (isset ($ d ['result ' ]) && $ d ['result ' ]===true && isset ($ d ['id ' ]) && $ d ['id ' ])
65+ $ this ->o [$ k ]->t ($ d ['id ' ]);
6566 } else $ this ->k ($ k , 'lost before server ' );
6667 } else {
6768 $ this ->l ($ k .' says: ' .$ _d );
@@ -82,7 +83,7 @@ private function x($r) {
8283 } else $ this ->k ($ k , 'unkown. ' );
8384 } else if ($ this ->p [$ k ]) {
8485 if (isset ($ d ['method ' ]) && $ d ['method ' ]=='mining.submit ' && isset ($ d ['params ' ]) && isset ($ d ['params ' ][0 ]) and $ d ['params ' ][0 ]==$ this ->o [$ k ]->P [2 ])
85- $ this ->o [$ k ]->t (TRUE );
86+ $ this ->o [$ k ]->t (- $ d [ ' id ' ] );
8687 $ this ->l ('server ' .$ k .' gets ' .$ _d );
8788 socket_write ($ this ->p [$ k ], $ _d );
8889 } else $ this ->k ($ k , 'lost server ' );
@@ -98,6 +99,7 @@ private function c($k, $o = 0) {
9899 else if ($ this ->o [$ k ]->s ) {
99100 socket_write ($ this ->p [$ k ], $ this ->o [$ k ]->s [1 ]);
100101 socket_write ($ this ->p [$ k ], '{"id": ' .($ this ->o [$ k ]->s [0 ]+1 ).', "method": "mining.authorize", "params": [" ' .$ p [2 ].'", " ' .$ p [3 ].'"]} ' ."\n" );
102+ $ this ->o [$ k ]->I = array ();
101103 $ this ->l ($ k .' connected to ' .$ p [0 ].': ' .$ p [1 ].' as ' .$ p [2 ].'. ' );
102104 } else $ this ->k ($ k , 'miss subscribe. ' );
103105 }
@@ -123,6 +125,7 @@ private function h($h) {
123125 'user ' =>$ o ->u ,
124126 'version ' =>$ o ->v ,
125127 'pool ' =>$ o ->P ,
128+ 'pending ' =>$ o ->I ,
126129 'diff ' =>$ o ->F ,
127130 '5min GHps avg ' =>number_format ($ o ->H , 2 , ', ' , '. ' )
128131 );
@@ -148,8 +151,9 @@ private function l($m) { return;
148151class U {
149152 public $ v = NULL ;
150153 public $ s = NULL ;
154+ public $ I = array ();
151155 public $ S = array ();
152- public $ H = ' 0,00 ' ;
156+ public $ H = 0 ;
153157 public $ Ht = array (0 );
154158 public $ F = 0 ;
155159 public $ P = NULL ;
@@ -188,16 +192,21 @@ public function c($p, $o = 0) {
188192 return FALSE ;
189193 }
190194
191- public function t ($ F = FALSE ) {
195+ public function t ($ I ) {
192196 $ t = (string )microtime (TRUE );
193- if ($ F ) {
197+ if ($ I <0 ) $ this ->I [abs ($ I )] = $ t ;
198+ else if (isset ($ this ->I [$ I ])) {
194199 if (!isset ($ this ->S [$ t ])) $ this ->S [$ t ] = 0 ;
195200 $ this ->S [$ t ] += $ this ->F ;
201+ unset($ this ->I [$ I ]);
202+ if ($ c = count ($ k = array_keys ($ this ->I )))
203+ for ($ i =0 ;$ i <$ c ;$ i ++) if ($ this ->I [$ k [$ i ]]<$ t -21 ) unset($ this ->I [$ k [$ i ]]); else break ;
204+ }
205+ if ($ c = count ($ k = array_keys ($ this ->S ))) { # pow(2,48)/65535/300/1e9
206+ for ($ i =0 ;$ i <$ c ;$ i ++) if ($ k [$ i ]<$ t -300 ) unset($ this ->S [$ k [$ i ]]); else break ;
207+ $ this ->Ht [] = bcmul (0.01431677611 , array_sum ($ this ->S ?:array (0 )), 2 );
208+ $ this ->H = bcdiv (array_sum ($ this ->Ht = array_slice ($ this ->Ht , -99 )), count ($ this ->Ht ), 2 );
196209 }
197- $ c = count ($ k = array_keys ($ this ->S )); # pow(2,48)/65535/300/1e9
198- for ($ i =0 ;$ i <$ c ;$ i ++) if ($ k [$ i ]<$ t -300 ) unset($ this ->S [$ k [$ i ]]); else break ;
199- $ this ->Ht [] = bcmul (0.01431677611 , array_sum ($ this ->S ?:array (0 )), 2 );
200- $ this ->H = bcdiv (array_sum ($ this ->Ht = array_slice ($ this ->Ht , -99 )), count ($ this ->Ht ), 2 );
201210 }
202211
203212 public function d ($ d ) {
0 commit comments