Exemplo n.º 1
0
 /**
  * @return \React\Promise\PromiseInterface|static
  */
 public function connectNextPeer()
 {
     $addr = new Deferred();
     try {
         $addr->resolve($this->locator->popAddress());
     } catch (\Exception $e) {
         $this->locator->queryDnsSeeds(1)->then(function (Locator $locator) use($addr) {
             $addr->resolve($locator->popAddress());
         });
     }
     return $addr->promise()->then(function (NetworkAddressInterface $host) {
         $goodPeer = new Deferred();
         $this->connector->connect($host)->then(function (Peer $peer) use($goodPeer) {
             $check = $this->checkAcceptablePeer($peer);
             if (false === $check) {
                 $peer->close();
                 $goodPeer->reject();
             } else {
                 $goodPeer->resolve($peer);
             }
         }, function () use($goodPeer) {
             $goodPeer->reject();
         });
         return $goodPeer->promise();
     })->then(function (Peer $peer) {
         $this->manager->registerOutboundPeer($peer);
     }, function () {
         return $this->connectNextPeer();
     });
 }
Exemplo n.º 2
0
 /**
  * @param Locator $locator
  * @return \React\Promise\ExtendedPromiseInterface|\React\Promise\Promise|static
  */
 public function connectNextPeer(Locator $locator)
 {
     $deferred = new Deferred();
     // Otherwise, rely on the Locator.
     try {
         $deferred->resolve($locator->popAddress());
     } catch (\Exception $e) {
         $locator->queryDnsSeeds()->then(function () use($deferred, $locator) {
             $deferred->resolve($locator->popAddress());
         });
     }
     return $deferred->promise()->then(function (NetworkAddressInterface $address) {
         return $this->connect($address)->then(function (Peer $peer) {
             $this->registerOutboundPeer($peer);
             return $peer;
         });
     })->otherwise(function () use($locator) {
         return $this->connectNextPeer($locator);
     });
 }