latest.ipv8.peerdiscovery.community

Module Contents

Classes

PeriodicSimilarity

Periodically send a request for similar Communities to a random peer.

PingRequestCache

Cache for ping measurements to a peer.

DiscoveryCommunity

Community for peers to more quickly discover peers in other communities.

class latest.ipv8.peerdiscovery.community.PeriodicSimilarity(overlay: DiscoveryCommunity)

Bases: latest.ipv8.peerdiscovery.churn.DiscoveryStrategy

Periodically send a request for similar Communities to a random peer.

take_step() None

Select a random peer, at most every second, to send a similarity request to.

class latest.ipv8.peerdiscovery.community.PingRequestCache(request_cache: latest.ipv8.requestcache.RequestCache, identifier: int, peer: latest.ipv8.peer.Peer, start_time: float)

Bases: latest.ipv8.requestcache.NumberCache

Cache for ping measurements to a peer.

property timeout_delay: float

After 5 seconds, consider the peer unreachable.

name = 'discoverypingcache'
finish() None

Complete the ping measurement by adding it to a peer’s pings.

on_timeout() None

If we can’t reach a peer, we assume accidental packet drop. Actually dropping the peer is left to the churn.

class latest.ipv8.peerdiscovery.community.DiscoveryCommunity(settings: latest.ipv8.community.CommunitySettings)

Bases: latest.ipv8.community.Community

Community for peers to more quickly discover peers in other communities.

Peers exchange the community ids they are part of with each other.

version = b'\x02'
community_id
get_available_strategies() dict[str, type[latest.ipv8.peerdiscovery.churn.DiscoveryStrategy]]

Expose strategies for periodically checking similarity and unreachable peer churn.

async unload() None

Unload the pending ping cache and then shut down the pending tasks.

on_old_introduction_request(source_address: latest.ipv8.types.Address, data: bytes) None

A backward-compatible (2014) introduction request handler.

The old logic flow was to first try to unpack the special DiscoveryCommunity intro request and then fall back to the actual intro request payload.

introduction_response_callback(peer: latest.ipv8.peer.Peer, dist: latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: latest.ipv8.messaging.payload.IntroductionResponsePayload | latest.ipv8.messaging.payload.NewIntroductionResponsePayload) None

If a peer sent us a response, send them a request for similarity.

send_similarity_request(address: latest.ipv8.types.Address) None

Send a request for similarity with our communities.

on_similarity_request(node: latest.ipv8.peer.Peer, dist: latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: latest.ipv8.peerdiscovery.payload.SimilarityRequestPayload) None

We received a request for similarity (overlap with another peer’s communities).

We update the known community ids for this peer and we send a response that contains our own ids.

on_similarity_response(node: latest.ipv8.peer.Peer, dist: latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: latest.ipv8.peerdiscovery.payload.SimilarityResponsePayload) None

We received a response to our request for similarity.

on_ping(source_address: latest.ipv8.types.Address, dist: latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: latest.ipv8.peerdiscovery.payload.PingPayload) None

We received a ping, send a pong back.

For backward compatibility, this message is unsigned.

on_pong(source_address: latest.ipv8.types.Address, dist: latest.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: latest.ipv8.peerdiscovery.payload.PongPayload, cache: PingRequestCache) None

We got a valid pong to our existing ping (retrieve_cache ensures this), finish the request in the cache handler.

Note: For backward compatibility, this message is UNSIGNED. The only thing guaranteeing that the response

is not faked, is its nonce.

get_my_overlays(peer: latest.ipv8.peer.Peer) list[bytes]

Get the known community ids that we are a part of.

custom_pack(peer: latest.ipv8.peer.Peer, msg_num: int, payloads: Sequence[latest.ipv8.messaging.serialization.Serializable]) bytes

You can have different key material for different communities. So, in order for you to cross-communicate, you should sign messages with the key material that is used by a particular community.

create_similarity_request(peer: latest.ipv8.peer.Peer) bytes

Create a similarity request message to send to the given peer.

create_similarity_response(identifier: int, peer: latest.ipv8.peer.Peer) bytes

Create a response message to a similarity request from a given peer.

send_ping(peer: latest.ipv8.peer.Peer) None

Send a ping message to the given peer.

create_pong(identifier: int) bytes

Create a pong message for the given identifier.