コード例 #1
0
ファイル: test_net.py プロジェクト: yzernik/squeak
    def test_serialization(self, verifying_key, fake_squeak_hash):
        # pubkey_bytes = verifying_key.to_bytes()
        interested = [
            CInterested([verifying_key, verifying_key, verifying_key], -1, 10,
                        fake_squeak_hash),
            CInterested([verifying_key], 30, 2000),
            CInterested(
                nMinBlockHeight=0,
                nMaxBlockHeight=100,
                hashReplySqk=fake_squeak_hash,
            ),
        ]
        locator = CSqueakLocator(interested)
        stream = _BytesIO()
        locator.stream_serialize(stream)
        serialized = _BytesIO(stream.getvalue())
        deserialized = CSqueakLocator.stream_deserialize(serialized)

        assert deserialized == locator
        assert len(deserialized.vInterested) == 3
        assert deserialized.vInterested[0].pubkeys == (verifying_key,
                                                       verifying_key,
                                                       verifying_key)
        assert deserialized.vInterested[1].pubkeys == (verifying_key, )
        assert deserialized.vInterested[2].pubkeys == ()
        assert deserialized.vInterested[
            1].hashReplySqk == b'\x00' * HASH_LENGTH
        assert deserialized.vInterested[2].hashReplySqk == fake_squeak_hash
コード例 #2
0
 def get_interested_locator(self) -> CSqueakLocator:
     block_range = self.get_block_range()
     followed_addresses = self.get_followed_addresses()
     if len(followed_addresses) == 0:
         return CSqueakLocator(vInterested=[], )
     interests = [
         CInterested(
             addresses=[
                 CSqueakAddress(address) for address in followed_addresses
             ],
             nMinBlockHeight=block_range.min_block,
             nMaxBlockHeight=block_range.max_block,
         )
     ]
     return CSqueakLocator(vInterested=interests, )
コード例 #3
0
 def get_download_msg(self) -> MsgSerializable:
     locator = CSqueakLocator(
         vInterested=[self.interest],
     )
     return msg_getsqueaks(
         locator=locator,
     )
コード例 #4
0
def test_download_interest_initiate(download_interest, interest):
    broadcast_fn = mock.Mock()
    download_interest.initiate_download(broadcast_fn)

    expected_msg = msg_getsqueaks(
        locator=CSqueakLocator(vInterested=[interest], ))

    broadcast_fn.assert_called_once_with(expected_msg)
コード例 #5
0
ファイル: peer.py プロジェクト: azernik/squeakserver
    def update_local_subscription(self, locator: CSqueakLocator):
        assert len(locator.vInterested) <= 1
        if len(locator.vInterested) == 0:
            locator = None

        # Send the subscribe message
        subscribe_msg = msg_subscribe(locator=locator, )
        self.send_msg(subscribe_msg)

        # Send the getsqueaks messages for differential interests
        if locator is not None:
            for interest in self.get_differential_interests(locator):
                diff_locator = CSqueakLocator(vInterested=[interest])
                getsqueaks_msg = msg_getsqueaks(locator=diff_locator, )
                self.send_msg(getsqueaks_msg)

        # Set the local subscription with the new value
        self.set_local_subscription(locator)
コード例 #6
0
 def msg_deser(cls, f, protover=PROTO_VERSION):
     locator = CSqueakLocator.stream_deserialize(f)
     return cls(locator)
コード例 #7
0
 def __init__(self, locator=None, protover=PROTO_VERSION):
     super(msg_subscribe, self).__init__(protover)
     self.locator = locator or CSqueakLocator()