/** * @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(); }); }
public function testSeedHosts() { $hosts = Locator::dnsSeedHosts(false); $hostsRandom = Locator::dnsSeedHosts(); $this->assertInternalType('array', $hosts); $this->assertInternalType('array', $hostsRandom); $this->assertNotEquals($hosts, $hostsRandom); }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(' Known DNS seeds:'); foreach (Locator::dnsSeedHosts(false) as $seed) { $output->writeln(" - " . $seed); } return 0; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $loop = \React\EventLoop\Factory::create(); $seed = $input->getOption('seed') ?: Locator::dnsSeedHosts()[0]; $factory = new \BitWasp\Bitcoin\Networking\Factory($loop); $factory->getDns()->resolve($seed)->then(function ($ipArr) use($seed, $output, $loop) { $output->writeln(' Results from ' . $seed); foreach ($ipArr as $ip) { $output->writeln(' - ' . $ip); } }); $loop->run(); return 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); }); }