示例#1
0
 public function testPeer()
 {
     $localhost = '127.0.0.1';
     $localport = '8333';
     $remotehost = '127.0.0.1';
     $remoteport = '9999';
     $loop = new StreamSelectLoop();
     $dnsResolverFactory = new \React\Dns\Resolver\Factory();
     $dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);
     $reactServer = new Server($loop);
     $network = Bitcoin::getDefaultNetwork();
     $client = new NetworkAddress(Buffer::hex('0000000000000001'), $localhost, $localport);
     $server = new NetworkAddress(Buffer::hex('0000000000000001'), $remotehost, $remoteport);
     $msgs = new Factory($network, new Random());
     $serverReceivedConnection = false;
     $serverListener = new Listener($server, $msgs, $reactServer, $loop);
     $serverListener->on('connection', function (Peer $peer) use(&$serverReceivedConnection, &$serverListener) {
         $peer->close();
         $serverReceivedConnection = true;
     });
     $serverListener->listen($server->getPort());
     $connector = new Connector($loop, $dns);
     $clientConnection = new Peer($client, $msgs, $loop);
     $clientConnection->connect($connector, $server)->then(function (Peer $peer) use($serverListener, &$loop) {
         $peer->close();
         $serverListener->close();
     });
     $loop->run();
     $this->assertTrue($serverReceivedConnection);
 }
示例#2
0
 /**
  * @param Listener $listener
  * @return $this
  */
 public function registerListener(Listener $listener)
 {
     $listener->on('connection', function (Peer $peer) {
         $this->registerInboundPeer($peer);
     });
     return $this;
 }