2012-11-09 10:40:57 +00:00
|
|
|
{% extends "global/layout.html" %}
|
2009-05-06 19:46:57 +00:00
|
|
|
{% block title %}SAM V3{% endblock %}
|
2014-07-19 15:57:32 +00:00
|
|
|
{% block lastupdated %}July 2014{% endblock %}
|
2014-06-28 15:56:00 +00:00
|
|
|
{% block accuratefor %}0.9.14{% endblock %}
|
2009-05-06 19:46:57 +00:00
|
|
|
{% block content %}
|
|
|
|
<p>Specified below is a simple client protocol for interacting with I2P.
|
2010-08-16 01:55:25 +00:00
|
|
|
</p>
|
|
|
|
<p>SAM version 3
|
|
|
|
was introduced in I2P release 0.7.3.
|
|
|
|
Alternatives:
|
2012-11-09 10:40:57 +00:00
|
|
|
<a href="{{ site_url('docs/api/sam') }}">SAM V1</a>,
|
|
|
|
<a href="{{ site_url('docs/api/samv2') }}">SAM V2</a>,
|
|
|
|
<a href="{{ site_url('docs/api/bob') }}">BOB</a>.
|
2009-05-06 19:46:57 +00:00
|
|
|
</p>
|
|
|
|
|
2014-07-13 23:56:20 +00:00
|
|
|
<h2>Version 3 Language Libraries</h2>
|
|
|
|
<ul>
|
2014-07-16 02:59:37 +00:00
|
|
|
<li>C - <a href="http://{{ i2pconv('git.repo.i2p') }}/w/libsam3.git">libsam3</a></li>
|
2014-07-16 03:02:56 +00:00
|
|
|
<li>C++ - <a href="https://github.com/VirtualDestructor/bitcoin-qt-i2p/tree/master/i2psam">i2psam</a></li>
|
2014-07-13 23:56:20 +00:00
|
|
|
<li>Go - <a href="https://bitbucket.org/kallevedin/sam3">sam3</a>,
|
|
|
|
<a href="https://github.com/cryptix/goSam">goSam</a> (<a href="http://git.repo.i2p/w/goSam.git">in I2P</a>)</li>
|
|
|
|
</ul>
|
|
|
|
|
2014-06-28 15:56:00 +00:00
|
|
|
<h2>Version 3 Changes</h2>
|
|
|
|
<h3>Version 3.0 Changes</h3>
|
|
|
|
<p>
|
|
|
|
Version 3.0 was introduced in I2P release 0.7.3.
|
2010-08-16 01:55:25 +00:00
|
|
|
SAM v2 provided a way to manage several sockets
|
2009-05-06 19:46:57 +00:00
|
|
|
on the same I2P destination <i>in parallel</i>, i.e. the client does not
|
|
|
|
have to wait for data being successfully sent on one socket before sending
|
2010-08-16 01:55:25 +00:00
|
|
|
data on another socket. But all data transited through the same
|
|
|
|
client<-->SAM socket, which was quite complicated to manage for the client.
|
2009-05-06 19:46:57 +00:00
|
|
|
<p />
|
2010-08-16 01:55:25 +00:00
|
|
|
SAM v3 manages sockets in a different way: each <i>I2P socket</i>
|
|
|
|
matches a unique client<-->SAM socket, which is much more simple to handle.
|
2012-11-09 10:40:57 +00:00
|
|
|
This is similar to <a href="{{ site_url('docs/api/bob') }}">BOB</a>.
|
2009-05-06 19:46:57 +00:00
|
|
|
<br />
|
2010-08-16 01:55:25 +00:00
|
|
|
SAM v3 also offers a UDP port for sending datagrams through I2P, and
|
2009-05-06 19:46:57 +00:00
|
|
|
can forward back I2P datagrams to the client's datagram server.
|
2014-06-28 15:56:00 +00:00
|
|
|
</p>
|
2009-05-06 19:46:57 +00:00
|
|
|
|
2014-06-28 15:56:00 +00:00
|
|
|
<h3>Version 3.1 Changes</h3>
|
|
|
|
<p>
|
|
|
|
Version 3.1 was introduced in I2P release 0.9.14.
|
|
|
|
<ul>
|
|
|
|
<li>DEST GENERATE and SESSION CREATE now support a SIGNATURE_TYPE parameter.
|
|
|
|
<li>The MIN and MAX parameters in HELLO VERSION are now optional.
|
|
|
|
<li>The MIN and MAX parameters in HELLO VERSION now support single-digit versions such as "3".
|
2014-07-19 15:57:32 +00:00
|
|
|
<li>RAW SEND is now supported on the bridge socket.
|
2014-06-28 15:56:00 +00:00
|
|
|
</ul>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<h2>Version 3 Protocol</h2>
|
2009-05-06 19:46:57 +00:00
|
|
|
<pre>
|
|
|
|
----------------------------------------------------------------------
|
2010-08-16 01:55:25 +00:00
|
|
|
Simple Anonymous Messaging (SAM version 3.0) Specification
|
2009-05-06 19:46:57 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
Client application talks to SAM bridge, which deals with
|
2010-08-16 01:55:25 +00:00
|
|
|
all of the I2P functionality (using the streaming
|
2009-05-06 19:46:57 +00:00
|
|
|
lib for virtual streams, or I2CP directly for async messages).
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
All client<-->SAM bridge communication is unencrypted and
|
2009-05-06 19:46:57 +00:00
|
|
|
unauthenticated. Access to the SAM
|
|
|
|
bridge should be protected through firewalls or other means
|
|
|
|
(perhaps the bridge may have ACLs on what IPs it accepts
|
|
|
|
connections from).
|
|
|
|
|
|
|
|
All of these SAM messages are sent on a single line in plain ASCII,
|
|
|
|
terminated by the newline character (\n). The formatting shown
|
|
|
|
below is merely for readability, and while the first two words in
|
|
|
|
each message must stay in their specific order, the ordering of
|
|
|
|
the key=value pairs can change (e.g. "ONE TWO A=B C=D" or
|
|
|
|
"ONE TWO C=D A=B" are both perfectly valid constructions). In
|
|
|
|
addition, the protocol is case-sensitive.
|
2010-08-16 01:55:25 +00:00
|
|
|
In the following, message examples are preceded by "-> " for
|
|
|
|
messages sent by the client to the SAM bridge, and by "<- " for
|
2009-05-06 19:46:57 +00:00
|
|
|
messages sent by the SAM bridge to the client.
|
|
|
|
|
|
|
|
I2P communications can take three distinct forms:
|
2013-02-06 01:55:33 +00:00
|
|
|
* <a href="{{ site_url('docs/api/streaming') }}">Virtual streams</a>
|
|
|
|
* <a href="{{ site_url('docs/spec/datagrams') }}#repliable">Repliable datagrams</a> (messages with a FROM field)
|
|
|
|
* <a href="{{ site_url('docs/spec/datagrams') }}#raw">Anonymous datagrams</a> (raw anonymous messages)
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
I2P communications are supported by I2P sessions, and each I2P
|
|
|
|
session is bound to an address (called destination). An I2P session
|
|
|
|
is associated with one of the three types above, and cannot carry
|
|
|
|
communications of another type.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM connection handshake
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
No SAM communication can occur until after the client and bridge have
|
|
|
|
agreed on a protocol version, which is done by the client sending
|
|
|
|
a HELLO and the bridge sending a HELLO REPLY:
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> HELLO VERSION MIN=$min MAX=$max
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
and
|
|
|
|
|
2014-06-28 15:56:00 +00:00
|
|
|
<- HELLO REPLY RESULT=OK VERSION=3.1
|
2009-05-06 19:46:57 +00:00
|
|
|
|
2014-06-28 15:56:00 +00:00
|
|
|
As of version 3.1 (I2P 0.9.14), the MIN and MAX parameters are optional.
|
|
|
|
SAM will always return the highest version possible given the
|
|
|
|
MIN and MAX constraints, or 3.1 if no constraints are given.
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If the SAM bridge cannot find a suitable version, it replies with :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- HELLO REPLY RESULT=NOVERSION
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If some error occurred, such as a bad request format, it replies with :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- HELLO REPLY RESULT=I2P_ERROR MESSAGE={$message}
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM sessions
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
A SAM session is created by a client opening a socket to the SAM
|
|
|
|
bridge, operating a handshake, and sending a SESSION CREATE message,
|
|
|
|
and the session terminates when the socket is disconnected.
|
|
|
|
|
|
|
|
Each registered I2P Destination is uniquely associated with a session ID
|
|
|
|
(or nickname).
|
|
|
|
|
|
|
|
Each session is uniquely associated with :
|
|
|
|
* the socket from which the client creates the session
|
|
|
|
* its ID (or nickname)
|
|
|
|
|
|
|
|
The session creation message can only use one of these forms (messages
|
|
|
|
received through other forms are answered with an error message) :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> SESSION CREATE
|
2009-05-06 19:46:57 +00:00
|
|
|
STYLE={STREAM,DATAGRAM,RAW}
|
|
|
|
ID={$nickname}
|
|
|
|
DESTINATION={$private_destination_key,TRANSIENT}
|
|
|
|
[option=value]*
|
|
|
|
|
|
|
|
DESTINATION specifies what destination should be used for
|
2014-06-25 14:26:42 +00:00
|
|
|
sending and receiving messages/streams. It is the base 64 encoding of
|
|
|
|
the concatenation of the destination, private key, and signing private key.
|
2014-06-28 15:56:00 +00:00
|
|
|
|
|
|
|
If the destination is specified as TRANSIENT, the SAM bridge creates a new destination.
|
|
|
|
As of version 3.1 (I2P 0.9.14), if the destination is TRANSIENT, an optional parameter
|
|
|
|
SIGNATURE_TYPE is supported. The SIGNATURE_TYPE value may be any name
|
|
|
|
(e.g. ECDSA_SHA256_P256, case insensitive) or number (e.g. 1)
|
2014-06-30 14:47:25 +00:00
|
|
|
supported by <a href="{{ site_url('docs/spec/common-structures') }}#type_Certificate">Key Certificates</a>.
|
2014-06-28 15:56:00 +00:00
|
|
|
The default is DSA_SHA1.
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
{$nickname} is the choice of the client. No whitespace is allowed.
|
|
|
|
|
|
|
|
Additional options given are passed to the I2P session
|
|
|
|
configuration if not interpreted by the SAM bridge (e.g.
|
|
|
|
outbound.length=0). These options are documented below.
|
|
|
|
|
|
|
|
The SAM bridge itself should already be configured with what router
|
|
|
|
it should communicate over I2P through (though if need be there may
|
|
|
|
be a way to provide an override, e.g. i2cp.tcp.host=localhost and
|
|
|
|
i2cp.tcp.port=7654).
|
|
|
|
|
|
|
|
After receiving the session create message, the SAM bridge will reply
|
|
|
|
with a session status message, as follows:
|
|
|
|
|
|
|
|
If the creation was successful :
|
2010-08-16 01:55:25 +00:00
|
|
|
<- SESSION STATUS RESULT=OK DESTINATION={$private_destination_key}
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If the nickname is already associated with a session :
|
2010-08-16 01:55:25 +00:00
|
|
|
<- SESSION STATUS RESULT=DUPLICATED_ID
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If the destination is already in use :
|
2010-08-16 01:55:25 +00:00
|
|
|
<- SESSION STATUS RESULT=DUPLICATED_DEST
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If the destination is not a valid private destination key :
|
2010-08-16 01:55:25 +00:00
|
|
|
<- SESSION STATUS RESULT=INVALID_KEY
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If some other error has occurred :
|
2010-08-16 01:55:25 +00:00
|
|
|
<- SESSION STATUS RESULT=I2P_ERROR MESSAGE={$message}
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
If it's not OK, the MESSAGE should contain human-readable information
|
|
|
|
as to why the session could not be created.
|
|
|
|
|
|
|
|
|
|
|
|
SAM sessions live and die with the socket they are associated with.
|
|
|
|
When the socket is closed, the session dies, and all communications
|
|
|
|
using the session die at the same time. And the other way round, when
|
|
|
|
the session dies for any reason, the SAM bridge closes the socket.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM virtual streams
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Virtual streams are guaranteed to be sent reliably and in order, with
|
|
|
|
failure and success notification as soon as it is available.
|
|
|
|
|
|
|
|
Streams are bidirectional communication sockets between two I2P
|
|
|
|
destinations, but their opening has to be requested by one of them.
|
|
|
|
Hereafter, CONNECT commands are used by the SAM client for such a
|
|
|
|
request. FORWARD / ACCEPT commands are used by the SAM client when
|
|
|
|
he wants to listen to requests coming from other I2P destinations.
|
|
|
|
|
|
|
|
|
|
|
|
-----------------------------
|
|
|
|
SAM virtual streams : CONNECT
|
|
|
|
-----------------------------
|
|
|
|
A client asks for a connection by :
|
|
|
|
* opening a new socket with the SAM bridge
|
|
|
|
* passing the same HELLO handshake as above
|
|
|
|
* sending the connection command :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> STREAM CONNECT
|
2009-05-06 19:46:57 +00:00
|
|
|
ID={$nickname}
|
|
|
|
DESTINATION=$peer_public_base64_key
|
2012-12-30 22:23:48 +00:00
|
|
|
[SILENT={true,false}]
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
This establishes a new virtual connection from the local session
|
|
|
|
whose ID is {$nickname} to the specified peer.
|
|
|
|
|
2012-12-30 22:23:48 +00:00
|
|
|
If SILENT=true is passed, the SAM bridge won't issue any other message
|
2009-05-06 19:46:57 +00:00
|
|
|
on the socket : if the connection fails, the socket will be closed.
|
|
|
|
If the connection succeeds, all remaining data passing through the
|
|
|
|
current socket is forwarded from and to the connected I2P destination
|
|
|
|
peer.
|
|
|
|
|
2012-12-30 22:23:48 +00:00
|
|
|
If SILENT=false, which is the default value, the SAM bridge sends a
|
2009-05-06 19:46:57 +00:00
|
|
|
last message to its client before forwarding or shutting down the
|
|
|
|
socket :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- STREAM STATUS
|
2009-05-06 19:46:57 +00:00
|
|
|
RESULT=$result
|
|
|
|
[MESSAGE=...]
|
|
|
|
|
|
|
|
The RESULT value may be one of:
|
|
|
|
|
|
|
|
OK
|
|
|
|
CANT_REACH_PEER
|
|
|
|
I2P_ERROR
|
|
|
|
INVALID_KEY
|
|
|
|
INVALID_ID
|
|
|
|
TIMEOUT
|
|
|
|
|
|
|
|
If the RESULT is OK, all remaining data passing through the
|
|
|
|
current socket is forwarded from and to the connected I2P destination
|
|
|
|
peer. If the connection was not possible (timeout, etc),
|
|
|
|
RESULT will contain the appropriate error value (accompanied by an
|
|
|
|
optional human-readable MESSAGE), and the SAM bridge closes the
|
|
|
|
socket.
|
|
|
|
|
|
|
|
----------------------------
|
|
|
|
SAM virtual streams : ACCEPT
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
A client waits for an incoming connection request by :
|
|
|
|
* opening a new socket with the SAM bridge
|
|
|
|
* passing the same HELLO handshake as above
|
|
|
|
* sending the accept command :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> STREAM ACCEPT
|
2009-05-06 19:46:57 +00:00
|
|
|
ID={$nickname}
|
2012-12-30 22:23:48 +00:00
|
|
|
[SILENT={true,false}]
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
This makes the session ${nickname} listen for one incoming
|
|
|
|
connection request from the I2P network.
|
|
|
|
|
|
|
|
The SAM bridge answers with :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- STREAM STATUS
|
2009-05-06 19:46:57 +00:00
|
|
|
RESULT=$result
|
|
|
|
[MESSAGE=...]
|
|
|
|
|
|
|
|
The RESULT value may be one of:
|
|
|
|
|
|
|
|
OK
|
|
|
|
I2P_ERROR
|
|
|
|
INVALID_ID
|
|
|
|
|
|
|
|
If the result is not OK, the socket is closed immediately by the SAM
|
|
|
|
bridge. If the result is OK, the SAM bridge starts waiting for an
|
|
|
|
incoming connection request from another I2P peer. When a request
|
|
|
|
arrives, the SAM bridge accepts it and :
|
|
|
|
|
2012-12-30 22:23:48 +00:00
|
|
|
* If SILENT=true was passed, the SAM bridge won't issue any other message
|
2009-05-06 19:46:57 +00:00
|
|
|
on the client socket : all remaining data passing through the
|
|
|
|
current socket is forwarded from and to the connected I2P destination
|
|
|
|
peer.
|
2012-12-30 22:23:48 +00:00
|
|
|
* If SILENT=false was passed, which is the default value, the SAM bridge
|
2009-05-06 19:46:57 +00:00
|
|
|
sends the client a ASCII line containing the base64 public destination key
|
|
|
|
of the requesting peer. After this '\n' terminated line, all remaining data
|
|
|
|
passing through the current socket is forwarded from and to the connected
|
|
|
|
I2P destination peer, until one of the peer closes the socket.
|
|
|
|
|
|
|
|
-----------------------------
|
|
|
|
SAM virtual streams : FORWARD
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
A client can use a regular socket server and wait for connection requests
|
|
|
|
coming from I2P. For that, the client has to :
|
|
|
|
* open a new socket with the SAM bridge
|
|
|
|
* pass the same HELLO handshake as above
|
|
|
|
* send the forward command :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> STREAM FORWARD
|
2009-05-06 19:46:57 +00:00
|
|
|
ID={$nickname}
|
|
|
|
PORT={$port}
|
|
|
|
[HOST={$host}]
|
2012-12-30 22:23:48 +00:00
|
|
|
[SILENT={true,false}]
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
This makes the session ${nickname} listen for incoming
|
|
|
|
connection requests from the I2P network.
|
|
|
|
|
|
|
|
The SAM bridge answers with :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- STREAM STATUS
|
2009-05-06 19:46:57 +00:00
|
|
|
RESULT=$result
|
|
|
|
[MESSAGE=...]
|
|
|
|
|
|
|
|
The RESULT value may be one of:
|
|
|
|
|
|
|
|
OK
|
|
|
|
I2P_ERROR
|
|
|
|
INVALID_ID
|
|
|
|
|
|
|
|
* {$host} is the hostname or IP address of the socket server to which
|
|
|
|
SAM will forward connection requests. If not given, SAM takes the IP
|
|
|
|
of the socket that issued the forward command.
|
|
|
|
|
|
|
|
* {$port} is the port number of the socket server to which SAM will
|
|
|
|
forward connection requests. It is mandatory.
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
When a connection request arrives from I2P, the SAM bridge requests a
|
|
|
|
socket connection from {$host}:{$port}. If it is accepted after no more
|
|
|
|
than 3 seconds, SAM will accept the connection from I2P, and then :
|
2009-05-06 19:46:57 +00:00
|
|
|
|
2012-12-30 22:23:48 +00:00
|
|
|
* If SILENT=true was passed, all data passing through the obtained
|
2009-05-06 19:46:57 +00:00
|
|
|
current socket is forwarded from and to the connected I2P destination
|
|
|
|
peer.
|
2012-12-30 22:23:48 +00:00
|
|
|
* If SILENT=false was passed, which is the default value, the SAM bridge
|
2009-05-06 19:46:57 +00:00
|
|
|
sends on the obtained socket an ASCII line containing the base64 public
|
|
|
|
destination key of the requesting peer. After this '\n' terminated line,
|
|
|
|
all remaining data passing through the socket is forwarded from and to
|
|
|
|
the connected I2P destination peer, until one of the sides closes the
|
|
|
|
socket.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The I2P router will stop listening to incoming connection requests as
|
|
|
|
soon as the "forwarding" socket is closed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM repliable datagrams : sending a datagram
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
While I2P doesn't inherently contain a FROM address, for ease of use
|
|
|
|
an additional layer is provided as repliable datagrams - unordered
|
2014-07-19 15:57:32 +00:00
|
|
|
and unreliable messages of up to 31744 bytes that include a FROM
|
2009-05-06 19:46:57 +00:00
|
|
|
address (leaving up to 1KB for header material). This FROM address
|
|
|
|
is authenticated internally by SAM (making use of the destination's
|
|
|
|
signing key to verify the source) and includes replay prevention.
|
|
|
|
|
2014-07-19 15:57:32 +00:00
|
|
|
Minimum size is 1. For best delivery reliability, recommended maximum
|
|
|
|
size is approximately 11 KB.
|
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
After establishing a SAM session with STYLE=DATAGRAM, the client can
|
|
|
|
send datagrams through SAM's UDP port (7655).
|
|
|
|
|
|
|
|
The first line of a datagram sent through this port has to be in the
|
|
|
|
following format :
|
|
|
|
|
|
|
|
3.0 {$nickname} {$base64_public_destination_key}
|
|
|
|
|
|
|
|
* 3.0 is the version of SAM
|
|
|
|
* {$nickname} is the id of the DGRAM session that will be used
|
|
|
|
* {$base64_public_destination_key} is the destination of the
|
|
|
|
datagram
|
|
|
|
* this line is '\n' terminated.
|
|
|
|
|
|
|
|
The first line will be discarded by SAM before sending the remaining
|
|
|
|
of the message to the specified destination.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM repliable datagrams : receiving a datagram
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Received datagrams are written by SAM on the socket from which the
|
|
|
|
datagram session was opened, unless specified otherwise by the CREATE
|
|
|
|
command.
|
|
|
|
|
|
|
|
When a datagram arrives, the bridge delivers it to the client via the
|
|
|
|
message :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- DATAGRAM RECEIVED
|
2009-05-06 19:46:57 +00:00
|
|
|
DESTINATION=$base64key
|
|
|
|
SIZE=$numBytes\n[$numBytes of data]
|
|
|
|
|
|
|
|
The SAM bridge never exposes to the client the authentication headers
|
|
|
|
or other fields, merely the data that the sender provided. This
|
|
|
|
continues until the session is closed (by the client dropping the
|
|
|
|
connection).
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM repliable datagrams : forwarding datagrams
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
When creating a datagram session, the client can ask SAM to forward
|
|
|
|
incoming messages to a specified ip:port. It does so by issuing the
|
|
|
|
CREATE command with PORT and HOST options :
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
-> SESSION CREATE
|
2009-05-06 19:46:57 +00:00
|
|
|
STYLE=DATAGRAM
|
|
|
|
ID={$nickname}
|
|
|
|
DESTINATION={$private_destination_key,TRANSIENT}
|
|
|
|
PORT={$port}
|
|
|
|
[HOST={$host}]
|
|
|
|
[option=value]*
|
|
|
|
|
|
|
|
* {$host} is the hostname or IP address of the datagram server to
|
|
|
|
which SAM will forward datagrams. If not given, SAM takes the
|
|
|
|
IP of the socket that issued the forward command.
|
|
|
|
|
|
|
|
* {$port} is the port number of the datagram server to which SAM
|
|
|
|
will forward datagrams.
|
|
|
|
|
|
|
|
When a datagram arrives, the bridge sends to the specified host:port
|
|
|
|
a message containing the following data :
|
|
|
|
|
|
|
|
${sender_base64_destination_key}\n{$datagram_payload}
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM anonymous datagrams
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Squeezing the most out of I2P's bandwidth, SAM allows clients to send
|
|
|
|
and receive anonymous datagrams, leaving authentication and reply
|
|
|
|
information up to the client themselves. These datagrams are
|
2014-07-19 15:57:32 +00:00
|
|
|
unreliable and unordered, and may be up to 32768 bytes.
|
|
|
|
|
|
|
|
Minimum size is 1. For best delivery reliability, recommended maximum
|
|
|
|
size is approximately 11 KB.
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
After establishing a SAM session with STYLE=RAW, the client can
|
2010-03-21 19:41:10 +00:00
|
|
|
send anonymous datagrams through the SAM bridge exactly the same way
|
2009-05-06 19:46:57 +00:00
|
|
|
he sends non anonymous datagrams.
|
|
|
|
|
|
|
|
Both ways of receiving datagrams are also available for anonymous
|
|
|
|
datagrams.
|
|
|
|
|
|
|
|
When anonymous datagrams are to be written to the socket that created
|
|
|
|
the session,the bridge delivers it to the client via:
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
<- RAW RECEIVED
|
2009-05-06 19:46:57 +00:00
|
|
|
SIZE=$numBytes\n[$numBytes of data]
|
|
|
|
|
|
|
|
When anonymous datagrams are to be forwarded to some host:port,
|
|
|
|
the bridge sends to the specified host:port a message containing
|
|
|
|
the following data :
|
|
|
|
|
|
|
|
{$datagram_payload}
|
|
|
|
|
|
|
|
|
2014-07-19 15:57:32 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
V1/V2 Compatible Datagram Handling
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
In SAM V3, the preferred way to send datagrams is via the datagram socket
|
|
|
|
at port 7655 as documented above. However, repliable datagrams may be sent
|
|
|
|
directly via the SAM bridge socket using the DATAGRAM SEND command,
|
|
|
|
as documented in <a href="sam>SAM V1</a> and <a href="samv2>SAM V2</a>.
|
|
|
|
|
|
|
|
As of release 0.9.14 (version 3.1), anonymous datagrams may be sent
|
|
|
|
directly via the SAM bridge socket using the RAW SEND command,
|
|
|
|
as documented in <a href="sam>SAM V1</a> and <a href="samv2>SAM V2</a>.
|
|
|
|
|
|
|
|
These commands do <i>not</i> support the ID parameter. The datagrams are
|
|
|
|
sent to the most recently created DATAGRAM- or RAW-style session,
|
|
|
|
as appropriate. Support for the ID parameter may be added in a future release.
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
SAM utility functionality
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
The following message can be used by the client to query the SAM
|
|
|
|
bridge for name resolution:
|
|
|
|
|
|
|
|
NAMING LOOKUP
|
|
|
|
NAME=$name
|
|
|
|
|
|
|
|
which is answered by
|
|
|
|
|
|
|
|
NAMING REPLY
|
|
|
|
RESULT=$result
|
|
|
|
NAME=$name
|
|
|
|
[VALUE=$base64key]
|
|
|
|
[MESSAGE=$message]
|
|
|
|
|
|
|
|
|
|
|
|
The RESULT value may be one of:
|
|
|
|
|
|
|
|
OK
|
|
|
|
INVALID_KEY
|
|
|
|
KEY_NOT_FOUND
|
|
|
|
|
|
|
|
If NAME=ME, then the reply will contain the base64key used by the
|
|
|
|
current session (useful if you're using a TRANSIENT one). If $result
|
|
|
|
is not OK, MESSAGE may convey a descriptive message, such as "bad
|
|
|
|
format", etc.
|
|
|
|
|
|
|
|
Public and private base64 keys can be generated using the following
|
|
|
|
message:
|
|
|
|
|
|
|
|
DEST GENERATE
|
|
|
|
|
|
|
|
which is answered by
|
|
|
|
|
|
|
|
DEST REPLY
|
|
|
|
PUB=$pubkey
|
|
|
|
PRIV=$privkey
|
|
|
|
|
2014-06-28 15:56:00 +00:00
|
|
|
As of I2P 0.9.14, an optional parameter SIGNATURE_TYPE is supported.
|
|
|
|
The SIGNATURE_TYPE value may be any name (e.g. ECDSA_SHA256_P256, case insensitive) or number (e.g. 1)
|
2014-06-30 14:47:25 +00:00
|
|
|
that is supported by <a href="{{ site_url('docs/spec/common-structures') }}#type_Certificate">Key Certificates</a>.
|
2014-06-28 15:56:00 +00:00
|
|
|
The default is DSA_SHA1.
|
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
RESULT values
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
These are the values that can be carried by the RESULT field, with
|
|
|
|
their meaning:
|
|
|
|
|
2010-08-17 09:54:34 +00:00
|
|
|
OK Operation completed successfully
|
2009-05-06 19:46:57 +00:00
|
|
|
CANT_REACH_PEER The peer exists, but cannot be reached
|
|
|
|
DUPLICATED_DEST The specified Destination is already in use
|
|
|
|
I2P_ERROR A generic I2P error (e.g. I2CP disconnection, etc.)
|
|
|
|
INVALID_KEY The specified key is not valid (bad format, etc.)
|
|
|
|
KEY_NOT_FOUND The naming system can't resolve the given name
|
|
|
|
PEER_NOT_FOUND The peer cannot be found on the network
|
|
|
|
TIMEOUT Timeout while waiting for an event (e.g. peer answer)
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
----------------------------------------------------------------------
|
2010-08-16 01:55:25 +00:00
|
|
|
Tunnel, I2CP, and Streaming Options
|
2009-05-06 19:46:57 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2010-08-16 01:55:25 +00:00
|
|
|
These options may be passed in as name=value pairs at the end of a
|
2009-05-06 19:46:57 +00:00
|
|
|
SAM SESSION CREATE line.
|
|
|
|
|
2013-02-06 01:55:33 +00:00
|
|
|
All sessions may include <a href="{{ site_url('docs/protocol/i2cp') }}#options">I2CP options such as tunnel lengths</a>.
|
|
|
|
STREAM sessions may include <a href="{{ site_url('docs/api/streaming') }}#options">Streaming lib options</a>.
|
2010-08-16 01:55:25 +00:00
|
|
|
See those references for option names and defaults.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
BASE 64 Notes
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Base 64 encoding must use the I2P standard Base 64 alphabet "A-Z, a-z, 0-9, -, ~".
|
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Client library implementations:
|
|
|
|
----------------------------------------------------------------------
|
2010-08-16 01:55:25 +00:00
|
|
|
Client libraries are available for C, C++, C#, Perl, and Python.
|
2013-02-06 01:55:33 +00:00
|
|
|
These are in the apps/sam/ directory in the <a href="{{ get_url('downloads_list') }}">I2P Source Package</a>.
|
2010-08-16 01:55:25 +00:00
|
|
|
Some may be older and have not been updated for SAMv3 support.
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Default SAM Setup
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
The default SAM port is 7656. SAM is not enabled by default in the I2P Router;
|
|
|
|
it must be started manually, or configured to start automatically,
|
|
|
|
on the configure clients page in the router console, or in the clients.config file.
|
|
|
|
The default SAM UDP port is 7655, listening on 0.0.0.0.
|
|
|
|
These may be changed by adding the arguments sam.udp.port=nnnnn and/or
|
|
|
|
sam.udp.host=w.x.y.z to the invocation.
|
|
|
|
|
2009-05-06 19:46:57 +00:00
|
|
|
</pre>
|
|
|
|
{% endblock %}
|