Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The connections of a proxy can now be listed before it is started, instead of failing
* The keep alive tuning of a connection now reaches the socket, instead of being dropped
* The service catalogue of a Consul proxy is now read under Python 3.5, instead of being dropped
* The SOCKS server can now be built and served, instead of failing on creation - [#123](https://github.com/hivesolutions/netius/issues/123)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
* The test of primality no longer takes a base that shares a factor for a prime one

## [1.63.1] - 2026-08-31
Expand Down
20 changes: 12 additions & 8 deletions src/netius/servers/socks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def on_auth(self):
self.owner.on_auth_socks(self, self.parser)


class SOCKSServer(netius.ServerAgent):
class SOCKSServer(netius.ContainerServer):
"""
SOCKS base server class to be used as an implementation of the
RFC 1928 or SOCKSv5 and the SOCKSv4 protocols.
Expand All @@ -139,20 +139,24 @@ def __init__(
send_buffer_c=int(max_pending * BUFFER_RATIO),
*args,
**kwargs
) # @TODO: how is this going to work (receive buffer control)
)
self.rules = rules
self.throttle = throttle
self.max_pending = max_pending
self.min_pending = int(max_pending * MIN_RATIO)
self.conn_map = {}

_loop, self.raw_protocol = netius.clients.RawClient.protocol()
self.raw_protocol.bind("connect", self._on_raw_connect)
self.raw_protocol.bind("data", self._on_raw_data)
self.raw_protocol.bind("close", self._on_raw_close)
self.raw_client = netius.clients.RawClient(
thread=False,
receive_buffer=int(max_pending * BUFFER_RATIO),
send_buffer=int(max_pending * BUFFER_RATIO),
*args,
**kwargs
)
self.raw_client.bind("connect", self._on_raw_connect)
self.raw_client.bind("data", self._on_raw_data)
self.raw_client.bind("close", self._on_raw_close)

# @TODO: this does not make sense
self.add_base(self)
self.add_base(self.raw_client)

def cleanup(self):
Expand Down
17 changes: 10 additions & 7 deletions src/netius/servers/socks.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from socket import socket as Socket
from typing import Any, Mapping

from netius import Connection, Protocol, ServerAgent, Transport
from netius import Connection, ContainerServer, Protocol, Transport
from netius.clients import RawClient, RawProtocol
from netius.common import SOCKSParser

Expand All @@ -28,13 +28,13 @@ class SOCKSConnection(Connection):
def on_data(self): ...
def on_auth(self): ...

class SOCKSServer(ServerAgent):
class SOCKSServer(ContainerServer):
rules: Mapping[str, Any]
throttle: bool
max_pending: int
min_pending: int
conn_map: dict[RawProtocol, SOCKSConnection]
raw_protocol: RawProtocol
raw_client: RawClient

def __init__(
self,
Expand All @@ -45,12 +45,15 @@ class SOCKSServer(ServerAgent):
**kwargs
): ...
def cleanup(self): ...
def on_data(self, connection: SOCKSConnection, data: bytes): ...
def on_data(self, connection: Connection, data: bytes): ...
def on_data_socks(self, connection: SOCKSConnection, parser: SOCKSParser): ...
def on_auth_socks(self, connection: SOCKSConnection, parser: SOCKSParser): ...
def on_connection_d(self, connection: SOCKSConnection): ...
def build_connection(
self, socket: Socket, address: tuple[str, int] | str | None, ssl: bool = ...
def on_connection_d(self, connection: Connection): ...
def build_connection( # type: ignore[override]
self,
socket: Socket,
address: tuple[str, int] | str | None,
ssl: bool = ...,
) -> SOCKSConnection: ...
def _throttle(self, _connection: Transport | Protocol): ...
def _raw_throttle(self, connection: SOCKSConnection): ...
Expand Down
Loading