mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-02 15:34:02 +00:00
Bundle pinned offline dependencies, remove libcork/libipset and submodule requirements, and add portable runtime helpers with relocatable static/shared library installations.
Add Clang static build validation for Linux/musl, macOS and Windows, real TCP/UDP and SIP003 interoperability coverage, and recorded performance tradeoffs. All 21 hosted checks pass at the reviewed PR head 8d504e6218.
44 lines
1.3 KiB
Python
Executable File
44 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Transparent SIP003 test transport; never used as a production plugin."""
|
|
import os
|
|
from pathlib import Path
|
|
import socket
|
|
import socketserver
|
|
import threading
|
|
|
|
mode, marker = os.environ["SS_PLUGIN_OPTIONS"].split(";marker=", 1)
|
|
local = (os.environ["SS_LOCAL_HOST"], int(os.environ["SS_LOCAL_PORT"]))
|
|
remote = (os.environ["SS_REMOTE_HOST"], int(os.environ["SS_REMOTE_PORT"]))
|
|
listen, destination = (remote, local) if mode == "server" else (local, remote)
|
|
|
|
|
|
def copy(source, target):
|
|
try:
|
|
while data := source.recv(16384):
|
|
target.sendall(data)
|
|
target.shutdown(socket.SHUT_WR)
|
|
except OSError:
|
|
pass
|
|
|
|
|
|
class Handler(socketserver.BaseRequestHandler):
|
|
def handle(self):
|
|
try:
|
|
with socket.create_connection(destination, timeout=10) as upstream:
|
|
self.request.settimeout(10)
|
|
thread = threading.Thread(target=copy, args=(self.request, upstream), daemon=True)
|
|
thread.start()
|
|
copy(upstream, self.request)
|
|
thread.join(timeout=10)
|
|
except OSError:
|
|
pass
|
|
|
|
|
|
class Server(socketserver.ThreadingTCPServer):
|
|
daemon_threads = True
|
|
|
|
|
|
with Server(listen, Handler) as server:
|
|
Path(marker).write_text(str(os.getpid()), encoding="ascii")
|
|
server.serve_forever()
|