@@ -79,46 +79,18 @@ public function unsetAuth()
7979
8080 public function onConnection (Connection $ connection )
8181 {
82-
83- $ line = function ($ msg ) use ($ connection ) {
84- echo date ('Y-m-d H:i:s ' ) . ' # ' . (int )$ connection ->stream . ' ' . $ msg . PHP_EOL ;
85- };
86-
87- $ line ('connect ' );
82+ // $this->emit('connection', array($connection));
8883
8984 $ that = $ this ;
9085 $ loop = $ this ->loop ;
91- $ this ->handleSocks ($ connection )->then (function ($ remote ) use ($ line , $ connection ){
92- $ line ('tunnel successfully estabslished ' );
86+ $ this ->handleSocks ($ connection )->then (function ($ remote ) use ($ connection ){
9387 $ connection ->emit ('ready ' ,array ($ remote ));
94- }, function ($ error ) use ($ connection , $ line , $ that ) {
95- if ($ error instanceof \Exception) {
96- $ msg = $ error ->getMessage ();
97- while ($ error ->getPrevious () !== null ) {
98- $ error = $ error ->getPrevious ();
99- $ msg .= ' - ' . $ error ->getMessage ();
100- }
101-
102- $ line ('error: ' . $ msg );
103- } else {
104- $ line ('error ' );
105- var_dump ($ error );
88+ }, function ($ error ) use ($ connection , $ that ) {
89+ if (!($ error instanceof \Exception)) {
90+ $ error = new \Exception ($ error );
10691 }
107-
92+ $ connection -> emit ( ' error ' , array ( $ error ));
10893 $ that ->endConnection ($ connection );
109-
110- // }, function ($progress) use ($line) {
111- // //$s = new StreamReader();
112- // $line('progress: './*$s->s*/($progress));
113- });
114-
115- $ that = $ this ;
116- $ connectionManager = $ this ->connectionManager ;
117- $ connection ->on ('target ' , function ($ host , $ port ) use ( $ line ) {
118- $ line ('target: ' . $ host . ': ' . $ port );
119- });
120- $ connection ->on ('close ' , function () use ($ line ) {
121- $ line ('disconnect ' );
12294 });
12395 }
12496
@@ -325,9 +297,9 @@ public function handleSocks5(Stream $stream, $auth=null)
325297 });
326298 }
327299
328- public function connectTarget (Stream $ stream , $ target )
300+ public function connectTarget (Stream $ stream , array $ target )
329301 {
330- $ stream ->emit ('target ' ,$ target );
302+ $ stream ->emit ('target ' , $ target );
331303 $ that = $ this ;
332304 return $ this ->connectionManager ->getConnection ($ target [0 ], $ target [1 ])->then (function (Stream $ remote ) use ($ stream , $ that ) {
333305 if (!$ stream ->isWritable ()) {
0 commit comments