Updated wiki text sources

This commit is contained in:
sunshine
2004-08-09 10:01:04 +00:00
committed by zzz
parent 2c2a103676
commit 5abd2b400c
11 changed files with 585 additions and 23 deletions

View File

@ -0,0 +1,49 @@
Title: User's Guide:i2p.BaseHTTPServer
Emulates Python BaseHTTPServer module using I2P sockets.
== Overview ==
The Python module is described at http://www.python.org/doc/current/lib/module-BaseHTTPServer.html
To get a server going, use:
<ul><pre>
>>> from i2p import BaseHTTPServer
>>> BaseHTTPServer.test().
</pre></ul>
Consult the documentation for function test() to change basic server settings, such as the session name.
A fully customizable example:
<ul><pre>
>>> from i2p import BaseHTTPServer
>>> session = "mytestxxx.i2p" # SAM session name
>>> class MyServer(BaseHTTPServer.HTTPServer): pass
>>> class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): pass
>>> httpd = MyServer(session, MyRequestHandler)
>>> httpd.socket.dest
(Base64 Destination of server)
>>> httpd.serve_forever()
</pre></ul>
== Classes ==
class '''BaseHTTPRequestHandler'''
<ul><pre>
Same interface as Python class BaseHTTPServer.BaseHTTPRequestHandler.
</pre></ul>
class '''HTTPServer'''
<ul><pre>
Same interface as Python class BaseHTTPServer.HTTPServer.
</pre></ul>
== Functions ==
'''test'''(HandlerClass=BaseHTTPRequestHandler, ServerClass=HTTPServer, protocol='HTTP/1.0', session='mytestxxx.i2p')
<ul><pre>
Test the HTTP request handler class.
This runs an I2P TCP server under SAM session 'session'. If a single command
line argument is given, the argument is used instead as the SAM session name.
</pre></ul>

View File

@ -0,0 +1,48 @@
Title: User's Guide:i2p.CGIHTTPServer
Module <code>i2p.CGIHTTPServer</code> emulates the Python CGIHTTPServer module using I2P sockets.
== Overview ==
The Python module is described at http://www.python.org/doc/current/lib/module-CGIHTTPServer.html
To get a server going, use:
<ul><pre>
>>> from i2p import CGIHTTPServer
>>> CGIHTTPServer.test().
</pre></ul>
Consult the documentation for function test() to change basic server settings, such as the session name.
A fully customizable example:
<ul><pre>
>>> from i2p import BaseHTTPServer, CGIHTTPServer
>>> session = "mytestxxx.i2p" # SAM session name
>>> class MyServer(BaseHTTPServer.HTTPServer): pass
>>> class MyRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler): pass
>>> httpd = MyServer(session, MyRequestHandler)
>>> httpd.socket.dest
(Base64 Destination of server)
>>> httpd.serve_forever()
</pre></ul>
== Classes ==
class '''CGIHTTPRequestHandler'''
<ul><pre>
Same interface as Python class CGIHTTPServer.CGIHTTPRequestHandler.
</pre></ul>
== Functions ==
'''test'''(HandlerClass=CGIHTTPRequestHandler,
ServerClass=i2p.BaseHTTPServer.HTTPServer,
session='mytestxxx.i2p')
<ul><pre>
Test the HTTP CGI request handler class.
This runs an I2P TCP server under SAM session 'session'. If a single
command line argument is given, the argument is used instead as the SAM session
name.
</pre></ul>

View File

@ -0,0 +1,45 @@
Title: User's Guide:i2p.SimpleHTTPServer
Emulates Python SimpleHTTPServer module using I2P sockets.
== Overview ==
The Python module is described at http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html
To get a server going, use:
<ul><pre>
>>> from i2p import SimpleHTTPServer
>>> SimpleHTTPServer.test().
</pre></ul>
Consult the documentation for function test() to change basic server settings, such as the session name.
A fully customizable example:
<ul><pre>
>>> from i2p import BaseHTTPServer, SimpleHTTPServer
>>> session = "mytestxxx.i2p" # SAM session name
>>> class MyServer(BaseHTTPServer.HTTPServer): pass
>>> class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): pass
>>> httpd = MyServer(session, MyRequestHandler)
>>> httpd.socket.dest
(Base64 Destination of server)
>>> httpd.serve_forever()
</pre></ul>
== Classes ==
class '''SimpleHTTPRequestHandler'''
<ul><pre>
Same interface as Python class SimpleHTTPServer.SimpleHTTPRequestHandler.
</pre></ul>
== Functions ==
'''test'''(HandlerClass=SimpleHTTPRequestHandler, ServerClass= i2p.BaseHTTPServer.HTTPServer, session='mytestxxx.i2p')
<ul><pre>
Test the HTTP simple request handler class.
This runs an I2P TCP server under SAM session 'session'. If a single command
line argument is given, the argument is used instead as the SAM session name.
</pre></ul>

View File

@ -0,0 +1,22 @@
Title: User's Guide:i2p.SocketServer
Emulates Python SocketServer module using I2P sockets.
The Python module is described at http://www.python.org/doc/current/lib/module-SocketServer.html
== Classes ==
<ul><pre>
BaseRequestHandler
BaseServer
DatagramRequestHandler
ForkingMixIn
ForkingTCPServer
ForkingUDPServer
StreamRequestHandler
TCPServer
ThreadingMixIn
ThreadingTCPServer
ThreadingUDPServer
UDPServer
</pre></ul>

View File

@ -19,8 +19,8 @@ Module <code>i2p.router</code> allows Python programs to control the I2P router.
Find the absolute path to a locally installed I2P router. Find the absolute path to a locally installed I2P router.
An I2P installation is located by looking in the An I2P installation is located by looking in the
environment I2P, then in PATH, then in the dir argument dir argument given to the function, then in the environment
given to the function. It looks for startRouter.sh or I2P, then in PATH. It looks for startRouter.sh or
startRouter.bat. Raises ValueError if an I2P installation startRouter.bat. Raises ValueError if an I2P installation
could not be located. could not be located.
</pre></ul> </pre></ul>

View File

@ -0,0 +1,27 @@
Title: User's Guide:i2p.select
Module <code>i2p.select</code> emulates the Python module <code>select</code>.
With this module, a program can perform select and poll commands on traditional and I2P sockets.
'''poll'''()
<ul>
Returns a polling object. Works on SAM sockets and Python sockets.
See [http://www.python.org/doc/current/lib/module-select.html select.poll()] in the Python library for more information.
</ul>
'''select'''(readlist, writelist, errlist, timeout=None)
<ul>
Performs a select call. Works on SAM sockets and Python sockets.
See [http://www.python.org/doc/current/lib/module-select.html select.select()] in the Python library for more information.
</ul>
'''Polling flags'''
<ul><pre>
POLLIN = 1
POLLOUT = 4
POLLERR = 8
POLLHUP = 16
POLLNVAL = 32
POLLPRI = 1
</pre></ul>

View File

@ -0,0 +1,276 @@
Title: User's Guide:i2p.socket
Module <code>i2p.socket</code> allows Python programs to access the [[SAM proxy]]. It emulates the Python module <code>socket</code>.
With this module, a program can send stream data, datagrams, and raw packets across the I2P network.
== Sockets ==
class '''socket'''(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.
</pre>
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.
</ul>
The class <code>socket</code> defines the following properties:
<ul>
dest - Local I2P Destination of socket
session - Session name
type - Socket type: SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW.
</ul>
The class <code>socket</code> defines the following methods:
'''accept'''(self)
<ul><pre>
Accept an incoming connection. The socket must be type SOCK_STREAM, and
listen() must be called prior to this command. The return value is (conn,
remotedest), where conn is a new socket object made for the connection, and
remotedest is the remote Destination from which the connection was made.
Example:
>>> from i2p import socket
>>> s = socket.socket('Alice', socket.SOCK_STREAM)
>>> s.listen(10)
This prepares the server. Now accept an incoming connection:
>>> c, remotedest = s.accept()
>>> c.send('hello world!')
If accept() is called on a socket that is in non-blocking mode or has a
timeout, i2p.socket.BlockError or i2p.socket.Timeout may be raised. This
indicates that no incoming connection is currently available.
</pre></ul>
'''bind'''(self, address)
<ul><pre>
Does nothing. Provided for compatibility with the Python socket command
bind(), which binds a server to a port.
</pre></ul>
'''close'''(self)
<ul><pre>
Closes the socket. It is an error to call any method other than recv() or
recvfrom() on a closed socket. For streams, the receive methods return data
that was received prior to the closing of the socket. For datagram and raw
sockets, the receive methods cannot be used on a closed socket.
</pre></ul>
'''connect'''(self, address)
<ul><pre>
Connect to a remote dest, identified in local SAM bridge's hosts file as host
'address'.
For example:
>>> s.connect('duck.i2p')
Alternatively, you can use a full base64 Destination:
Example:
>>> s.connect('238797sdfh2k34kjh....AAAA')
If connect() is called on a socket that is in non-blocking mode or has a
timeout, i2p.socket.BlockError or i2p.socket.Timeout may be raised. This
indicates that the connection is still being initiated. Use i2p.select.select()
to determine when the connection is ready.
</pre></ul>
'''connect_ex'''(self, address)
<ul><pre>
Like connect(), but return any error that is raised. Returns None if no error
is raised.
</pre></ul>
'''getpeername'''(self)
<ul><pre>
Get the remote Destination associated with the socket. This is equivalent to
s.remotedest, and is provided for compatibility with the Python socket module.
</pre></ul>
'''getsockname'''(self)
<ul><pre>
Get the local Destination associated with the socket. This is equivalent to
s.dest, and is provided for compatibility with the Python socket module.
</pre></ul>
'''gettimeout'''(self)
<ul><pre>
Get the timeout value.
</pre></ul>
'''listen'''(self, backlog)
<ul><pre>
Listen for connections made to the socket. This method must be called before
accept(). The backlog argument specifies the maximum number of queued incoming
connections.
</pre></ul>
'''makefile'''(self, mode='r', bufsize=-1)
<ul><pre>
Return a file object for the socket. See socket.makefile() in the Python
documentation for more information.
</pre></ul>
'''recv'''(self, bufsize, flags=0)
<ul><pre>
Receive string data from the socket.
The maximum amount of data to be received is given by bufsize. If bufsize is
zero, this function returns an empty string immediately. If bufsize is nonzero,
this function blocks until at least one character is available for reading. If
the socket has been closed, an empty string is returned as an end of file
indicator.
If recv() is called on a socket that is in non-blocking mode or has a timeout,
i2p.socket.BlockError or i2p.socket.Timeout will be raised if data is not
available within the given timeframe.
For a datagram or raw socket, the first bufsize characters of the packet are
read, and the remainder of the packet is discarded. To read the entire packet,
use bufsize = -1.
For datagram and raw sockets, the packet may originate from any Destination.
Use recvfrom() with datagrams to determine the Destination from which the
packet was received.
The flags argument can be a bitwise OR of MSG_PEEK, MSG_WAITALL, and/or
MSG_DONTWAIT. MSG_PEEK indicates that any data read should not be removed from
the socket's incoming buffer. MSG_WAITALL indicates to wait for exactly bufsize
characters or an error. MSG_DONTWAIT indicates that the recv() command should
not block execution.
</pre></ul>
'''recvfrom'''(self, bufsize, flags=0)
<ul><pre>
Like recv(), but returns a tuple (data, remoteaddr), where data is the string
data received, and remoteaddr is the remote Destination.
</pre></ul>
'''send'''(self, string, flags=0)
<ul><pre>
Sends string data to a remote Destination.
For a stream, connect() must be called prior to send(). Once close() is called,
no further data can be sent, and the stream cannot be re-opened.
For datagram and raw sockets, connect() only specifies a Destination to which
packets are sent to. send() will then send a packet to the given Destination.
connect() can be used multiple times.
The send() command never blocks execution. The flags argument is ignored.
</pre></ul>
'''sendall'''(self, string, flags=0)
<ul><pre>
Identical to send().
</pre></ul>
'''sendto'''(self, string, flags, address)
<ul><pre>
Send a packet to the given Destination.
Only valid for datagram and raw sockets. The address argument should be either
a name from the hosts file, or a base64 Destination.
The sendto() command never blocks execution. The flags argument is ignored.
</pre></ul>
'''setblocking'''(self, flag)
<ul><pre>
Set blocking or non-blocking mode for the socket.
If flag is True, any method called on the socket will hang until the method has
completed. If flag is False, all methods will raise i2p.socket.BlockError() if
they cannot complete instantly.
s.setblocking(False) is equivalent to s.settimeout(0); s.setblocking(True) is
equivalent to s.settimeout(None).
</pre></ul>
'''settimeout'''(self, value)
<ul><pre>
Set a timeout for the socket.
The value argument should be a timeout value in seconds, or None. None is
equivalent to an infinite timeout.
A socket operation will raise a i2p.socket.Timeout if the operation cannot
complete within in the specified time limit.
</pre></ul>
== Functions ==
Functions defined in module <code>i2p.socket</code>:
'''resolve'''(host, samaddr='127.0.0.1:7656')
<ul>
Resolve I2P host name --> I2P Destination.
Returns the same string if host is already a Destination.
</ul>
== Errors ==
class '''Error'''(i2p.Error)
<ul><pre>
Base class for all SAM errors.
</pre></ul>
class '''BlockError'''(Error)
<ul><pre>
Socket call would have blocked.
</pre></ul>
class '''ClosedError'''(Error)
<ul><pre>
A command was used on a socket that closed gracefully.
</pre></ul>
class '''NetworkError'''(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>
== Constants ==
'''Socket types'''
<ul><pre>
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
</pre></ul>
'''Packet sizes'''
<ul><pre>
MAX_DGRAM = 31744 # Maximum size for datagram packet
MAX_RAW = 32768 # Maximum size for raw packet
</pre></ul>
'''Flags for recv()'''
<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>

View File

@ -0,0 +1,79 @@
Title: User's Guide:i2p.tunnel
Module <code>i2p.tunnel</code> allows data to be exchanged between traditional TCP sockets and I2P sockets.
== Tunnels ==
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.
class '''Tunnel'''(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 i2p.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.
</pre></ul>
'''close'''()
<ul>
Close all connections made for this tunnel.
</ul>
=== Tunnel Server ===
class '''TunnelServer'''(session, port, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
<ul><pre>
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 i2p.socket.socket(). This call blocks until the
tunnel is ready.
</pre></ul>
'''TunnelServer''' properties:
<ul><pre>
dest - I2P Destination of server.
session - Session name for server.
</pre></ul>
=== Tunnel Client ===
class '''TunnelClient'''(session, port, dest, samaddr='127.0.0.1:7656', nconnect=-1, timeout=None, **kwargs)
<ul><pre>
Derived from Tunnel.
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 i2p.socket.socket(). This call
blocks until the tunnel is ready.
</pre></ul>
'''TunnelClient''' properties:
<ul><pre>
dest - Local Destination used for routing.
remotedest - Remote Destination.
session - Session name for local Destination.
</pre></ul>

View File

@ -2,15 +2,19 @@ Title: User's Guide:i2p
Package <code>i2p</code> is a container package for more specific modules. Package <code>i2p</code> is a container package for more specific modules.
It exports the following names: It contains the following modules:
<ul>
[[:User's Guide:i2p.sam|sam]]
[[:User's Guide:i2p.eep|eep]]
[[:User's Guide:i2p.router|router]]
[[:User's Guide:i2p#Error|Error]]
[[:User's Guide:i2p#RouterError|RouterError]]
</ul>
<ul>
[[:User's Guide:i2p.BaseHTTPServer|i2p.BaseHTTPServer]] (Emulate Python BaseHTTPServer module)
[[:User's Guide:i2p.CGIHTTPServer|i2p.CGIHTTPServer]] (Emulate Python CGIHTTPServer module)
[[:User's Guide:i2p.eep|i2p.eep]] (Retrieve eepsites)
[[:User's Guide:i2p.router|i2p.router]] (Manage the I2P router)
[[:User's Guide:i2p.select|i2p.select]] (Emulate Python select module)
[[:User's Guide:i2p.SimpleHTTPServer|i2p.SimpleHTTPServer]] (Emulate Python SimpleHTTPServer module)
[[:User's Guide:i2p.socket|i2p.socket]] (Send and receive across the I2P network)
[[:User's Guide:i2p.SocketServer|i2p.SocketServer]] (Emulate Python SocketServer module)
[[:User's Guide:i2p.tunnel|i2p.tunnel]] (Exchange data between I2P and regular sockets)
</ul>
class '''Error'''(Exception): class '''Error'''(Exception):
<ul> <ul>
Base class for all I2P errors. Base class for all I2P errors.

View File

@ -13,21 +13,29 @@ python setup.py install
Use: Use:
<ul><pre> <ul><pre>
>>> from i2p import sam >>> from i2p import socket
>>> s = sam.socket('Alice', sam.SOCK_STREAM) >>> s = socket.socket('Alice', socket.SOCK_STREAM)
>>> s.connect('duck.i2p') >>> s.connect('duck.i2p')
>>> s.send('GET / HTTP/1.0\r\n\r\n') >>> s.send('GET / HTTP/1.0\r\n\r\n')
>>> s.recv(1000) >>> s.recv(1000)
(HTTP response from duck.i2p) (HTTP response from duck.i2p)
</pre></ul> </pre></ul>
See the src/examples/ directory for more code examples.
== User's Guide == == User's Guide ==
The following modules are available: The following modules are available:
<ul> <ul>
[[:User's Guide:i2p|i2p]] (Container package) [[:User's Guide:i2p|i2p]] (Container package)
[[:User's Guide:i2p.sam|i2p.sam]] (Send and receive across the I2P network) [[:User's Guide:i2p.BaseHTTPServer|i2p.BaseHTTPServer]] (Emulate Python BaseHTTPServer module)
[[:User's Guide:i2p.eep|i2p.eep]] (Retrieve eepsites) [[:User's Guide:i2p.CGIHTTPServer|i2p.CGIHTTPServer]] (Emulate Python CGIHTTPServer module)
[[:User's Guide:i2p.router|i2p.router]] (Manage the I2P router) [[:User's Guide:i2p.eep|i2p.eep]] (Retrieve eepsites)
[[:User's Guide:i2p.router|i2p.router]] (Manage the I2P router)
[[:User's Guide:i2p.select|i2p.select]] (Emulate Python select module)
[[:User's Guide:i2p.SimpleHTTPServer|i2p.SimpleHTTPServer]] (Emulate Python SimpleHTTPServer module)
[[:User's Guide:i2p.socket|i2p.socket]] (Send and receive across the I2P network)
[[:User's Guide:i2p.SocketServer|i2p.SocketServer]] (Emulate Python SocketServer module)
[[:User's Guide:i2p.tunnel|i2p.tunnel]] (Exchange data between I2P and regular sockets)
</ul> </ul>

View File

@ -6,13 +6,17 @@ This directory houses the wiki text sources.
Feel free to move to any other documentation system, if Feel free to move to any other documentation system, if
it is efficient and easy to maintain. it is efficient and easy to maintain.
Ideally, one could patch pydoc to export only certain Do not use the Monobook skin, as it is Copyrighted.
names, in a certain order, like so:
__pydoc__ = ['f', 'g'] # f() and g() documented in order -------------------------------------------------------
This could proceed recursively for all namespaces. The documentation made by epydoc is pretty nice.
Combine this with a second patch to make pydoc create Ideally, one could patch epydoc to use a more condensed
nice CSS, and this whole guide could be generated 2-column format (where there are fewer pages, and it is
directly from the sources. easier to read).
With a little work on the output, epydoc could then be
used solely for documenting this project.
Note that the docs produced by epydoc are huge.