Beispiel #1
0
 def __init__(
     self,
     privkey: datatypes.PrivateKey,
     address: Address,
     network_id: int,
     min_peers: int = 0,
     peer_class: Type[BasePeer] = ShardingPeer,
     peer_pool_class: Type[PeerPool] = PeerPool,
     bootstrap_nodes: List[str] = [],
 ) -> None:
     BaseService.__init__(self, CancelToken('ShardingServer'))
     self.privkey = privkey
     self.address = address
     self.network_id = network_id
     self.peer_class = peer_class
     self.discovery = DiscoveryProtocol(self.privkey,
                                        self.address,
                                        bootstrap_nodes=bootstrap_nodes)
     # XXX: This is not supposed to work and causes both the PeerPool and Server to crash, but
     # the tests in test_sharding.py don't seem to care
     self.headerdb = None
     self.peer_pool = peer_pool_class(
         peer_class,
         self.headerdb,
         self.network_id,
         self.privkey,
         self.discovery,
         min_peers=min_peers,
     )
     shard_db = ShardDB(MemoryDB())
     shard = Shard(shard_db, 0)
     self.syncer = ShardSyncer(shard, self.peer_pool,
                               self.cancel_token)  # type: ignore
Beispiel #2
0
 def __init__(self,
              headerdb: BaseAsyncHeaderDB,
              peer_pool: LESPeerPool,
              token: CancelToken = None) -> None:
     PeerSubscriber.__init__(self)
     BaseService.__init__(self, token)
     self.headerdb = headerdb
     self.peer_pool = peer_pool
     self._pending_replies = weakref.WeakValueDictionary()
Beispiel #3
0
 def __init__(self, connection: ConnectionAPI,
              request_protocol: ProtocolAPI,
              response_cmd_type: Type[CommandAPI]) -> None:
     # This style of initialization keeps `mypy` happy.
     BaseService.__init__(self, token=connection.cancel_token)
     self._connection = connection
     self.request_protocol = request_protocol
     self.response_cmd_type = response_cmd_type
     self._lock = asyncio.Lock()
Beispiel #4
0
 def __init__(self,
              headerdb: BaseAsyncHeaderDB,
              peer_pool: LESPeerPool,
              token: CancelToken = None) -> None:
     PeerSubscriber.__init__(self)
     BaseService.__init__(self, token)
     self.headerdb = headerdb
     self.peer_pool = peer_pool
     self._pending_replies: Dict[int, Callable[[Payload], None]] = {}
Beispiel #5
0
 def __init__(self,
              headerdb: 'BaseAsyncHeaderDB',
              peer_pool: PeerPool,
              token: CancelToken = None) -> None:
     PeerPoolSubscriber.__init__(self)
     BaseService.__init__(self, token)
     self.headerdb = headerdb
     self.peer_pool = peer_pool
     self._pending_replies: Dict[int, Callable[[protocol._DecodedMsgType],
                                               None]] = {}
Beispiel #6
0
    def __init__(self, connection: ConnectionAPI,
                 request_protocol_type: Type[ProtocolAPI],
                 response_cmd_type: Type[CommandAPI]) -> None:
        # This style of initialization keeps `mypy` happy.
        BaseService.__init__(self, token=connection.cancel_token)
        self._connection = connection
        self.request_protocol_type = request_protocol_type
        try:
            self.request_protocol = self._connection.get_multiplexer(
            ).get_protocol_by_type(request_protocol_type, )
        except UnknownProtocol as err:
            raise UnknownProtocol(
                f"Response candidate stream configured to use "
                f"{request_protocol_type} which is not available in the "
                f"Multiplexer") from err

        self.response_cmd_type = response_cmd_type
        self._lock = asyncio.Lock()