diff --git a/src/shadowrocket/Module/Base/GuarderInterface.php b/src/shadowrocket/Module/Base/GuarderInterface.php index fc53113..c4b5882 100644 --- a/src/shadowrocket/Module/Base/GuarderInterface.php +++ b/src/shadowrocket/Module/Base/GuarderInterface.php @@ -34,7 +34,8 @@ public function block($request, $port); /** * If false returned, connection between client and remote will be closed. * @param $data string the data come in and go out this server + * @param $port * @return mixed */ - public function inspectFailed($data); + public function inspectFailed($data, $port); } \ No newline at end of file diff --git a/src/shadowrocket/Module/Guarder.php b/src/shadowrocket/Module/Guarder.php index 3ed8524..76732c6 100644 --- a/src/shadowrocket/Module/Guarder.php +++ b/src/shadowrocket/Module/Guarder.php @@ -44,9 +44,9 @@ public function _block($request, $port) return $this->getConfig('instance')->block($request, $port); } - public function _inspectFailed($data) + public function _inspectFailed($data, $port) { - return $this->getConfig('instance')->inspectFailed($data); + return $this->getConfig('instance')->inspectFailed($data, $port); } public function deny($request, $port) @@ -54,12 +54,12 @@ public function deny($request, $port) return false; } - public function block($request, $prot) + public function block($request, $port) { return false; } - public function inspectFailed($data) + public function inspectFailed($data, $port) { return false; } diff --git a/src/shadowrocket/Module/Server.php b/src/shadowrocket/Module/Server.php index e9a0b99..b486b59 100644 --- a/src/shadowrocket/Module/Server.php +++ b/src/shadowrocket/Module/Server.php @@ -115,10 +115,10 @@ protected function createWorker($protocol, $superadd = false) Connection::bind($client, $remote); // 远程连接发来消息时,进行加密,转发给shadowsocks客户端,shadowsocks客户端会解密转发给浏览器 - $remote->onMessage = function ($remote, $buffer) { + $remote->onMessage = function ($remote, $buffer) use ($config) { $data = $remote->opposite->cipher->encrypt($buffer); if ($guarder = Launcher::getModuleIfReady('guarder')) { - if ($guarder->_inspectFailed($data)) { + if ($guarder->_inspectFailed($data, $config['port'])) { $remote->close(); return; } @@ -126,10 +126,10 @@ protected function createWorker($protocol, $superadd = false) $remote->opposite->send($data); }; // 当shadowsocks客户端发来数据时,解密数据,并发给远程服务端 - $client->onMessage = function ($client, $data) { + $client->onMessage = function ($client, $data) use ($config) { $data = $client->cipher->decrypt($data); if ($guarder = Launcher::getModuleIfReady('guarder')) { - if ($guarder->_inspectFailed($data)) { + if ($guarder->_inspectFailed($data, $config['port'])) { $client->close(); return; }