Exemplo n.º 1
0
 public function runPing($socket, App $app)
 {
     try {
         $parsed = $app->parseSocksSocket($socket);
     } catch (Exception $e) {
         echo 'error: invalid ping target: ' . $e->getMessage() . PHP_EOL;
         return;
     }
     // TODO: remove hack
     // resolver can not resolve 'localhost' ATM
     if ($parsed['host'] === 'localhost') {
         $parsed['host'] = '127.0.0.1';
     }
     $direct = new Connector($app->getLoop(), $app->getResolver());
     $via = new Client($parsed['host'] . ':' . $parsed['port'], $app->getLoop(), $direct, $app->getResolver());
     if (isset($parsed['protocolVersion'])) {
         try {
             $via->setProtocolVersion($parsed['protocolVersion']);
         } catch (Exception $e) {
             echo 'error: invalid protocol version: ' . $e->getMessage() . PHP_EOL;
             return;
         }
     }
     if (isset($parsed['user']) || isset($parsed['pass'])) {
         $parsed += array('user' => '', 'pass' => '');
         try {
             $via->setAuth($parsed['user'], $parsed['pass']);
         } catch (Exception $e) {
             echo 'error: invalid authentication info: ' . $e->getMessage() . PHP_EOL;
             return;
         }
     }
     try {
         $via->setResolveLocal(false);
     } catch (UnexpectedValueException $ignore) {
         // ignore in case it's not allowed (SOCKS4 client)
     }
     $this->pingEcho($via->createConnector(), 'www.google.com', 80);
 }
Exemplo n.º 2
0
 public function run(App $app)
 {
     echo 'exiting...';
     $app->getLoop()->stop();
     echo PHP_EOL;
 }