I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 36fb99a0 authored by sunshine's avatar sunshine Committed by zzz
Browse files

Updated Python-I2P version 0.91 by sunshine

parent 8f5d325c
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en"><head><title>User's Guide:i2p.sam - Wikipedia</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="robots" content="index,follow">
<link rel="shortcut icon" href="/favicon.ico">
<script type="text/javascript" src="/~barnesc/wiki/stylesheets/wikibits.js"></script>
<style type='text/css'><!--
@import url("/~barnesc/wiki/stylesheets/wikiprintable.css");
/*/*/
a.new, #quickbar a.new { color: #CC2200; }
#quickbar { position: absolute; top: 4px; left: 4px; border-right: 1px solid gray; }
#article { margin-left: 152px; margin-right: 4px; }
/* */
//--></style>
</head>
<body bgcolor='#FFFFFF' onload=''>
<h1 class='pagetitle'>User's Guide:i2p.sam</h1><p class='subtitle'>From Python-I2P.
<div class='bodytext'><a name="top"></a>
Module <code >i2p.sam</code > allows Python programs to access the <a href="./samproxy.html" class='printable' title ="SAM proxy">SAM proxy</a>.
<p>
With this module, a program can send stream data, datagrams, and raw packets across the I2P network.
<p>
<p><table border="0" id="toc"><tr><td align="center">
<b>Table of contents</b></td></tr><tr id='tocinside'><td>
<div style="margin-bottom:0px;">
<A CLASS="internal" HREF="#Sockets">1 Sockets</A><BR>
</div>
<div style="margin-bottom:0px;">
<A CLASS="internal" HREF="#Tunnels">2 Tunnels</A><BR>
</div>
<div style="margin-left:2em;">
<A CLASS="internal" HREF="#Tunnel_Server">2.1 Tunnel Server</A><BR>
<A CLASS="internal" HREF="#Tunnel_Client">2.2 Tunnel Client</A><BR>
</div>
<div style="margin-bottom:0px;">
<A CLASS="internal" HREF="#Errors">3 Errors</A><BR>
</div>
<div style="margin-bottom:0px;">
<A CLASS="internal" HREF="#Constants">4 Constants</A><BR>
</div>
</td></tr></table><P>
<h2><a name="Sockets"> Sockets </a></h2>
<p>
<strong>socket</strong>(session, type, samaddr='127.0.0.1:7656', **kwargs)
<ul ><pre>
Create a new socket. Argument session should be a session
name -- if the name has not yet been used, an I2P
Destination will be created for it, otherwise, the
existing Destination will be re-used. An empty session
string causes a transient session to be created. Argument
type is one of SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.
I2P configuration keyword arguments:
* in_depth - depth of incoming tunnel (default 2)
* out_depth - depth of outgoing tunnel (default 2)
A single session may be shared by more than one socket, if
the sockets are the same type, and if the sockets are
created within the same Python process. The socket
objects are multithread-safe.
Examples:
a = i2p.socket('Alice', i2p.SOCK_STREAM)
b = i2p.socket('Bob', i2p.SOCK_DGRAM,
in_depth=2, out_depth=5)
The created object behaves identically to a socket from
module socket, with the following exceptions:
* I2P Destinations are used as address arguments [1].
* bind is a no-op: sockets are always bound.
* send* methods send all data and are non-blocking.
A given session name can only be open in a single Python
program at a time. If you need to overcome this
limitation, consider patching I2P.
[1]. Alternatively, a host name can be used as an address.
It will be resolved using hosts.txt.
For details on how to use socket objects, see
http://www.python.org/doc/current/lib/socket-objects.html
See the examples directory for code examples.
</pre>
</ul >
<strong>socket()</strong> object properties:
<ul >
<pre> dest - Local I2P Destination of socket
session - Session name
type - Socket type: SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.
</pre>
</ul >
<strong>poll</strong>()
<ul >
<pre> Returns a polling object. Works on SAM sockets and Python sockets.
See <a href='http://www.python.org/doc/current/lib/module-select.html' class='printable' title="http://www.python.org/doc/current/lib/module-select.html">select.poll()</a> in the Python library for more information.
</pre>
</ul >
<p>
<strong>resolve</strong>(host, samaddr='127.0.0.1:7656')
<ul >
<pre> Resolve I2P host name --&gt; I2P Destination.
Returns the same string if host is already a Destination.
</pre>
</ul >
<p>
<strong>select</strong>(readlist, writelist, errlist, timeout=None)
<ul >
<pre> Performs a select call. Works on SAM sockets and Python sockets.
See <a href='http://www.python.org/doc/current/lib/module-select.html' class='printable' title="http://www.python.org/doc/current/lib/module-select.html">select.select()</a> in the Python library for more information.
</pre>
</ul >
<p>
<h2><a name="Tunnels"> Tunnels </a></h2>
<p>
Tunnels allow stream sockets to be joined, so that connections to a listening socket are relayed to one or more sending sockets. This allows an ordinary web server to be exposed as an I2P Destination, or an I2P Destination to be bound as a local port, and so on.
<p>
class <strong>Tunnel</strong>(self, receive, make_send, nconnect=-1, timeout=60.0)
<ul ><pre>
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 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.
</pre>
</ul >
<p>
<strong>close</strong>()
<ul >
<pre> Close all connections made for this tunnel.
</pre>
</ul >
<p>
<h3><a name="Tunnel_Server"> Tunnel Server </a></h3>
<p>
class <strong>TunnelServer</strong>(session, port, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
<ul ><pre>
Tunnels incoming SAM streams --&gt; 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.
</pre>
</ul >
<p>
<strong>TunnelServer</strong> properties:
<ul ><pre>
dest - I2P Destination of server.
session - Session name for server.
</pre>
</ul >
<p>
<h3><a name="Tunnel_Client"> Tunnel Client </a></h3>
<p>
class <strong>TunnelClient</strong>(session, port, dest, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
<ul ><pre>
Derived from Tunnel.
Tunnels localhost:port --&gt; 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.
</pre>
</ul >
<p>
<strong>TunnelClient</strong> properties:
<ul ><pre>
dest - Local Destination used for routing.
remotedest - Remote Destination.
session - Session name for local Destination.
</pre>
</ul >
<p>
<h2><a name="Errors"> Errors </a></h2>
<p>
class <strong>Error</strong>(i2p.Error)
<ul ><pre>
Base class for all SAM errors.
</pre>
</ul >
class <strong>BlockError</strong>(Error)
<ul ><pre>
Socket call would have blocked.
</pre>
</ul >
class <strong>ClosedError</strong>(Error)
<ul ><pre>
A command was used on a socket that closed gracefully.
</pre>
</ul >
class <strong>NetworkError</strong>(Error)
<ul ><pre>
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.
</pre>
</ul >
<p>
<h2><a name="Constants"> Constants </a></h2>
<p>
<strong>Socket types</strong>
<ul ><pre>
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
</pre>
</ul >
<strong>Packet sizes</strong>
<ul ><pre>
MAX_DGRAM = 31744 # Maximum size for datagram packet
MAX_RAW = 32768 # Maximum size for raw packet
</pre>
</ul >
<strong>Flags for recv()</strong>
<ul ><pre>
MSG_DONTWAIT = 128 # Don't block
MSG_PEEK = 2 # Peek at incoming data
MSG_WAITALL = 64 # Wait for all data or error
</pre>
</ul >
<strong>Polling flags</strong>
<ul ><pre>
POLLIN = 1
POLLOUT = 4
POLLERR = 8
POLLHUP = 16
POLLNVAL = 32
POLLPRI = 1
</pre>
</ul >
<p>
</div>
<p><em>
</em><!-- Time since request: 0.86 secs. -->
</body></html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment