java.lang.Object
net.i2p.sam.SAMMessageSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
- Direct Known Subclasses:
SAMDatagramSession, SAMRawSession
Base abstract class for SAM message-based sessions.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classSAM message-based session handler, running in its own thread.Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanTrue for a session we opened, false for a remote peer's.protected final LogLogger for this session's messages.private final SAMMessageSession.SAMMessageSessionHandlerThe handler processing the messages.private final intThe port listened on.private final intThe protocol listened for.private final I2PSessionThe I2P session of this SAM session.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSAMMessageSession(InputStream destStream, Properties props) Initialize a new SAM message-based session.protectedSAMMessageSession(String dest, Properties props) Initialize a new SAM message-based session.protectedSAMMessageSession(I2PSession sess, int listenProtocol, int listenPort) Initialize a new SAM message-based session using an existing I2PSession.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close a SAM message-based session.Get the SAM message-based session Destination.protected I2PSessionGet the I2PSession object used by the SAM message-based session.intPort to listen on.intProtocol family to listen for.lookupDest(String name) Lookup a destination through the I2CP session.(package private) static DestinationlookupDest(I2PSession session, String name) Lookup a destination through the I2CP session.protected abstract voidmessageReceived(byte[] msg, int proto, int fromPort, int toPort) Handle a new received message.abstract booleanSend bytes through a SAM message-based session.protected booleansendBytesThroughMessageSession(String dest, byte[] data, int proto, int fromPort, int toPort) Actually send bytes through the SAM message-based session I2PSession (er...).protected booleansendBytesThroughMessageSession(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) Actually send bytes through the SAM message-based session I2PSession, using per-message extended options.protected abstract voidshutDown()Do whatever is needed to shutdown the SAM session.voidstart()Start the SAM message session handler.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SAMMessageSess
sendBytes
Field Details
_log
Logger for this session's messages.session
The I2P session of this SAM session._isOwnSession
protected final boolean _isOwnSessionTrue for a session we opened, false for a remote peer's.handler
The handler processing the messages.listenProtocol
private final int listenProtocolThe protocol listened for.listenPort
private final int listenPortThe port listened on.
Constructor Details
SAMMessageSession
Initialize a new SAM message-based session.- Parameters:
dest- Base64-encoded destination and private keys, and optional offline signature section (same format as PrivateKeyFile)props- Properties to setup the I2P session- Throws:
I2PSessionException- if the session cannot be created
SAMMessageSession
Initialize a new SAM message-based session.- Parameters:
destStream- Input stream containing the binary destination and private keys, and optional offline signature section (same format as PrivateKeyFile)props- Properties to setup the I2P session- Throws:
I2PSessionException- if the session cannot be created
SAMMessageSession
Initialize a new SAM message-based session using an existing I2PSession.- Parameters:
sess- the already-established I2P session to attach to, not owned by this wrapperlistenProtocol- the I2CP protocol to bind, or I2PSession.PROTO_ANY for alllistenPort- the local port to bind, or I2PSession.PORT_ANY to let the router choose
Method Details
start
public void start()Start the SAM message session handler.- Specified by:
startin interfaceSAMMessageSess
getDestination
Get the SAM message-based session Destination.- Specified by:
getDestinationin interfaceSAMMessageSess- Returns:
- The SAM message-based session Destination.
getListenProtocol
public int getListenProtocol()Protocol family to listen for.- Specified by:
getListenProtocolin interfaceSAMMessageSess- Returns:
- the listen protocol
getListenPort
public int getListenPort()Port to listen on.- Specified by:
getListenPortin interfaceSAMMessageSess- Returns:
- the listen port
sendBytes
public abstract boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException Send bytes through a SAM message-based session.- Specified by:
sendBytesin interfaceSAMMessageSess- Parameters:
dest- destination to send to, as base64, a .b32.i2p name or a hostnamedata- Bytes to be sentproto- the I2CP protocol to send underfromPort- the I2CP from port, 0 for the defaulttoPort- the I2CP to port, 0 for the default- Returns:
- True if the data was sent, false otherwise
- Throws:
DataFormatException- on unknown / bad destI2PSessionException- on serious error, probably session closed
sendBytesThroughMessageSession
protected boolean sendBytesThroughMessageSession(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException Actually send bytes through the SAM message-based session I2PSession (er...).- Parameters:
dest- destination to send to, as base64, a .b32.i2p name or a hostnamedata- Bytes to be sentproto- I2CP protocolfromPort- I2CP from porttoPort- I2CP to port- Returns:
- True if the data was sent, false otherwise
- Throws:
DataFormatException- on unknown / bad destI2PSessionException- on serious error, probably session closed
sendBytesThroughMessageSession
protected boolean sendBytesThroughMessageSession(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) throws DataFormatException, I2PSessionException Actually send bytes through the SAM message-based session I2PSession, using per-message extended options. For efficiency, use the method without all the extra options if they are all defaults.- Parameters:
dest- destination to send to, as base64, a .b32.i2p name or a hostnamedata- Bytes to be sentproto- I2CP protocolfromPort- I2CP from porttoPort- I2CP to portsendLeaseSet- true is the usual setting and the I2CP defaultsendTags- 0 to leave as defaulttagThreshold- 0 to leave as defaultexpiration- SECONDS from now, NOT absolute time, 0 to leave as default- Returns:
- True if the data was sent, false otherwise
- Throws:
DataFormatException- on unknown / bad destI2PSessionException- on serious error, probably session closed
lookupDest
Lookup a destination through the I2CP session. Blocking.- Specified by:
lookupDestin interfaceSAMMessageSess- Parameters:
name- the base32 hostname, or full destination, to resolve- Returns:
- the Destination or null
- Throws:
I2PSessionException- if the lookup does not complete within the 10 second session timeout
lookupDest
Lookup a destination through the I2CP session. Blocking.- Parameters:
session- the I2P session whose tunnel pool performs the lookupname- the base32 hostname, or full destination, to resolve- Returns:
- the Destination or null
- Throws:
I2PSessionException- if the lookup does not complete within the 10 second session timeout
close
public void close()Close a SAM message-based session.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSAMMessageSess
messageReceived
protected abstract void messageReceived(byte[] msg, int proto, int fromPort, int toPort) Handle a new received message.- Parameters:
msg- the received datagram payload, passed on to the handlerproto- I2CP protocolfromPort- I2CP from porttoPort- I2CP to port
shutDown
protected abstract void shutDown()Do whatever is needed to shutdown the SAM session.getI2PSession
Get the I2PSession object used by the SAM message-based session.- Returns:
- The I2PSession of the SAM message-based session