コード例 #1
0
ファイル: Peers.php プロジェクト: sbwdlihao/node-php
 /**
  * @param Peer $peer
  */
 public function add(Peer $peer)
 {
     $counter = $this->c++;
     $this->storage[$counter] = $peer;
     $peer->on('close', function () use($counter) {
         unset($this->storage[$counter]);
     });
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: tokenly/bitcoin-p2p-php
 /**
  * @param Peer $peer
  */
 public function registerInboundPeer(Peer $peer)
 {
     $next = $this->nInPeers++;
     $this->inPeers[$next] = $peer;
     $peer->on('close', function () use($next) {
         unset($this->inPeers[$next]);
     });
     $this->emit('inbound', [$peer]);
 }
コード例 #3
0
 /**
  * @param Peer $peer
  */
 public function initPeer(Peer $peer)
 {
     $self = $this;
     $peer->on('inv', array($self, 'onInv'));
     $peer->on('tx', array($self, 'onTx'));
     $peer->on('block', array($self, 'onBlock'));
     $this->on('tx', function (TransactionInterface $tx) {
         $this->processTransaction($tx);
     });
 }
コード例 #4
0
ファイル: P2PService.php プロジェクト: Bit-Wasp/node-php
 /**
  * @param Peer $peer
  */
 private function setupPeer(Peer $peer)
 {
     $peer->on(Message::ADDR, [$this, 'onAddr']);
     $peer->on(Message::BLOCK, [$this, 'onBlock']);
     $peer->on(Message::FEEFILTER, [$this, 'onFeeFilter']);
     $peer->on(Message::FILTERADD, [$this, 'onFilterAdd']);
     $peer->on(Message::FILTERCLEAR, [$this, 'onFilterClear']);
     $peer->on(Message::FILTERLOAD, [$this, 'onFilterLoad']);
     $peer->on(Message::GETADDR, [$this, 'onGetAddr']);
     $peer->on(Message::GETDATA, [$this, 'onGetData']);
     $peer->on(Message::GETBLOCKS, [$this, 'onGetBlocks']);
     $peer->on(Message::GETHEADERS, [$this, 'onGetHeaders']);
     $peer->on(Message::HEADERS, [$this, 'onHeaders']);
     $peer->on(Message::INV, [$this, 'onInv']);
     $peer->on(Message::MEMPOOL, [$this, 'onMemPool']);
     $peer->on(Message::MERKLEBLOCK, [$this, 'onMerkleBlock']);
     $peer->on(Message::NOTFOUND, [$this, 'onNotFound']);
     $peer->on(Message::PING, [$this, 'onPing']);
     $peer->on(Message::PONG, [$this, 'onPong']);
     $peer->on(Message::REJECT, [$this, 'onReject']);
     $peer->on(Message::SENDHEADERS, [$this, 'onSendHeaders']);
     $peer->on('close', [$this, 'onPeerClose']);
 }
コード例 #5
0
 /**
  * @param Peer $peer
  */
 public function setupPeer(Peer $peer)
 {
     echo "New peer: " . $peer->getRemoteAddr()->getIp() . "\n";
     $peer->on('inv', function (Peer $peer, Inv $inv) {
         //echo "INV: " . $peer->getRemoteAddr()->getIp() . "\n";
         $get = [];
         foreach ($inv->getItems() as $item) {
             if ($item->isTx()) {
                 $hash = $item->getHash();
                 if (!$this->Requested($hash->getBinary())) {
                     $this->requestedTx[$hash->getBinary()] = 1;
                     //echo "Request " . $hash->getHex() . "\n";
                     $get[] = $item;
                 }
             }
         }
         if (!empty($get)) {
             $peer->getdata($get);
         }
     });
     $peer->on('tx', function (Peer $peer, Tx $tx) {
         $transaction = $tx->getTransaction();
         $this->handleTransaction($peer, $transaction);
     });
     $peer->on('getdata', function (Peer $peer, GetData $requested) {
         $items = $requested->getItems();
         //echo "peer requested " . count($items) . " items\n";
         foreach ($items as $item) {
             if ($item->isTx()) {
                 $hash = $item->getHash()->getBinary();
                 if ($this->Have($hash)) {
                     /** @var TransactionInterface $tx */
                     $tx = $this->haveTx[$hash];
                     $peer->tx($tx);
                 }
             }
         }
     });
     $this->peers[$peer->getRemoteAddr()->getIp()] = $peer;
 }
コード例 #6
0
 /**
  * @param \BitWasp\Bitcoin\Networking\Peer\Peer $peer
  */
 public function attachPeer(Peer $peer)
 {
     $peer->on('msg', function (Peer $peer, NetworkMessage $message) {
         $this->onPacket($peer, $message);
     });
 }