Metadata-Version: 2.5
Name: splitsocks
Version: 0.1.1
Summary: A SOCKS5 server, cut in half
Author-email: "Armin \"Era\" Ramezani" <e@4d2.org>
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-Expression: LGPL-3.0-or-later
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Topic :: Internet
Classifier: Topic :: Security
Classifier: Topic :: System :: Networking
Classifier: Programming Language :: Python :: 3.13
License-File: COPYING
License-File: COPYING.LESSER
Import-Name: splitsocks

# splitsocks

A prototype multi-hop store-and-forward SOCKS5 proxy server, with built-in congestion control, retransmission, and
reordering between the server's halves.

## Use Case

This project is mainly aimed at developers and system administrators. It simply provides all the backend needed to set
up a multi-hop IP proxy using any sort of communication protocol between the server halves, even non-IP-based,
best-effort, and/or quota‑based protocols. If that's overkill for what you're trying to do, you should probably look at
other projects before committing to this one.

## Usage

1. Install Python (version 3.13 or above) on the server halves.
2. Install this library via `pip install splitsocks` on both halves.
3. Write a bouncer script and an exit script, and run each of them on one of the server halves.

Documentation is still WIP, but these templates are a good place to start:

```python
# bouncer side
# this runs on the half that the user interacts with
#
import asyncio
import splitsocks

socks_bouncer = splitsocks.SocksBouncer()


async def send(data) -> None:
    # this function should attempt to send `data` to the exit side's `receive` function. Additionally, it should only
    # return once the communication channel is ready/able to handle more data. This function does not need to retry
    # sending `data` if it encounters/suspects a failure, as splitsocks will attempt to handle that on its own. 


def receive(data) -> None:
    loop.call_soon_threadsafe(socks_bouncer.received_data, data)


async def restart() -> None:
    global socks_bouncer
    await socks_bouncer.abort()
    socks_bouncer = splitsocks.SocksBouncer()
    await socks_bouncer.start(send, port=1080)


async def main() -> None:
    # Before the bouncer is started (or before `send` actually starts utilizing the communication channel) the bouncer
    # needs to somehow trigger the exit side's restart function and wait for it to complete. this is not needed if the
    # exit side hasn't been turned on yet.
    await socks_bouncer.start(send, port=1080)


if __name__ == '__main__':
    try:
        import uvloop
        loop = uvloop.new_event_loop()
    except ImportError:
        loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.create_task(main())
    loop.run_forever()

```
```python
# exit side
# this runs on the half that actually connects to the requested endpoints
#
import asyncio
import splitsocks

socks_exit = splitsocks.SocksExit()


async def send(data) -> None:
    # this function should attempt to send `data` to the bouncer side's `receive` function. Additionally, it should only
    # return once the communication channel is ready/able to handle more data. This function does not need to retry
    # sending `data` if it encounters/suspects a failure, as splitsocks will attempt to handle that on its own. 


def receive(data) -> None:
    loop.call_soon_threadsafe(socks_exit.received_data, data)


async def restart() -> None:
    global socks_exit
    await socks_exit.abort()
    socks_exit = splitsocks.SocksExit()
    socks_exit.start(send)


if __name__ == '__main__':
    try:
        import uvloop
        loop = uvloop.new_event_loop()
    except ImportError:
        loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    # Before the exit is started (or before `send` actually starts utilizing the communication channel) the exit needs
    # to somehow trigger the bouncer side's restart function and wait for it to complete. this is not needed if the
    # bouncer side hasn't been turned on yet.
    loop.call_soon(socks_exit.start, send)
    loop.run_forever()

```

## Features

- [ ] Mimicking TCP Behavior

  - [x] Dynamic Congestion Control

  - [x] Dynamic Buffer Size

  - [x] Packet Reordering

  - [x] Packet Retransmission

  - [x] Packet Deduplication

  - [ ] Aggressive Teardown of Aborted Connections

- [ ] Nearly Full SOCKS5 Implementation

  - [x] All Standard Atyps

  - [ ] UDP ASSOCIATE Requests

  - [ ] Authentication Support

  - [x] Half-Close Semantics

  - [x] Idle Timeouts

