v0.2

What's new in v0.2

  1. Now, on windows, TCP/IP stack accepts connection only after accept()call from proxy. What does it mean? If you have limit of connections = 1. Other clients will not be connected to socket at all instead of TCP handshake and incoming data buffering in stack. https://learn.microsoft.com/en-us/windows/win32/winsock/so-conditional-accept

    SO_CONDITIONAL_ACCEPT = 0x3002

  2. New asynchronous upstream mechanism

  3. Removed connection_made Session's constructor now called on ready

API

Definitions

CALLBACK - called by proxy on event USER METHOD - called by user code from handler/other places

(class) ku.Reject

Pass this object to the handler's output to prevent incoming data from being sent to the other side

(class) ku.Pass

Pass this object to the handler's output to pass incoming data to the other side

ku.Pass '==' None you can use none in handlers too

(class) ku.state(Enum)

Represents tcpsession state

(class) ku.tcpsession

CALLBACK

Constructor

  • client: socket

  • server: socket

  • proxy: ku.ku

  • *args: Tuple[Any] # You can specify here the arguments you need and provide them on proxy instantiating

Called when client and server connected and ready to transmission

clientbound(self, data: bytes) -> Union[bytes, Reject, Pass]

CALLBACK

Called when data is received from the server

serverbound(self, data: bytes) -> Union[bytes, Reject, Pass]

CALLBACK

Called when data is received from the client

shutdown(self) -> None

CALLBACK

Called on proxy shutdown, if protocol have shutdown sequence, it should be placed here. For example, websocket closure procedure, minecraft disconnect packet.

terminate(self) -> None

USER METHOD

Request proxy to terminate this session

(class) ku.ku

Constructor

  • listen: Tuple[str, int, str, int...] # Listen addreses / (domain names (ipv4 only))

  • upstream: Tuple[str, int] # Upstream address

  • session: Optional[tcpsession] # ku.tcpsession

  • session_args: Tuple[Any] # Session arguments, must match with session type used

  • maxcon: int # Maximum connections limit default = -1 (unlim)

  • upstream_6: bool # Use ipv6 for upstreaming (domain names) default = False

shutdown(self) -> None

  1. Stop event polling

  2. Safe shutdown all connected sessions

  3. Close all descriptors

Maybe, you can re-start proxy after shutdown but i'm unsure...

*can't be called from a handler!)

send(self, fd: socket, data: bytes) -> None

Try to send data to connected socket, if fail, close socket and terminated associated session

terminate(self, session: tcpsession) -> None

Safest way to end transmission

Usage example

Example output

Last updated

Was this helpful?