java.lang.Object
net.i2p.sam.SAMMessageSession
net.i2p.sam.SAMRawSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
- Direct Known Subclasses:
SAMv3RawSession
SAM RAW session class.
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLargest datagram this session will send, in bytes; larger is rejected.protected SAMRawReceiverReceiver handed the raw bytes arriving from the tunnel.Fields inherited from class SAMMessageSession
_isOwnSession, _logModifier and TypeFieldDescriptionprotected final booleanTrue for a session we opened, false for a remote peer's.protected final LogLogger for this session's messages.Constructor Summary
ConstructorsModifierConstructorDescriptionSAMRawSession(InputStream destStream, Properties props, SAMRawReceiver recv) Create a new SAM RAW session.protectedSAMRawSession(String dest, Properties props, SAMRawReceiver recv) Create a new SAM RAW session.protectedSAMRawSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMRawReceiver recv) Create a new SAM RAW session on an existing I2P session.Method Summary
Public MethodsModifier and TypeMethodDescriptionprotected voidmessageReceived(byte[] msg, int proto, int fromPort, int toPort) Handle a received raw message from I2P.booleanSend bytes through a SAM RAW session.booleansendBytes(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) Send bytes through a SAM RAW session.protected voidshutDown()Shut down the raw session.Methods inherited from class SAMMessageSession
close, getDestination, getI2PSession, getListenPort, getListenProtocol, lookupDest, lookupDest, sendBytesThroughMessageSession, sendBytesThroughMessageSession, startModifier 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 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.voidstart()Start the SAM message session handler.
Field Details
RAW_SIZE_MAX
public static final int RAW_SIZE_MAXLargest datagram this session will send, in bytes; larger is rejected.- See Also:
recv
Receiver handed the raw bytes arriving from the tunnel.
Constructor Details
SAMRawSession
protected SAMRawSession(String dest, Properties props, SAMRawReceiver recv) throws IOException, DataFormatException, I2PSessionException Create a new SAM RAW session.- Parameters:
dest- Base64-encoded destination and private keys (same format as PrivateKeyFile)props- Properties to setup the I2P sessionrecv- Object that will receive incoming data- Throws:
IOException- declared on this constructor, but not raised by the bodyDataFormatException- likewise declared, but not raised by the bodyI2PSessionException- if the I2P session cannot be created from dest
SAMRawSession
public SAMRawSession(InputStream destStream, Properties props, SAMRawReceiver recv) throws I2PSessionException Create a new SAM RAW session.Caller MUST call start().
- Parameters:
destStream- Input stream containing the destination and private keys (same format as PrivateKeyFile)props- Properties to setup the I2P sessionrecv- Object that will receive incoming data- Throws:
I2PSessionException- if the I2P session cannot be created from the keys read out of destStream
SAMRawSession
protected SAMRawSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMRawReceiver recv) throws I2PSessionException Create a new SAM RAW session on an existing I2P session.- Parameters:
sess- the already established session to shareprops- unused for nowlistenProtocol- protocol number to accept datagrams for, 1-254 or PROTO_ANY (0)listenPort- port to accept datagrams on, 1-65535 or PORT_ANY (0)recv- Object that will receive incoming data- Throws:
I2PSessionException- if the shared session cannot be attached to
Method Details
sendBytes
public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException Send bytes through a SAM RAW session.- Specified by:
sendBytesin interfaceSAMMessageSess- Specified by:
sendBytesin classSAMMessageSession- Parameters:
dest- destination to send to, as base64, a .b32.i2p name or a hostnamedata- Bytes to be sentproto- if 0, will use PROTO_DATAGRAM_RAW (18)fromPort- 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
sendBytes
public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) throws DataFormatException, I2PSessionException Send bytes through a SAM RAW session.- Parameters:
dest- the base32 destination or .b32.i2p hostname to send todata- the bytes to sendproto- the I2CP protocol to send underfromPort- the I2CP from port, 0 for the defaulttoPort- the I2CP to port, 0 for the defaultsendLeaseSet- true to include the LeaseSet in the messagesendTags- the number of tunnels to include, 0 to leave as defaulttagThreshold- the build success ratio below which no tunnel is sent, 0 for defaultexpiration- the lease lifetime in seconds from now, 0 to leave as default- Returns:
- True if the data was sent, false otherwise
- Throws:
DataFormatException- if dest is not a valid destinationI2PSessionException- on serious error, probably session closed
messageReceived
protected void messageReceived(byte[] msg, int proto, int fromPort, int toPort) Handle a received raw message from I2P.- Specified by:
messageReceivedin classSAMMessageSession- Parameters:
msg- the raw I2P messageproto- the I2CP protocolfromPort- the I2CP from porttoPort- the I2CP to port
shutDown