socks_router.router

Attributes

CHUNK_SIZE

logger

Classes

SocksRouter

Mix-in class to handle each request in a new thread.

SocksRouterRequestHandler

Define self.rfile and self.wfile for stream sockets.

Functions

create_socket(→ socks.socksocket)

with_proxy(→ socks.socksocket)

poll_socket(destination[, timeout])

resolve_address(→ socks_router.models.Address)

create_remote(→ socks.socksocket)

connect_remote(→ socks.socksocket)

exchange_loop(client, remote[, chunk_size, timeout])

match_upstream(...)

Module Contents

CHUNK_SIZE = 4096
logger
create_socket(type: socks_router.models.Socks5AddressType, *args: create_socket.P, **kwargs: create_socket.P) socks.socksocket[source]
with_proxy(socket: socks.socksocket, proxy_server: socks_router.models.Address | None = None) socks.socksocket[source]
poll_socket(destination: socks_router.models.Address, timeout: float = 0.1)[source]
resolve_address(address: socks_router.models.Address, logger: logging.Logger = logger, **kwargs) socks_router.models.Address[source]
create_remote(address: socks_router.models.Address, proxy_server: socks_router.models.Address | None = None) socks.socksocket[source]
connect_remote(destination: socks_router.models.Address, proxy_server: socks_router.models.Address | None = None, remote_socket_timeout: float | None = None, proxy_poll_socket_timeout: float = 0.1, proxy_retry_options: socks_router.models.RetryOptions | None = None, logger: logging.Logger = logger) socks.socksocket[source]
exchange_loop(client: socket.socket, remote: socket.socket, chunk_size: int = CHUNK_SIZE, timeout: float | None = None)[source]
match_upstream(routing_table: socks_router.models.RoutingTable, destination: socks_router.models.Address) socks_router.models.UpstreamAddress | None[source]
class SocksRouter(*argv, context: socks_router.models.ApplicationContext | None = None, address_family: socket.AddressFamily = socket.AF_INET, **kwargs)[source]

Bases: socketserver.ThreadingTCPServer

Mix-in class to handle each request in a new thread.

allow_reuse_address = True
daemon_threads = True
block_on_close = True
context: socks_router.models.ApplicationContext
logger: logging.Logger
address_family
property address: socks_router.models.Address
server_activate() None[source]

Called by constructor to activate the server.

May be overridden.

get_request()[source]

Get the request and client address from the socket.

May be overridden.

shutdown_request(request: socket.socket | tuple[bytes, socket.socket]) None[source]

Called to shutdown and close an individual request.

shutdown() None[source]

Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.

class SocksRouterRequestHandler(request, client_address, server)[source]

Bases: socketserver.StreamRequestHandler

Define self.rfile and self.wfile for stream sockets.

server: SocksRouter
state: socks_router.models.Socks5State
remote: socks.socksocket | None = None
property logger
acquire_upstream(destination: socks_router.models.Address) socks_router.models.UpstreamAddress | None[source]
handshake()[source]
reply(type: socks_router.models.Socks5ReplyType)[source]
connect_remote(destination: socks_router.models.Address) socks.socksocket[source]
handle_request()[source]
exchange()[source]
setup()[source]
handle()[source]

Handle incoming connections

finish()[source]