__init__(self,
receive,
make_send,
nconnect=-1,
timeout=60.0)
(Constructor)
A Tunnel relays connections from a 'receive' socket to one or more
'send' sockets. The receive socket must be bound and listening. For
each incoming connection, a new send socket is created by calling
make_send(). Data is then exchanged between the created streams until
one socket is closed. nconnect is the maximum number of simultaneous
connections (-1 for infinite), and timeout is the time that a single
connection can last for (None allows a connection to last forever).
Sockets must accept stream traffic and support the Python socket
interface. A separate daemonic thread is created to manage the tunnel.
For high performance, make_send() should make a socket and connect in
non-blocking mode (you should catch and discard the socket.BlockError
or socket.error due to executing connect on a non-blocking socket).
Security Note: A firewall is needed to maintain the end user's
anonymity. An attacker could keep a tunnel socket open by pinging it
regularly. The accepted sockets from 'receive' must prevent this by
closing down eventually.
Socket errors do not cause the Tunnel to shut down.
-
|