Package net.i2p.sam
Class SAMMessageSession
- java.lang.Object
-
- net.i2p.sam.SAMMessageSession
-
- All Implemented Interfaces:
Closeable,AutoCloseable,SAMMessageSess
- Direct Known Subclasses:
SAMDatagramSession,SAMRawSession
abstract class SAMMessageSession extends Object implements SAMMessageSess
Base abstract class for SAM message-based sessions.- Author:
- human
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_isOwnSessionprotected Log_log
-
Constructor Summary
Constructors Modifier Constructor Description protectedSAMMessageSession(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Close a SAM message-based session.DestinationgetDestination()Get the SAM message-based session Destination.protected I2PSessiongetI2PSession()Get the I2PSession object used by the SAM message-based session.intgetListenPort()intgetListenProtocol()protected abstract voidmessageReceived(byte[] msg, int proto, int fromPort, int toPort)Handle a new received messageabstract booleansendBytes(String dest, byte[] data, int proto, int fromPort, int toPort)Send 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 sessionvoidstart()Start a SAM message-based session.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.i2p.sam.SAMMessageSess
sendBytes
-
-
-
-
Field Detail
-
_log
protected final Log _log
-
_isOwnSession
protected final boolean _isOwnSession
-
-
Constructor Detail
-
SAMMessageSession
protected SAMMessageSession(String dest, Properties props) throws IOException, DataFormatException, I2PSessionException
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:
IOExceptionDataFormatExceptionI2PSessionException
-
SAMMessageSession
protected SAMMessageSession(InputStream destStream, Properties props) throws IOException, DataFormatException, I2PSessionException
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:
IOExceptionDataFormatExceptionI2PSessionException
-
SAMMessageSession
protected SAMMessageSession(I2PSession sess, int listenProtocol, int listenPort) throws IOException, DataFormatException, I2PSessionException
Initialize a new SAM message-based session using an existing I2PSession.- Throws:
IOExceptionDataFormatExceptionI2PSessionException- Since:
- 0.9.25
-
-
Method Detail
-
start
public void start()
Description copied from interface:SAMMessageSessStart a SAM message-based session. MUST be called after constructor.- Specified by:
startin interfaceSAMMessageSess
-
getDestination
public Destination getDestination()
Get the SAM message-based session Destination.- Specified by:
getDestinationin interfaceSAMMessageSess- Returns:
- The SAM message-based session Destination.
-
getListenProtocol
public int getListenProtocol()
- Specified by:
getListenProtocolin interfaceSAMMessageSess- Since:
- 0.9.25
-
getListenPort
public int getListenPort()
- Specified by:
getListenPortin interfaceSAMMessageSess- Since:
- 0.9.25
-
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- Destinationdata- Bytes to be sent- 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- Destinationdata- 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- Destinationdata- 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- Since:
- 0.9.24
-
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- Message payload
-
shutDown
protected abstract void shutDown()
Do whatever is needed to shutdown the SAM session
-
getI2PSession
protected I2PSession getI2PSession()
Get the I2PSession object used by the SAM message-based session.- Returns:
- The I2PSession of the SAM message-based session
-
-