latest.ipv8.lazy_community
Module Contents
Classes
Base class that provides you with some easy ways to pack and unpack payloads. |
Functions
|
Handler for messages which failed to match to an existing overlay cache. |
|
This function wrapper match a payload to a registered cache for you. |
|
This function wrapper will unpack the BinMemberAuthenticationPayload for you. |
|
This function wrapper will unpack the BinMemberAuthenticationPayload for you, as well as pass the raw data to the |
This function wrapper will unpack just the normal payloads for you. |
|
This function wrapper will unpack just the normal payloads for you, as well as pass the raw data to the decorated |
Attributes
- latest.ipv8.lazy_community.UT
- latest.ipv8.lazy_community.CTF
- latest.ipv8.lazy_community.cache_retrieval_failed(overlay: latest.ipv8.overlay.Overlay, cache_class: type[latest.ipv8.types.NumberCache]) None
Handler for messages which failed to match to an existing overlay cache.
- latest.ipv8.lazy_community.retrieve_cache(cache_class: type[latest.ipv8.types.NumberCache]) Callable[[CTF], CTF]
This function wrapper match a payload to a registered cache for you.
For this wrapper to function, you will need to comply with three standards:
The last specified payload must include an
identifier
attribute.The
cache_class
must specify aname
attribute.The overlay this method belongs to has a
request_cache
attribute.
You can now message handlers as follows:
@lazy_wrapper(MyPayload1, MyPayload2) # MyPayload2.identifier must exist! @retrieve_cache(MyCache) # MyCache.name must exist! def on_message(peer: Peer, payload1: MyPayload1, payload2: MyPayload2, cache: NumberCache): pass
- Parameters:
cache_class – the cache to fetch.
- latest.ipv8.lazy_community.lazy_wrapper(*payloads: type[latest.ipv8.messaging.serialization.Payload]) Callable[[latest.ipv8.types.LazyWrappedHandler], latest.ipv8.types.MessageHandlerFunction]
This function wrapper will unpack the BinMemberAuthenticationPayload for you.
You can now write your authenticated and signed functions as follows:
@lazy_wrapper(IntroductionRequestPayload, IntroductionResponsePayload) def on_message(peer: Peer, payload1: IntroductionRequestPayload, payload2: IntroductionResponsePayload): pass
- latest.ipv8.lazy_community.lazy_wrapper_wd(*payloads: type[latest.ipv8.messaging.serialization.Payload]) Callable[[latest.ipv8.types.LazyWrappedWDataHandler], latest.ipv8.types.MessageHandlerFunction]
This function wrapper will unpack the BinMemberAuthenticationPayload for you, as well as pass the raw data to the decorated function.
You can now write your authenticated and signed functions as follows:
@lazy_wrapper_wd(IntroductionRequestPayload, IntroductionResponsePayload) def on_message(peer: Peer, payload1: IntroductionRequestPayload, payload2: IntroductionResponsePayload, data: bytes): pass
- latest.ipv8.lazy_community.lazy_wrapper_unsigned(*payloads: type[latest.ipv8.messaging.serialization.Payload]) Callable[[latest.ipv8.types.LazyWrappedUnsignedHandler], latest.ipv8.types.MessageHandlerFunction]
This function wrapper will unpack just the normal payloads for you.
You can now write your non-authenticated and signed functions as follows:
@lazy_wrapper_unsigned(IntroductionRequestPayload, IntroductionResponsePayload) def on_message(source_address: Address, payload1: IntroductionRequestPayload, payload2: IntroductionResponsePayload): pass
- latest.ipv8.lazy_community.lazy_wrapper_unsigned_wd(*payloads: type[latest.ipv8.messaging.serialization.Payload]) Callable[[latest.ipv8.types.LazyWrappedWDataUnsignedHandler], latest.ipv8.types.MessageHandlerFunction]
This function wrapper will unpack just the normal payloads for you, as well as pass the raw data to the decorated function.
You can now write your non-authenticated and signed functions as follows:
@lazy_wrapper_unsigned_wd(IntroductionRequestPayload, IntroductionResponsePayload) def on_message(source_address: Address, payload1: IntroductionRequestPayload, payload2: IntroductionResponsePayload, data: bytes): pass
- class latest.ipv8.lazy_community.EZPackOverlay(settings: SettingsClass)
Bases:
latest.ipv8.overlay.Overlay
,abc.ABC
Base class that provides you with some easy ways to pack and unpack payloads.
- ez_send(peer: latest.ipv8.peer.Peer, *payloads: latest.ipv8.messaging.serialization.Payload, **kwargs) None
Send a Payload instance (with a defined msg_id field) to a peer. If you supply more than one Payload instance, the msg_id of the LAST instance will be used.
- Parameters:
peer – the peer to send to
sig (bool) – whether or not to sign this message
payloads – the list of Payload instances to serialize
- _ez_senda(address: latest.ipv8.types.Address, *payloads: latest.ipv8.messaging.serialization.Payload, **kwargs) None
Send a Payload instance to an address.
You will probably not need this, try to use ez_send instead.
- Parameters:
address – the address to send to
sig (bool) – whether or not to sign this message
payloads – the list of Payload instances to serialize
- ezr_pack(msg_num: int, *payloads: latest.ipv8.messaging.serialization.Payload, **kwargs) bytes
The easier way to pack your messages. Supply with the message number and the Payloads you want to serialize. Optionally you can choose to sign the message.
- Parameters:
msg_num – the message number to claim for this message
sig (bool) – whether or not to sign this message
payloads – the list of Payload instances to serialize
- Returns:
the serialized message
- _ez_pack(prefix: bytes, msg_num: int, payloads: Sequence[latest.ipv8.messaging.serialization.Payload], sig: bool = True) bytes
- _verify_signature(auth: latest.ipv8.messaging.payload_headers.BinMemberAuthenticationPayload, data: bytes) tuple[bool, bytes]
- _ez_unpack_auth(payload_class: type[UT], data: bytes) tuple[latest.ipv8.messaging.payload_headers.BinMemberAuthenticationPayload, latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, UT]
- exception latest.ipv8.lazy_community.PacketDecodingError
Bases:
RuntimeError
Exception for when binary data doesn’t match its expected format.