/** * @param NetworkAddressInterface $remotePeer * @return \React\Promise\PromiseInterface */ public function rawConnect(NetworkAddressInterface $remotePeer) { return $this->socketConnector->create($remotePeer->getIp()->getHost(), $remotePeer->getPort())->then(function (Stream $stream) { $peer = new Peer($this->msgs, $this->eventLoop); $peer->setupStream($stream); return $peer; }); }
/** * @param Connector $connector * @param NetworkAddressInterface $remoteAddr * @return \React\Promise\Promise|\React\Promise\PromiseInterface */ public function connect(Connector $connector, NetworkAddressInterface $remoteAddr) { $deferred = new Deferred(); $this->remoteAddr = $remoteAddr; $this->inbound = false; $connector->create($this->remoteAddr->getIp(), $this->remoteAddr->getPort())->then(function (Stream $stream) use($deferred) { $this->stream = $stream; $this->setupConnection(); $this->on('version', function () { $this->verack(); }); $this->on('verack', function () use($deferred) { if (false === $this->exchangedVersion) { $this->exchangedVersion = true; $this->emit('ready', [$this]); $deferred->resolve($this); } }); $this->version(); }, function ($error) use($deferred) { $deferred->reject($error); }); return $deferred->promise(); }
/** * Saves a NetworkAddress from the cache * @param NetworkAddressInterface $networkAddress */ public function save(NetworkAddressInterface $networkAddress) { $new = $this->getEnd() + 1; $this->cache->save($new, $networkAddress->getIp()); $this->setEnd($new); }