i2p.sam
index
d:\code\i2p\i2p\sam.py

SAM Python API

 
Modules
       
Queue
copy
i2p
select
socket
i2p.samclasses
thread
threading
time

 
Classes
       
i2p.Error(exceptions.Exception)
Error
BlockError
ClosedError
NetworkError
Timeout
Poll
Socket
Tunnel
TunnelClient
TunnelServer

 
class BlockError(Error)
    Socket call would have blocked.
 
 
Method resolution order:
BlockError
Error
i2p.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class ClosedError(Error)
    A command was used on a socket that closed gracefully.
 
 
Method resolution order:
ClosedError
Error
i2p.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Error(i2p.Error)
    Base class for all SAM errors.
 
 
Method resolution order:
Error
i2p.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class NetworkError(Error)
    Network error occurred within I2P.
The error object is a 2-tuple: (errtag, errdesc).
errtag is a SAM error string,
errdesc is a human readable error description.
 
 
Method resolution order:
NetworkError
Error
i2p.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Poll
    Class implementing poll interface.  Works for Python sockets
and SAM sockets.
 
  Methods defined here:
__init__(self)
poll(self, timeout=None)
register(self, fd, eventmask=13)
unregister(self, fd)

 
class Socket
    A socket object.
 
  Methods defined here:
__deepcopy__(self, memo)
__init__(self, session, type, samaddr='127.0.0.1:7656', **kwargs)
Equivalent to socket().
accept(self)
bind(self, address)
close(self)
connect(self, address)
connect_ex(self, address)
getpeername(self)
getsockname(self)
gettimeout(self)
listen(self, backlog)
makefile(self, mode='r', bufsize=-1)
recv(self, bufsize, flags=0)
recvfrom(self, bufsize, flags=0)
For a datagram or raw socket, bufsize = -1 indicates that the
entire packet should be retrieved.
send(self, string, flags=0)
sendall(self, string, flags=0)
sendto(self, string, flags, address)
setblocking(self, flag)
settimeout(self, value)

Properties defined here:
dest
Local I2P Destination of socket
session
Session name
type
Socket type: SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.

 
class Timeout(Error)
    Time out occurred for a socket which had timeouts enabled
via a prior call to settimeout().
 
 
Method resolution order:
Timeout
Error
i2p.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Tunnel
     Methods defined here:
__init__(self, receive, make_send, nconnect=-1, timeout=60.0)
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 sam.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.
close(self)
Close all connections made for this tunnel.

 
class TunnelClient(Tunnel)
     Methods defined here:
__init__(self, session, port, dest, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
Tunnels localhost:port --> I2P Destination dest.
 
A session named 'session' is created locally, for purposes
of routing to 'dest'.  nconnect and timeout are the maximum
number of connections and maximum time per connection.  All
other arguments are passed to sam.socket().  This call blocks
until the tunnel is ready.

Properties defined here:
dest
get = 'Local Destination used for routing.'
remotedest
Remote Destination.
session
get = 'Session name for local Destination.'

Methods inherited from Tunnel:
close(self)
Close all connections made for this tunnel.

 
class TunnelServer(Tunnel)
     Methods defined here:
__init__(self, session, port, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
Tunnels incoming SAM streams --> localhost:port.
 
nconnect and timeout are the maximum number of connections
and maximum time per connection.  All other arguments are
passed to sam.socket().  This call blocks until the tunnel
is ready.

Properties defined here:
dest
I2P Destination of server.
session
Session name for server.

Methods inherited from Tunnel:
close(self)
Close all connections made for this tunnel.

 
Data
        MAX_DGRAM = 31744
MAX_RAW = 32768
MSG_DONTWAIT = 128
MSG_PEEK = 2
MSG_WAITALL = 64
POLLERR = 8
POLLHUP = 16
POLLIN = 1
POLLNVAL = 32
POLLOUT = 4
POLLPRI = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
SOCK_STREAM = 1
samaddr = '127.0.0.1:7656'
samver = 1.0