2.13.ipv8.messaging.anonymization.community

The tunnel community.

Author(s): Egbert Bouman

Module Contents

Classes

Functions

2.13.ipv8.messaging.anonymization.community.unpack_cell(payload_cls: type[2.13.ipv8.messaging.serialization.Serializable]) Callable[Ellipsis, Callable[[TunnelCommunity, 2.13.ipv8.types.Address, bytes, int | None], None]]

This function wrapper will unpack the normal payload for you, and handle a singular circuit_id parameter at the end of the parameter list You can now write your non-authenticated and signed functions as follows:

@unpack_cell(DataPayload)
def on_message(source_address, payload):
    '''
    :type source_address: str
    :type payload: DataPayload
    '''
    pass.
class 2.13.ipv8.messaging.anonymization.community.TunnelSettings

Bases: 2.13.ipv8.community.CommunitySettings

Settings to forward to the TunnelCommunity.

property max_relay_early: int

Return the maximum number of relay_early cells that are allowed to pass a relay.

property peer_flags: Set[int]

Return the peer flags.

min_circuits = 1
max_circuits = 8
max_joined_circuits = 100
max_time
max_time_ip
max_time_inactive = 20
max_traffic
circuit_timeout = 60
unstable_timeout = 60
next_hop_timeout = 10
swarm_lookup_interval = 30
swarm_connection_limit = 15
remove_tunnel_delay = 5
_peer_flags: Set[int]
_max_relay_early = 8
dht_provider: 2.13.ipv8.dht.provider.DHTCommunityProvider | None
class 2.13.ipv8.messaging.anonymization.community.TunnelCommunity(settings: TunnelSettings)

Bases: 2.13.ipv8.community.Community

Community to create circuits of intermediate peers (hops) that send data into (exit) and receive from the Internet.

version = b'\x02'
community_id
settings_class
async unload() None

Remove all circuits/relays/exitsockets.

get_serializer() 2.13.ipv8.messaging.serialization.Serializer

Extend our serializer with the ability to (un)pack exit node flags.

add_cell_handler(payload_cls: type[2.13.ipv8.messaging.lazy_payload.VariablePayloadWID], handler: Callable[[TunnelCommunity, 2.13.ipv8.types.Address, bytes, int | None], None] | Callable[[2.13.ipv8.types.Address, bytes, int | None], None]) None

Handler for messages that are exclusively tunneled (i.e., never handled plaintext).

_generate_circuit_id() int
do_circuits() None

Check if we have sufficient circuits and attempt to create new circuits if we have too little.

build_tunnels(hops: int) None

Signal that we want circuits of a given number of hops.

The number of circuits created for this hop count is dictated by the max_circuits setting.

tunnels_ready(hops: int) float

Fraction of circuits that are available for the given hop count.

do_remove() None

Remove all circuits that are inactive, old or overused and remove old peers from our candidate list.

get_candidates(*requested_flags: int) list[2.13.ipv8.peer.Peer]

Get all the peers that we can create circuits with.

get_max_time(circuit_id: int) float

Get the maximum time (in seconds) that the given circuit is allowed to exist.

find_circuits(ctype: str | None = CIRCUIT_TYPE_DATA, state: str | None = CIRCUIT_STATE_READY, exit_flags: collections.abc.Collection[int] | None = None, hops: int | None = None) list[Circuit]

Get circuits of the given type and state (and potentially exit flags and a given number of hops).

create_circuit(goal_hops: int, ctype: str = CIRCUIT_TYPE_DATA, exit_flags: collections.abc.Collection[int] | None = None, required_exit: 2.13.ipv8.peer.Peer | None = None, info_hash: bytes | None = None) Circuit | None

Create a circuit of a given number of hops. The circuit will be created immediately but not be available for transmission of data immediately. Note that not all circuits exist to send data.

Returns:

None if we are supposed to find an exit node and know of none.

send_initial_create(circuit: Circuit, candidate_peers: list[2.13.ipv8.peer.Peer], max_tries: int) None

Attempt to establish the first hop in a Circuit.

async remove_circuit(circuit_id: int, additional_info: str = '', remove_now: bool = False, destroy: bool | int = False) None

Remove a circuit and optionally send a destroy message.

async remove_relay(circuit_id: int, additional_info: str = '', remove_now: bool = False, destroy: bool = False) 2.13.ipv8.messaging.anonymization.tunnel.RelayRoute | None

Remove a relay and all information associated with the relay. Return the relays that have been removed.

async remove_exit_socket(circuit_id: int, additional_info: str = '', remove_now: bool = False, destroy: bool = False) 2.13.ipv8.messaging.anonymization.exit_socket.TunnelExitSocket | None

Remove an exit socket. Send a destroy message if necessary.

destroy_circuit(circuit: Circuit, reason: int = 0) None

Send a destroy message over a circuit.

Note that the circuit will still exist.

destroy_relay(circuit_id: int, reason: int = 0) None

Destroy our relay circuit upon request and forward a destroy message.

Note that the relay route will still exist.

destroy_exit_socket(exit_socket: 2.13.ipv8.messaging.anonymization.exit_socket.TunnelExitSocket, reason: int = 0) None

Destroy an exit socket.

Note that the exit socket will still exist.

send_cell(target_addr: 2.13.ipv8.types.Address, payload: CellablePayload) None

Send the given payload DIRECTLY to the given peer with the appropriate encryption rules.

send_data(target: 2.13.ipv8.types.Address, circuit_id: int, dest_address: 2.13.ipv8.types.Address, source_address: 2.13.ipv8.types.Address, data: bytes) None

Pack the given binary data and forward it to the given peer.

send_packet(target: 2.13.ipv8.types.Address, packet: bytes) int

Send raw data over the socket to a given peer and return the length of the sent data.

send_destroy(target: 2.13.ipv8.types.Address, circuit_id: int, reason: int) None

Send a destroy message directly to the given peer.

_ours_on_created_extended(circuit_id: int, payload: CreatedPayload | ExtendedPayload) None
send_extend(circuit: Circuit, candidates: list[bytes], max_tries: int) None

Extend a circuit by choosing one of the given candidates.

extract_peer_flags(extra_bytes: bytes) list[int]

Convert piggybacked introduction bytes to a list of peer flags.

introduction_request_callback(peer: 2.13.ipv8.peer.Peer, dist: 2.13.ipv8.messaging.payload_headers.GlobalTimeDistributionPayload, payload: 2.13.ipv8.messaging.payload.IntroductionRequestPayload | 2.13.ipv8.messaging.payload.NewIntroductionRequestPayload) None

Try to extract piggybacked data from the introduction request.

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

Try to extract piggybacked data from the introduction response.

create_introduction_request(socket_address: 2.13.ipv8.types.Address, extra_bytes: bytes = b'', new_style: bool = False, prefix: bytes | None = None) bytes

Add peer flags to our introduction requests.

create_introduction_response(lan_socket_address: 2.13.ipv8.types.Address, socket_address: 2.13.ipv8.types.Address, identifier: int, introduction: 2.13.ipv8.peer.Peer | None = None, extra_bytes: bytes = b'', prefix: bytes | None = None, new_style: bool = False) bytes

Add peer flags to our introduction responses.

on_cell(source_address: 2.13.ipv8.types.Address, data: bytes) None

Process an incoming cell, originating from a given address.

on_packet_from_circuit(source_address: 2.13.ipv8.types.Address, data: bytes, circuit_id: int) None

Process incoming raw data, assumed to be an IPv8 packet, originating from a given address.

async should_join_circuit(create_payload: CreatePayload, previous_node_address: 2.13.ipv8.types.Address) bool

Check whether we should join a circuit.

Note that this method is intended to be overwritten and, therefore, has unused arguments.

join_circuit(create_payload: CreatePayload, previous_node_address: 2.13.ipv8.types.Address) None

Actively join a circuit and send a created message back.

async on_create(source_address: 2.13.ipv8.types.Address, payload: CreatePayload, _: int | None) None

Process a request to join someone’s circuit.

on_created(source_address: 2.13.ipv8.types.Address, payload: CreatedPayload, _: int | None) None

Callback for when another peer signals that they have joined our circuit.

async on_extend(source_address: 2.13.ipv8.types.Address, payload: ExtendPayload, _: int | None) None

Callback for when a peer asks us to extend for their circuit.

on_extended(source_address: 2.13.ipv8.types.Address, payload: ExtendedPayload, _: int | None) None

Callback for when a peer signals that they have extended our circuit.

on_raw_data(circuit: Circuit, origin: 2.13.ipv8.types.Address, data: bytes) None

Handle data, coming from a specific circuit and origin. This method is usually implemented in subclasses of this community.

on_data(sock_addr: 2.13.ipv8.types.Address, data: bytes, _: int | None) None

Callback for when we receive a DataPayload out of a circuit.

Data is readable only if this handler is (a) an exit node or (b) the one that created the circuit.

on_ping(source_address: 2.13.ipv8.types.Address, payload: PingPayload, _: int | None) None

Callback for when we received a tunneled ping message.

on_pong(source_address: 2.13.ipv8.types.Address, payload: PongPayload, _: int | None) None

Callback for when we received a tunneled pong (response) message.

do_ping(exclude: list[int] | None = None) None

Ping circuits. Pings are only sent to the first hop, subsequent hops will relay the ping.

on_destroy(peer: 2.13.ipv8.peer.Peer, payload: DestroyPayload) None

Callback for when we received a destroy message.

exit_data(circuit_id: int, sock_addr: 2.13.ipv8.types.Address, destination: 2.13.ipv8.types.Address, data: bytes) None

Exit data (to the destination) out of the exit socket associated with the given circuit id.

async dht_peer_lookup(mid: bytes, peer: 2.13.ipv8.peer.Peer | None = None) None

Perform a DHT lookup for a given SHA-1 hash of a public key.

Note that connections (if any) will be performed in the background. Query for results manually later.

send_test_request(circuit: Circuit, request_size: int = 0, response_size: int = 0) Future[tuple[bytes, float]]

Send a speed test request and wait for a (data, RTT time in seconds) tuple to be recorded.

on_test_request(source_address: 2.13.ipv8.types.Address, data: bytes, circuit_id: int | None) None

Callback for when we receive a speed test request.

on_test_response(source_address: 2.13.ipv8.types.Address, data: bytes, circuit_id: int | None) None

Callback for when we received a test response.

We record the data that the response contained and the time since we sent the original request.