java.lang.Object
net.i2p.sam.SAMMessageSession
net.i2p.sam.SAMDatagramSession
net.i2p.sam.SAMv3DatagramSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMDatagramReceiver, SAMMessageSess, Session
SAM v3 datagram session implementation.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SocketAddressWhere the client's datagrams come from.private final SAMv3HandlerThe handler that created this session.private final StringName the client gave this session.private final SAMv3DatagramServerThe UDP server the session is registered with.Fields inherited from class SAMDatagramSession
DGRAM_SIZE_MAX, recvModifier and TypeFieldDescriptionstatic final intLargest datagram payload accepted in either direction, in bytes.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
ConstructorsConstructorDescriptionSAMv3DatagramSession(String nick, Properties props, SAMv3Handler handler, I2PSession isess, int listenProtocol, int listenPort, SAMv3DatagramServer dgServer) Build a Datagram Session on an existing i2p session registered with the given nicknameSAMv3DatagramSession(String nick, SAMv3DatagramServer dgServer) Build a DatagramSession according to informations registered with the given nicknameMethod Summary
Modifier and TypeMethodDescriptiongetNick()Get the session nickname.private static SessionRecordLook up the registered session record for the given nickname, throwing if it has already disappeared.voidreceiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) Receive a datagram from I2P and forward to the SAM client.voidStop receiving datagrams.Methods inherited from class SAMDatagramSession
messageReceived, sendBytes, sendBytes, shutDownModifier 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
handler
The handler that created this session.server
The UDP server the session is registered with.nick
Name the client gave this session.clientAddress
Where the client's datagrams come from.
Constructor Details
SAMv3DatagramSession
public SAMv3DatagramSession(String nick, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException, SAMException Build a DatagramSession according to informations registered with the given nicknameCaller MUST call start().
- Parameters:
nick- nickname of the sessiondgServer- the datagram server that dispatches datagrams to this session- Throws:
IOException- declared on this constructor, but not raised by the bodyDataFormatException- likewise declared, but not raised by the bodyI2PSessionException- if the session registered under nick cannot be rebuilt from the record's destinationSAMException- if the nickname is no longer registered
SAMv3DatagramSession
public SAMv3DatagramSession(String nick, Properties props, SAMv3Handler handler, I2PSession isess, int listenProtocol, int listenPort, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException Build a Datagram Session on an existing i2p session registered with the given nicknameCaller MUST call start().
- Parameters:
nick- nickname of the sessionprops- session properties read from the SESSION CREATE commandhandler- handler used to send DATAGRAM replies back to the clientisess- the existing I2P session this datagram session runs overlistenProtocol- datagram protocol number to listen for, 0 for anylistenPort- local port to listen on, 0 for anydgServer- the datagram server that dispatches datagrams to this session- Throws:
IOException- declared on this constructor, but not raised by the bodyDataFormatException- likewise declared, but not raised by the bodyI2PSessionException- declared on this constructor, but not raised by the body
Method Details
getNick
getRec
Look up the registered session record for the given nickname, throwing if it has already disappeared.- Parameters:
nick- the nickname the session was registered under- Returns:
- the registered session record, never null because a missing one is thrown rather than returned
- Throws:
SAMException- if the nickname is not registered
receiveDatagramBytes
public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException Receive a datagram from I2P and forward to the SAM client.- Specified by:
receiveDatagramBytesin interfaceSAMDatagramReceiver- Parameters:
sender- the destination that sent the datagramdata- the datagram payloadproto- the I2CP protocolfromPort- the I2CP from porttoPort- the I2CP to port- Throws:
IOException- if forwarding to the client fails
stopDatagramReceiving
public void stopDatagramReceiving()Stop receiving datagrams.- Specified by:
stopDatagramReceivingin interfaceSAMDatagramReceiver