Skip to content

Commit

Permalink
Merge pull request #13 from ycgambo/dev
Browse files Browse the repository at this point in the history
trace port for Guarder
  • Loading branch information
ycgambo authored May 1, 2018
2 parents e65a9a8 + caf056d commit 4820a82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/shadowrocket/Module/Base/GuarderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions src/shadowrocket/Module/Guarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ 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)
{
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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/shadowrocket/Module/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ 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;
}
}
$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;
}
Expand Down

0 comments on commit 4820a82

Please sign in to comment.