@@ -107,13 +107,8 @@ public function unsetAuth()
107107 public function onConnection (ConnectionInterface $ connection )
108108 {
109109 $ that = $ this ;
110- $ handling = $ this ->handleSocks ($ connection )->then (function ($ remote ) use ($ connection ){
111- $ connection ->emit ('ready ' ,array ($ remote ));
112- }, function ($ error ) use ($ connection , $ that ) {
113- if (!($ error instanceof \Exception)) {
114- $ error = new \Exception ($ error );
115- }
116- $ connection ->emit ('error ' , array ($ error ));
110+ $ handling = $ this ->handleSocks ($ connection )->then (null , function () use ($ connection , $ that ) {
111+ // SOCKS failed => close connection
117112 $ that ->endConnection ($ connection );
118113 });
119114
@@ -280,9 +275,8 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
280275 $ remote = str_replace (':// ' , ':// ' . rawurlencode ($ username ) . ': ' . rawurlencode ($ password ) . '@ ' , $ remote );
281276 }
282277
283- return $ auth ($ username , $ password , $ remote )->then (function () use ($ stream, $ username ) {
278+ return $ auth ($ username , $ password , $ remote )->then (function () use ($ stream ) {
284279 // accept
285- $ stream ->emit ('auth ' , array ($ username ));
286280 $ stream ->write (pack ('C2 ' , 0x01 , 0x00 ));
287281 }, function () use ($ stream ) {
288282 // reject => send any code but 0x00
@@ -296,7 +290,7 @@ public function handleSocks5(ConnectionInterface $stream, $auth=null, StreamRead
296290 $ stream ->write (pack ('C2 ' , 0x05 , 0xFF ));
297291 throw new UnexpectedValueException ('No acceptable authentication mechanism found ' );
298292 }
299- })->then (function ($ method ) use ($ reader, $ stream ) {
293+ })->then (function ($ method ) use ($ reader ) {
300294 return $ reader ->readBinary (array (
301295 'version ' => 'C ' ,
302296 'command ' => 'C ' ,
@@ -368,7 +362,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)
368362 $ uri .= '?source= ' . rawurlencode ($ target [2 ]);
369363 }
370364
371- $ stream ->emit ('target ' , $ target );
372365 $ that = $ this ;
373366 $ connecting = $ this ->connector ->connect ($ uri );
374367
@@ -382,7 +375,6 @@ public function connectTarget(ConnectionInterface $stream, array $target)
382375
383376 // remote end closes connection => stop reading from local end, try to flush buffer to local and disconnect local
384377 $ remote ->on ('end ' , function () use ($ stream , $ that ) {
385- $ stream ->emit ('shutdown ' , array ('remote ' , null ));
386378 $ that ->endConnection ($ stream );
387379 });
388380
0 commit comments