/** * @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(); }); }
/** * @param NetworkAddressInterface $address * @return \React\Promise\PromiseInterface * @throws \Exception */ public function connect(NetworkAddressInterface $address) { return $this->connector->connect($address); }