(self, peer)
Call this method when a peer comes online and you want to keep its mempool
        in sync with this mempool.
Call this method when a peer comes online and you want to keep its mempool
        in sync with this mempool.
Call this method when a peer comes online and you want to keep its mempool in sync with this mempool .
def add_peer(self, peer):
        """
        Call this method when a peer comes online and you want to keep its mempool
        in sync with this mempool.
        """
        @asyncio.coroutine
        def _run_getdata(next_message):
            while True:
                name, data = yield from next_message()
                inv_items = data["items"]
                not_found = []
                txs_found = []
                for inv_item in inv_items:
                    if inv_item.item_type != ITEM_TYPE_TX:
                        continue
                    tx = self.tx_store.get(inv_item.data)
                    if tx:
                        txs_found.append(tx)
                    else:
                        not_found.append(inv_item)
                if not_found:
                    peer.send_msg("notfound", items=not_found)
                for tx in txs_found:
                    peer.send_msg("tx", tx=tx)

        @asyncio.coroutine
        def _run_mempool(next_message):
            try:
                name, data = yield from next_message()
                inv_items = [InvItem(ITEM_TYPE_TX, tx.hash()) for tx in self.tx_store.values()]
                logging.debug("sending inv of %d item(s) in response to mempool", len(inv_items))
                if len(inv_items) > 0:
                    peer.send_msg("inv", items=inv_items)
                # then we exit. We don't need to handle this message more than once.
            except EOFError:
                pass

        next_getdata = peer.new_get_next_message_f(lambda name, data: name == 'getdata')
        peer.add_task(_run_getdata(next_getdata))
        next_mempool = peer.new_get_next_message_f(lambda name, data: name == 'mempool')
        peer.add_task(_run_mempool(next_mempool))
        peer.send_msg("mempool")
def add_peer ( self , peer ) : @ asyncio . coroutine def _run_getdata ( next_message ) : while True : name , data = yield from next_message ( ) inv_items = data [ "items" ] not_found = [ ] txs_found = [ ] for inv_item in inv_items : if inv_item . item_type != ITEM_TYPE_TX : continue tx = self . tx_store . get ( inv_item . data ) if tx : txs_found . append ( tx ) else : not_found . append ( inv_item ) if not_found : peer . send_msg ( "notfound" , items = not_found ) for tx in txs_found : peer . send_msg ( "tx" , tx = tx ) @ asyncio . coroutine def _run_mempool ( next_message ) : try : name , data = yield from next_message ( ) inv_items = [ InvItem ( ITEM_TYPE_TX , tx . hash ( ) ) for tx in self . tx_store . values ( ) ] logging . debug ( "sending inv of %d item(s) in response to mempool" , len ( inv_items ) ) if len ( inv_items ) > 0 : peer . send_msg ( "inv" , items = inv_items ) # then we exit. We don't need to handle this message more than once. except EOFError : pass next_getdata = peer . new_get_next_message_f ( lambda name , data : name == 'getdata' ) peer . add_task ( _run_getdata ( next_getdata ) ) next_mempool = peer . new_get_next_message_f ( lambda name , data : name == 'mempool' ) peer . add_task ( _run_mempool ( next_mempool ) ) peer . send_msg ( "mempool" )