java.lang.Object
net.i2p.sam.SAMMessageSession
net.i2p.sam.SAMDatagramSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
- Direct Known Subclasses:
SAMv3DatagramSession
SAM DATAGRAM session class.
Field Summary
Modifier and TypeFieldDescriptionstatic final intLargest datagram payload accepted in either direction, in bytes.private final I2PDatagramDissectorDissects the datagrams this session receivesprivate final I2PDatagramMakerMakes the datagrams this session sends.protected SAMDatagramReceiverReceiver this session hands assembled incoming datagrams to.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
ConstructorsModifierConstructorDescriptionSAMDatagramSession(InputStream destStream, Properties props, SAMDatagramReceiver recv) Create a new SAM DATAGRAM session.protectedSAMDatagramSession(String dest, Properties props, SAMDatagramReceiver recv) Create a new SAM DATAGRAM session.protectedSAMDatagramSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMDatagramReceiver recv) Create a new SAM DATAGRAM session on an existing I2P session.Method Summary
Public MethodsModifier and TypeMethodDescriptionprotected voidmessageReceived(byte[] msg, int proto, int fromPort, int toPort) Handle a received datagram message from I2P.booleanSend bytes through a SAM DATAGRAM 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 DATAGRAM session.protected voidshutDown()Shut down the datagram 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
DGRAM_SIZE_MAX
public static final int DGRAM_SIZE_MAXLargest datagram payload accepted in either direction, in bytes.- See Also:
recv
Receiver this session hands assembled incoming datagrams to.dgramMaker
Makes the datagrams this session sends.dgramDissector
Dissects the datagrams this session receives
Constructor Details
SAMDatagramSession
protected SAMDatagramSession(String dest, Properties props, SAMDatagramReceiver recv) throws IOException, DataFormatException, I2PSessionException Create a new SAM DATAGRAM session.- Parameters:
dest- Base64-encoded destination (private key)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
SAMDatagramSession
public SAMDatagramSession(InputStream destStream, Properties props, SAMDatagramReceiver recv) throws I2PSessionException Create a new SAM DATAGRAM session.Caller MUST call start().
- Parameters:
destStream- Input stream containing the destination keysprops- 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
SAMDatagramSession
protected SAMDatagramSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMDatagramReceiver recv) throws I2PSessionException Create a new SAM DATAGRAM session on an existing I2P session.- Parameters:
sess- the already-established I2P session to run over, which this session does not ownprops- unused for nowlistenProtocol- the tunnel protocol for the datagram tunnel, normally PROTO_DATAGRAMlistenPort- the local port the datagram tunnel is published fromrecv- the object handed each datagram that arrives on the session- Throws:
I2PSessionException- not raised here, since the body only wires up the session
Method Details
sendBytes
public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException Send bytes through a SAM DATAGRAM session.- Specified by:
sendBytesin interfaceSAMMessageSess- Specified by:
sendBytesin classSAMMessageSession- Parameters:
dest- the .b32.i2p address to send todata- Bytes to be sentproto- ignored, will always use PROTO_DATAGRAM (17)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 DATAGRAM 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 datagram message from I2P.- Specified by:
messageReceivedin classSAMMessageSession- Parameters:
msg- the raw I2P datagram messageproto- the I2CP protocolfromPort- the I2CP from porttoPort- the I2CP to port
shutDown
protected void shutDown()Shut down the datagram session.- Specified by:
shutDownin classSAMMessageSession