public interface I2PSessionDefine the standard means of sending and receiving messages on the
I2P network by using the I2CP (the client protocol). This is done over a
bidirectional TCP socket.
End to end encryption in I2PSession was disabled in release 0.6.
Periodically the router will ask the client to authorize a new set of
tunnels to be allocated to the client, which the client can accept by sending a
LeaseSet signed by the Destination.
In addition, the router may on occasion provide the client with an updated
clock offset so that the client can stay in sync with the network (even if
the host computer's clock is off).
| Modifier and Type | Interface and Description |
|---|---|
static class | I2PSession.TunnelPairSimple holder for tunnel pair information. |
| Modifier and Type | Field and Description |
|---|---|
static int | PORT_ANYAny port |
static int | PORT_UNSPECIFIEDUnspecified port |
static int | PROTO_ANYAny protocol |
static int | PROTO_DATAGRAMA repliable and signed datagram |
static int | PROTO_DATAGRAM_RAWA raw (unsigned, unrepliable) datagram |
static int | PROTO_DATAGRAM2A repliable and signed datagram. |
static int | PROTO_DATAGRAM3A repliable but unsigned datagram. |
static int | PROTO_STREAMINGStreaming protocol |
static int | PROTO_UNSPECIFIEDUnspecified protocol |
| Modifier and Type | Method and Description |
|---|---|
void | addMuxedSessionListener(I2PSessionMuxedListener l,
int proto,
int port)Listen on specified protocol and port, and receive notification
of proto, fromPort, and toPort for every message. |
void | addSessionListener(I2PSessionListener lsnr,
int proto,
int port)Listen on specified protocol and port. |
I2PSession | addSubsession(InputStream privateKeyStream,
Properties opts)Add a subsession. |
void | addTunnelStatusListener(TunnelStatusListener lsnr)Add a listener for tunnel status changes. |
int[] | bandwidthLimits()Get the current bandwidth limits. |
void | connect()Actually connect the session and start receiving/sending messages. |
void | destroySession()Tear down the session and release any resources. |
I2PSession.TunnelPair | getCurrentTunnelPair()Get the tunnel IDs currently in use by this session. |
PrivateKey | getDecryptionKey()Retrieve the decryption PrivateKey associated with the Destination. |
Destination | getMyDestination()Retrieve the Destination this session serves as the endpoint for. |
long | getOfflineExpiration()Get the offline expiration |
Signature | getOfflineSignature()Get the offline signature. |
SigningPrivateKey | getPrivateKey()Retrieve the signing SigningPrivateKey associated with the Destination. |
String | getRouterVersion()Always valid in RouterContext. |
List<I2PSession> | getSubsessions()Get the list of subsessions. |
SigningPublicKey | getTransientSigningPublicKey()Get the transient signing public key. |
boolean | isClosed()Have we closed the session? |
boolean | isOffline()Does this session have offline and transient keys? |
Destination | lookupDest(Hash h)Lookup a Destination by Hash. |
Destination | lookupDest(Hash h,
long maxWait)Lookup a Destination by Hash. |
LookupResult | lookupDest(Hash h,
long maxWait,
LookupCallback callback)Lookup a Destination by hash. |
Destination | lookupDest(String name)Ask the router to lookup a Destination by host name. |
Destination | lookupDest(String name,
long maxWait)Ask the router to lookup a Destination by host name. |
LookupResult | lookupDest(String name,
long maxWait,
LookupCallback callback)Lookup a Destination by hostname. |
LookupResult | lookupDest2(String name,
long maxWait)Ask the router to lookup a Destination by host name. |
void | rebuildTunnels()Force immediate tunnel rebuild. |
byte[] | receiveMessage(int msgId)Receive a message that the router has notified the client about, returning
the payload. |
void | removeListener(int proto,
int port)removes the specified listener (only) |
void | removeSubsession(I2PSession session)Remove a subsession. |
void | removeTunnelStatusListener(TunnelStatusListener lsnr)Remove a tunnel status listener. |
void | reportAbuse(int msgId,
int severity)Instruct the router that the message received was abusive (including how
abusive on a 1-100 scale) in the hopes the router can do something to
minimize receiving abusive messages like that in the future. |
void | sendBlindingInfo(BlindData bd)Send blinding info to the router. |
boolean | sendMessage(Destination dest,
byte[] payload)Send a new message to the given destination, containing the specified
payload, returning true if the router feels confident that the message
was delivered. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size)Send a new message to the given destination, containing the specified
payload, returning true if the router feels confident that the message
was delivered. |
boolean | sendMessage(Destination dest,
byte[] payload,
int proto,
int fromport,
int toport)See I2PSessionMuxedImpl for proto/port details. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
int proto,
int fromPort,
int toPort,
SendMessageOptions options)See I2PSessionMuxedImpl for proto/port details. |
long | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
int proto,
int fromPort,
int toPort,
SendMessageOptions options,
SendMessageStatusListener listener)Send a message and request an asynchronous notification of delivery status. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
SessionKey keyUsed,
Set<SessionTag> tagsSent)End-to-End Crypto is disabled, tags and keys are ignored. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
SessionKey keyUsed,
Set<SessionTag> tagsSent,
int proto,
int fromPort,
int toPort)See I2PSessionMuxedImpl for proto/port details. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
SessionKey keyUsed,
Set<SessionTag> tagsSent,
long expire)End-to-End Crypto is disabled, tags and keys are ignored. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
SessionKey keyUsed,
Set<SessionTag> tagsSent,
long expire,
int proto,
int fromPort,
int toPort)See I2PSessionMuxedImpl for proto/port details. |
boolean | sendMessage(Destination dest,
byte[] payload,
int offset,
int size,
SessionKey keyUsed,
Set<SessionTag> tagsSent,
long expire,
int proto,
int fromPort,
int toPort,
int flags)See I2PSessionMuxedImpl for proto/port details. |
boolean | sendMessage(Destination dest,
byte[] payload,
SessionKey keyUsed,
Set<SessionTag> tagsSent)End-to-End Crypto is disabled, tags and keys are ignored!
Like sendMessage above, except the key used and the tags sent are exposed to the
application. |
void | setCurrentTunnelPair(I2PSession.TunnelPair pair)Set the tunnel IDs actively in use by this session. |
void | setSessionListener(I2PSessionListener lsnr)Instruct the I2PSession where it should send event notifications
WARNING: It is recommended that you use a method that specifies the protocol and ports. |
boolean | switchToNewTunnel()Switch to a new tunnel for this session. |
void | updateOptions(Properties options)Pass updated options to the router. |
static final int PORT_ANY
static final int PORT_UNSPECIFIED
static final int PROTO_ANY
static final int PROTO_DATAGRAM
static final int PROTO_DATAGRAM_RAW
static final int PROTO_DATAGRAM2
static final int PROTO_DATAGRAM3
static final int PROTO_STREAMING
static final int PROTO_UNSPECIFIED
void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port)
l - the listener to addproto - 1-254 or PROTO_ANY (0) for all; 255 disallowedport - 1-65535 or PORT_ANY (0) for allvoid addSessionListener(I2PSessionListener lsnr, int proto, int port)
lsnr - the listener to addproto - 1-254 or PROTO_ANY (0) for all; recommended:
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedport - 1-65535 or PORT_ANY (0) for allI2PSession addSubsession(InputStream privateKeyStream, Properties opts) throws I2PSessionException
privateKeyStream - null for transient, if non-null must have same encryption keys as primary session
and different signing keysopts - subsession options if any, may be nullI2PSessionException - on errorvoid addTunnelStatusListener(TunnelStatusListener lsnr)
lsnr - the listener to addint[] bandwidthLimits()
throws I2PSessionExceptionI2PSessionException - on errorvoid connect()
throws I2PSessionExceptionI2PSessionException - on errorvoid destroySession()
throws I2PSessionExceptionI2PSessionException - on errorI2PSession.TunnelPair getCurrentTunnelPair()
PrivateKey getDecryptionKey()
Destination getMyDestination()
long getOfflineExpiration()
Signature getOfflineSignature()
SigningPrivateKey getPrivateKey()
String getRouterVersion()
List<I2PSession> getSubsessions()
SigningPublicKey getTransientSigningPublicKey()
boolean isClosed()
boolean isOffline()
Destination lookupDest(Hash h) throws I2PSessionException
h - the hash to look upI2PSessionException - on errorDestination lookupDest(Hash h, long maxWait) throws I2PSessionException
h - the hash to look upmaxWait - msI2PSessionException - on errorLookupResult lookupDest(Hash h, long maxWait, LookupCallback callback) throws I2PSessionException
h - the hash to look upmaxWait - mscallback - to return the result, non-nullI2PSessionException - on errorDestination lookupDest(String name) throws I2PSessionException
if (name.length() == 60 && name.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
if (session != null)
return session.lookup(Hash.create(Base32.decode(name.toLowerCase(Locale.US).substring(0, 52))));
else
return ctx.namingService().lookup(name); // simple session for xxx.b32.i2p handled by naming service (optional if you need lookup w/o an existing session)
} else if (ctx.isRouterContext()) {
return ctx.namingService().lookup(name); // hostname from router's naming service
} else {
Destination d = ctx.namingService().lookup(name); // local naming svc, optional
if (d != null)
return d;
if (session != null)
return session.lookup(name);
// simple session (optional if you need lookup w/o an existing session)
Destination rv = null;
I2PClient client = new I2PSimpleClient();
Properties opts = new Properties();
opts.put(I2PClient.PROP_TCP_HOST, host);
opts.put(I2PClient.PROP_TCP_PORT, port);
I2PSession session = null;
try {
session = client.createSession(null, opts);
session.connect();
rv = session.lookupDest(name);
} finally {
if (session != null)
session.destroySession();
}
return rv;
}
Requires router side to be 0.9.11 or higher. If the router is older,
this will return null immediately.name - the hostname to look upI2PSessionException - on errorDestination lookupDest(String name, long maxWait) throws I2PSessionException
name - the hostname to look upmaxWait - msI2PSessionException - on errorLookupResult lookupDest(String name, long maxWait, LookupCallback callback) throws I2PSessionException
name - the hostname to look upmaxWait - mscallback - to return the result, non-nullI2PSessionException - on errorLookupResult lookupDest2(String name, long maxWait) throws I2PSessionException
name - the hostname to look upmaxWait - msI2PSessionException - on errorvoid rebuildTunnels()
byte[] receiveMessage(int msgId)
throws I2PSessionExceptionmsgId - message to fetchI2PSessionException - on errorvoid removeListener(int proto,
int port)proto - protocol numberport - port numbervoid removeSubsession(I2PSession session)
session - the subsession to removevoid removeTunnelStatusListener(TunnelStatusListener lsnr)
lsnr - the listener to removevoid reportAbuse(int msgId,
int severity)
throws I2PSessionExceptionmsgId - message that was abusive (or -1 for not message related)severity - how abusiveI2PSessionException - on errorvoid sendBlindingInfo(BlindData bd) throws I2PSessionException
bd - the blind dataI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)I2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int proto, int fromport, int toport) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)proto - protocol numberfromport - source porttoport - destination portI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendproto - 1-254 or 0 for unset; recommended:
I2PSession.PROTO_UNSPECIFIED
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedfromPort - 1-65535 or 0 for unsettoPort - 1-65535 or 0 for unsetoptions - to be passed to the routerI2PSessionException - on errorlong sendMessage(Destination dest, byte[] payload, int offset, int size, int proto, int fromPort, int toPort, SendMessageOptions options, SendMessageStatusListener listener) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendproto - 1-254 or 0 for unset; recommended:
I2PSession.PROTO_UNSPECIFIED
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedfromPort - 1-65535 or 0 for unsettoPort - 1-65535 or 0 for unsetoptions - to be passed to the routerlistener - for delivery status notificationI2PSessionException - on all errorsboolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendkeyUsed - UNUSED, IGNORED.tagsSent - UNUSED, IGNORED.I2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, int proto, int fromPort, int toPort) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendkeyUsed - UNUSED, IGNORED.tagsSent - UNUSED, IGNORED.proto - 1-254 or 0 for unset; recommended:
I2PSession.PROTO_UNSPECIFIED
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedfromPort - 1-65535 or 0 for unsettoPort - 1-65535 or 0 for unsetI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendkeyUsed - UNUSED, IGNORED.tagsSent - UNUSED, IGNORED.expire - absolute expiration timestamp, NOT interval from nowI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromPort, int toPort) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendkeyUsed - UNUSED, IGNORED.tagsSent - UNUSED, IGNORED.expire - absolute expiration timestamp, NOT interval from nowproto - 1-254 or 0 for unset; recommended:
I2PSession.PROTO_UNSPECIFIED
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedfromPort - 1-65535 or 0 for unsettoPort - 1-65535 or 0 for unsetI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set<SessionTag> tagsSent, long expire, int proto, int fromPort, int toPort, int flags) throws I2PSessionException
dest - location to send the messagepayload - body of the message to be sent (unencrypted)offset - offset into the payloadsize - number of bytes to sendkeyUsed - UNUSED, IGNORED.tagsSent - UNUSED, IGNORED.expire - absolute expiration timestamp, NOT interval from nowproto - 1-254 or 0 for unset; recommended:
I2PSession.PROTO_UNSPECIFIED
I2PSession.PROTO_STREAMING
I2PSession.PROTO_DATAGRAM
255 disallowedfromPort - 1-65535 or 0 for unsettoPort - 1-65535 or 0 for unsetflags - message flagsI2PSessionException - on errorboolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set<SessionTag> tagsSent) throws I2PSessionException
If some application layer message delivery confirmation is used, rather than i2p's (slow) built in confirmation via guaranteed delivery mode, the application can update the SessionKeyManager, ala:
SessionKeyManager.getInstance().tagsDelivered(dest.getPublicKey(), keyUsed, tagsSent);If an application is using guaranteed delivery mode, this is not useful, but for applications using best effort delivery mode, if they can know with certainty that a message was delivered and can update the SessionKeyManager appropriately, a significant performance boost will occur (subsequent message encryption and decryption will be done via AES and a SessionTag, rather than ElGamal+AES, which is 1000x slower).
dest - location to send the messagepayload - body of the message to be sent (unencrypted)keyUsed - UNUSED, IGNORED. Session key delivered to the destination for association with the tags sent. This is essentially
an output parameter - keyUsed.getData() is ignored during this call, but after the call completes,
it will be filled with the bytes of the session key delivered. Typically the key delivered is the
same one as the key encrypted with, but not always. If this is null then the key data will not be
exposed.tagsSent - UNUSED, IGNORED. Set of tags delivered to the peer and associated with the keyUsed. This is also an output parameter -
the contents of the set is ignored during the call, but afterwards it contains a set of SessionTag
objects that were sent along side the given keyUsed.I2PSessionException - on errorvoid setCurrentTunnelPair(I2PSession.TunnelPair pair)
pair - the tunnel pair in usevoid setSessionListener(I2PSessionListener lsnr)
lsnr - listener to retrieve eventsboolean switchToNewTunnel()
void updateOptions(Properties options)
options - non-null