socks_router.cli

Attributes

routing_table

logger

Classes

ApplicationContext

RetryOptions

SocksRouter

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

SocksRouterRequestHandler

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

Functions

cli(ctx, logging_config, hostname, port, routes, ...)

Module Contents

routing_table: parsec.Parser[socks_router.models.RoutingTable]
class ApplicationContext[source]
name: str = 'socks-router'
routing_table: RoutingTable
ssh_connection_timeout: int = 10
remote_socket_timeout: float | None = 10
proxy_poll_socket_timeout: float = 0.1
proxy_retry_options: RetryOptions
mutex: threading.Lock
upstreams: collections.abc.MutableMapping[UpstreamAddress, Upstream]
is_terminating: bool = False
class RetryOptions[source]
tries: int
delay: float = 1
max_delay: float | None = None
backoff: float = 1
jitter: float = 0
classmethod exponential_backoff(*argv, backoff=2, **kwargs)[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
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]
logger
cli(ctx: click.Context, logging_config: str, hostname: str, port: int, routes: str | None, routes_file: pathlib.Path, retries: int)