2.12.ipv8.messaging.anonymization.tunnel

Module Contents

Classes

Attributes

2.12.ipv8.messaging.anonymization.tunnel.ORIGINATOR = 0
2.12.ipv8.messaging.anonymization.tunnel.EXIT_NODE = 1
2.12.ipv8.messaging.anonymization.tunnel.ORIGINATOR_SALT = 2
2.12.ipv8.messaging.anonymization.tunnel.EXIT_NODE_SALT = 3
2.12.ipv8.messaging.anonymization.tunnel.ORIGINATOR_SALT_EXPLICIT = 4
2.12.ipv8.messaging.anonymization.tunnel.EXIT_NODE_SALT_EXPLICIT = 5
2.12.ipv8.messaging.anonymization.tunnel.PEER_SOURCE_UNKNOWN = 0
2.12.ipv8.messaging.anonymization.tunnel.PEER_SOURCE_DHT = 1
2.12.ipv8.messaging.anonymization.tunnel.PEER_SOURCE_PEX = 2
2.12.ipv8.messaging.anonymization.tunnel.PEER_FLAG_RELAY = 1
2.12.ipv8.messaging.anonymization.tunnel.PEER_FLAG_EXIT_BT = 2
2.12.ipv8.messaging.anonymization.tunnel.PEER_FLAG_EXIT_IPV8 = 4
2.12.ipv8.messaging.anonymization.tunnel.PEER_FLAG_SPEED_TEST = 8
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_TYPE_DATA = 'DATA'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_TYPE_IP_SEEDER = 'IP_SEEDER'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_TYPE_RP_SEEDER = 'RP_SEEDER'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_TYPE_RP_DOWNLOADER = 'RP_DOWNLOADER'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_STATE_READY = 'READY'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_STATE_EXTENDING = 'EXTENDING'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_STATE_CLOSING = 'CLOSING'
2.12.ipv8.messaging.anonymization.tunnel.CIRCUIT_ID_PORT = 1024
2.12.ipv8.messaging.anonymization.tunnel.PING_INTERVAL = 7.5
2.12.ipv8.messaging.anonymization.tunnel.DESTROY_REASON_UNKNOWN = 1
2.12.ipv8.messaging.anonymization.tunnel.DESTROY_REASON_SHUTDOWN = 2
2.12.ipv8.messaging.anonymization.tunnel.DESTROY_REASON_UNNEEDED = 4
2.12.ipv8.messaging.anonymization.tunnel.DESTROY_REASON_LEAVE_SWARM = 5
class 2.12.ipv8.messaging.anonymization.tunnel.DataChecker

Class to verify that only IPv8-allowed traffic is being forwarded.

static could_be_utp(data: bytes) bool

Check if this data could be uTP (see also https://www.bittorrent.org/beps/bep_0029.html).

Packets should be 20 bytes or larger.

The type should be 0..4:
  • 0: ST_DATA

  • 1: ST_FIN

  • 2: ST_STATE

  • 3: ST_RESET

  • 4: ST_SYN

The version should be 1.

The extension should be 0..3:
  • 0: No extension

  • 1: Selective ACK

  • 2: Deprecated

  • 3: Close reason

static could_be_udp_tracker(data: bytes) bool

Check if the data could be a UDP-based tracker.

static could_be_dht(data: bytes) bool

Check if the data contain a bencoded dictionary.

static could_be_bt(data: bytes) bool

Check if the data could be any BitTorrent traffic.

static could_be_ipv8(data: bytes) bool

Check if the data is likely IPv8 overlay traffic.

2.12.ipv8.messaging.anonymization.tunnel.PT
class 2.12.ipv8.messaging.anonymization.tunnel.Tunnel(circuit_id: int, peer: PT)

Bases: Generic[PT]

Statistics for a tunnel to a peer over a circuit (base class for circuits, exit sockets, and relay routes).

property peer: PT

The peer on the other end of this tunnel, if it exists.

beat_heart() None

Notify this object that the tunnel was active.

class 2.12.ipv8.messaging.anonymization.tunnel.TunnelExitSocket(circuit_id: int, peer: 2.12.ipv8.peer.Peer, overlay: 2.12.ipv8.messaging.anonymization.community.TunnelCommunity)

Bases: Tunnel[2.12.ipv8.peer.Peer], asyncio.DatagramProtocol, 2.12.ipv8.taskmanager.TaskManager

Socket for exit nodes that communicates with the outside world.

enable() None

Allow data to be sent.

This creates the datagram endpoint that allows us to send messages.

sendto(data: bytes, destination: 2.12.ipv8.types.Address) None

Send o message over our datagram transporter.

async resolve(host: str) str

Using asyncio’s getaddrinfo since the aiodns resolver seems to have issues. Returns [(family, type, proto, canonname, sockaddr)].

datagram_received(data: bytes, source: 2.12.ipv8.types.Address) None

Callback for when data is received by the socket.

is_allowed(data: bytes) bool

Check if the captured data is not malicious junk.

tunnel_data(source: 2.12.ipv8.types.Address, data: bytes) None

Send data back over the tunnel that we are exiting for.

async close() None

Closes the UDP socket if enabled and cancels all pending tasks.

Returns:

A deferred that fires once the UDP socket has closed.

class 2.12.ipv8.messaging.anonymization.tunnel.Circuit(circuit_id: int, goal_hops: int = 0, ctype: str = CIRCUIT_TYPE_DATA, required_exit: 2.12.ipv8.peer.Peer | None = None, info_hash: bytes | None = None)

Bases: Tunnel[Optional[2.12.ipv8.peer.Peer]]

A peer-to-peer encrypted communication channel, consisting of 0 or more hops (intermediate peers).

property peer: 2.12.ipv8.peer.Peer | None

Get the gateway peer for this tunnel, if it already exists.

property exit_flags: list[int]

Get the flags of the last hop in our circuit.

property hops: Sequence[Hop]

Return a read only tuple version of the hop-list of this circuit.

property state: str

The circuit state.

This can be either:
  • CIRCUIT_STATE_CLOSING

  • CIRCUIT_STATE_EXTENDING

  • CIRCUIT_STATE_READY

add_hop(hop: Hop) None

Adds a hop to the circuits hop collection.

close(closing_info: str = '') None

Sets the state of the circuit to CIRCUIT_STATE_CLOSING. This ensures that this circuit will not be used to contact new peers.

__eq__(other: object) bool

Check if the other object is equal to this circuit.

class 2.12.ipv8.messaging.anonymization.tunnel.Hop(peer: 2.12.ipv8.peer.Peer, flags: list[int] | None = None)

Circuit Hop containing the address, its public key and the first part of the Diffie-Hellman handshake.

property public_key: 2.12.ipv8.keyvault.public.libnaclkey.LibNaCLPK

Get the public key instance of the hop.

property node_public_key: bytes

The hop’s public_key bytes.

property mid: bytes

Get the SHA-1 of the hop’s public key.

class 2.12.ipv8.messaging.anonymization.tunnel.RelayRoute(circuit_id: int, peer: 2.12.ipv8.peer.Peer, rendezvous_relay: bool = False)

Bases: Tunnel[2.12.ipv8.peer.Peer]

Relay object containing the destination circuit, socket address and whether it is online or not.

class 2.12.ipv8.messaging.anonymization.tunnel.RendezvousPoint(circuit: Circuit, cookie: bytes)

Rendezvous for circuits to link up.

class 2.12.ipv8.messaging.anonymization.tunnel.IntroductionPoint(peer: 2.12.ipv8.peer.Peer, seeder_pk: bytes, source: int = PEER_SOURCE_UNKNOWN, last_seen: float | None = None)

A point of introduction, available for linking up.

__eq__(other: object) bool

Check if another object is equal to this intro point.

__hash__() int

Each intro point is unique to its peer and seeder’s public key.

to_dict() dict[str, dict[str, str | int] | str | int]

Convert this intro point to a flat dict.

class 2.12.ipv8.messaging.anonymization.tunnel.Swarm(info_hash: bytes, hops: int, lookup_func: Callable[[bytes, IntroductionPoint | None, int], asyncio.Future[list[IntroductionPoint]]], seeder_sk: 2.12.ipv8.keyvault.private.libnaclkey.LibNaCLSK | None = None, max_ip_age: float = 180.0, min_dht_lookup_interval: float = 300.0, max_dht_lookup_interval: float = 120.0)

A group of circuit exits that organizes around a SHA-1.

property seeding: bool

Whether we are seeding data in this swarm.

property _active_circuits: list[Circuit]
add_connection(rp_circuit: Circuit, intro_point_used: IntroductionPoint) None

Add a newly known circuit to this swarm.

remove_connection(rp_circuit: Circuit) bool

Remove the given circuit from this swarm, if we manage it.

This does not close the circuit.

has_connection(seeder_pk: bytes) bool

Check if the given public key is in the swarm.

get_num_connections() int

Get the number of circuits we have in this swarm.

get_num_connections_incomplete() int

Get the number of circuits we don’t have yet, but know of, in this swarm.

add_intro_point(ip: IntroductionPoint) IntroductionPoint

Add an available introduction point to this swarm.

Returns the introduction point we should use (not necessarily the one we just added).

remove_old_intro_points() None

Cleanup old introduction points.

remove_intro_point(ip: IntroductionPoint) None

Remove the given introduction point from this swarm.

async lookup(target: IntroductionPoint | None = None) list[IntroductionPoint] | None

Lookup introduction points, possibly those that match the given introduction point.

get_num_seeders() int

Get the number of different seeder public keys in this swarm.

get_total_up() int

Get the total number of bytes uploaded in this swarm.

get_total_down() int

Get the total number of bytes downloaded from this swarm.