Skip to content

Commit

Permalink
Merge pull request #78 from clue-labs/events
Browse files Browse the repository at this point in the history
Remove undocumented "connection" event from Server and drop explicit Evenement dependency
  • Loading branch information
clue authored Nov 13, 2018
2 parents c252676 + aa478fe commit 94e41c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
},
"require": {
"php": ">=5.3",
"react/socket": "^1.0 || ^0.8.6",
"react/promise": "^2.1 || ^1.2",
"evenement/evenement": "~3.0|~1.0|~2.0"
"react/socket": "^1.0 || ^0.8.6"
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35",
Expand Down
20 changes: 5 additions & 15 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Clue\React\Socks;

use Evenement\EventEmitter;
use React\Socket\ServerInterface;
use React\Promise;
use React\Promise\Deferred;
Expand All @@ -16,7 +15,7 @@
use \Exception;
use React\Promise\Timer\TimeoutException;

class Server extends EventEmitter
class Server
{
// the following error codes are only used for SOCKS5 only
/** @internal */
Expand Down Expand Up @@ -55,7 +54,6 @@ public function __construct(LoopInterface $loop, ServerInterface $serverInterfac

$that = $this;
$serverInterface->on('connection', function ($connection) use ($that) {
$that->emit('connection', array($connection));
$that->onConnection($connection);
});
}
Expand Down Expand Up @@ -109,13 +107,8 @@ public function unsetAuth()
public function onConnection(ConnectionInterface $connection)
{
$that = $this;
$handling = $this->handleSocks($connection)->then(function($remote) use ($connection){
$connection->emit('ready',array($remote));
}, function ($error) use ($connection, $that) {
if (!($error instanceof \Exception)) {
$error = new \Exception($error);
}
$connection->emit('error', array($error));
$handling = $this->handleSocks($connection)->then(null, function () use ($connection, $that) {
// SOCKS failed => close connection
$that->endConnection($connection);
});

Expand Down Expand Up @@ -282,9 +275,8 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
$remote = str_replace('://', '://' . rawurlencode($username) . ':' . rawurlencode($password) . '@', $remote);
}

return $auth($username, $password, $remote)->then(function () use ($stream, $username) {
return $auth($username, $password, $remote)->then(function () use ($stream) {
// accept
$stream->emit('auth', array($username));
$stream->write(pack('C2', 0x01, 0x00));
}, function() use ($stream) {
// reject => send any code but 0x00
Expand All @@ -298,7 +290,7 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
$stream->write(pack('C2', 0x05, 0xFF));
throw new UnexpectedValueException('No acceptable authentication mechanism found');
}
})->then(function ($method) use ($reader, $stream) {
})->then(function ($method) use ($reader) {
return $reader->readBinary(array(
'version' => 'C',
'command' => 'C',
Expand Down Expand Up @@ -370,7 +362,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)
$uri .= '?source=' . rawurlencode($target[2]);
}

$stream->emit('target', $target);
$that = $this;
$connecting = $this->connector->connect($uri);

Expand All @@ -384,7 +375,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)

// remote end closes connection => stop reading from local end, try to flush buffer to local and disconnect local
$remote->on('end', function() use ($stream, $that) {
$stream->emit('shutdown', array('remote', null));
$that->endConnection($stream);
});

Expand Down

0 comments on commit 94e41c7

Please sign in to comment.