tribler.core.socks5.client

Exceptions

Socks5Error

Errors with the SOCKS5 protocol.

Classes

Socks5ClientUDPConnection

A datagram protocol for Socks5 connections.

Socks5Client

This object represents a minimal Socks5 client. Both TCP and UDP are supported.

Module Contents

exception tribler.core.socks5.client.Socks5Error

Bases: Exception

Errors with the SOCKS5 protocol.

class tribler.core.socks5.client.Socks5ClientUDPConnection(callback: collections.abc.Callable[[bytes, ipv8.messaging.interfaces.udp.endpoint.DomainAddress | tuple], None])

Bases: asyncio.DatagramProtocol

A datagram protocol for Socks5 connections.

callback
transport: asyncio.DatagramTransport | None = None
proxy_udp_addr: ipv8.messaging.interfaces.udp.endpoint.DomainAddress | ipv8.messaging.interfaces.udp.endpoint.UDPv4Address | None = None
logger
connection_made(transport: asyncio.BaseTransport) None

Callback for when a transport is available.

datagram_received(data: bytes, _: tuple) None

Callback for when data is received over our transport.

sendto(data: bytes, target_addr: ipv8.messaging.interfaces.udp.endpoint.DomainAddress | tuple) None

Attempt to send the given data to the given address.

class tribler.core.socks5.client.Socks5Client(proxy_addr: tuple, callback: collections.abc.Callable[[bytes, ipv8.messaging.interfaces.udp.endpoint.DomainAddress | tuple], None])

Bases: asyncio.Protocol

This object represents a minimal Socks5 client. Both TCP and UDP are supported.

proxy_addr
callback
transport: asyncio.WriteTransport | None = None
connection: Socks5ClientUDPConnection | None = None
connected_to: ipv8.messaging.interfaces.udp.endpoint.DomainAddress | tuple | None = None
queue: asyncio.Queue[bytes]
data_received(data: bytes) None

Callback for when data comes in. Call our registered callback or save the incoming save for calling back later.

connection_lost(_: Exception | None) None

Callback for when the connection is dropped.

async _send(data: bytes) bytes

Send data to the remote and wait for an answer.

async _login() None

Send a login.

Raises:

Socks5Error – If the proxy server is unsupported.

async _associate_udp(local_addr: tuple | None = None) None

Send an associate request to the connection.

async _connect_tcp(target_addr: tuple) None

Connect to the given address using TCP.

property connected: bool

Whether this client is connected over TCP.

property associated: bool

Whether this client is associated over UDP.

async associate_udp() None

Login and associate with the proxy.

sendto(data: bytes, target_addr: tuple) None

Attemp to send data to the given address.

Raises:

Socks5Error – If we have not associated UDP yet.

async connect_tcp(target_addr: tuple) None

Login and connect to the proxy using TCP.

Raises:

Socks5Error – If we have not associated UDP yet.

write(data: bytes) None

Write to whatever transport we have.