Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3c7a798

Browse files
committed
Fixed already kicked clients.
1 parent a0d1ec5 commit 3c7a798

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

‎bin/php-proxy-stratum-daemon.php‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function __construct() {
1616
$this->s[] = $c;
1717
$this->l('connected, total: '.($k+1).'.');
1818
$c->on('close', function ($c) {
19-
$this->k(array_search($c, $this->s), 'gone');
19+
if (($k = array_search($c, $this->s))!==FALSE)
20+
$this->k($k, $c, 'gone');
2021
});
2122
$c->on('data', function ($d, $c) use ($l) {
2223
$this->x($d, $c, $l);
@@ -40,9 +41,13 @@ public function __construct() {
4041
}
4142

4243
private function x($_d, $_r, $l) {
43-
$k = array_search($_r, $this->s);
44+
if (($k = array_search($_r, $this->s))===FALSE) {
45+
$_r->close();
46+
$this->l('already kicked.');
47+
return;
48+
}
4449
$_d = $this->o[$k]->d($_d);
45-
if ($_d === FALSE || !($d = json_decode($_d, TRUE))) $this->k($k, 'lost');
50+
if ($_d === FALSE || !($d = json_decode($_d, TRUE))) $this->k($k, $_r, 'lost');
4651
else {
4752
$this->l(((int)$k).' says: '.$_d);
4853
if (isset($d['method'])) {
@@ -59,14 +64,14 @@ private function x($_d, $_r, $l) {
5964
if (isset($d['params']) && isset($d['params'][0]) && $d['params'][0]) {
6065
$this->o[$k]->u = $d['params'][0];
6166
$this->c($l, $k);
62-
} else $this->k($k, 'unkown');
67+
} else $this->k($k, $_r, 'unkown');
6368
} else if ($this->p[$k]) {
6469
if(isset($d['method']) && $d['method']=='mining.submit' && isset($d['params']) && isset($d['params'][0]) and $d['params'][0]==$this->o[$k]->P['user'])
6570
$this->o[$k]->t(-$d['id']);
6671
$this->l('server '.$k.' gets '.$_d);
6772
$this->p[$k]->write($_d);
68-
} else $this->k($k, 'lost server');
69-
} else $this->k($k, 'said garbage');
73+
} else $this->k($k, $_r, 'lost server');
74+
} else $this->k($k, $_r, 'said garbage');
7075
}
7176
}
7277

@@ -86,13 +91,14 @@ private function c($l, $k, $o = 0) {
8691
$this->o[$k]->I = array();
8792
$this->l(((int)$k).' connected to '.$this->o[$k]->P['url'].':'.$this->o[$k]->P['port'].' as '.$this->o[$k]->P['user'].'.');
8893
$s->on('close', function ($s) {
89-
$this->k(array_search($s, $this->p), 'server gone');
94+
if (($k = array_search($s, $this->p))!==FALSE)
95+
$this->k($k, $s, 'server gone');
9096
});
9197
$s->on('data', function ($__d, $s) {
9298
$k = array_search($s, $this->p);
9399
if (isset($this->s[$k])) {
94100
foreach(array_filter(explode(PHP_EOL, $__d)) as $_d) {
95-
if ($_d === FALSE || !($d = json_decode($_d, TRUE))) $this->k($k, 'server lost');
101+
if ($_d === FALSE || !($d = json_decode($_d, TRUE))) $this->k($k, $s, 'server lost');
96102
if (isset($d['id']) && $d['id'] && $d['id'] == $this->o[$k]->s[0]) {
97103
if (isset($d['result']) && isset($d['result'][1]) && $d['result'][1]) {
98104
$this->l(((int)$k).' gets extranonce ["'.$d['result'][1].'", '.$d['result'][2].'].');
@@ -107,16 +113,20 @@ private function c($l, $k, $o = 0) {
107113
if (isset($d['result']) && $d['result']===TRUE && isset($d['id']) && $d['id'])
108114
$this->o[$k]->t($d['id']);
109115
}
110-
} else $this->k($k, 'lost before server');
116+
} else $this->k($k, $s, 'lost before server');
111117
});
112-
} else $this->k($k, 'miss subscribe');
118+
} else $this->k($k, $s, 'miss subscribe');
113119
}, function() use ($k, $n) {
114120
if ($n) $this->c($l, $k, $n);
115-
else $this->k($k, 'lost pools');
121+
else $this->k($k, $this->s[$k], 'lost pools');
116122
});
117123
}
118124

119-
private function k($k, $m) {
125+
private function k($k, $x, $m) {
126+
if ($k===FALSE || !in_array($x, array($this->s[$k], $this->p[$k]), TRUE)) {
127+
$this->l(($k===FALSE?'?':(int)$k).' does not compute.');
128+
return;
129+
}
120130
unset($this->s[$k], $this->p[$k], $this->o[$k]);
121131
$this->s = array_values($this->s);
122132
$this->p = array_values($this->p);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /