java.lang.Object
net.i2p.sam.SAMMessageSession
net.i2p.sam.SAMRawSession
net.i2p.sam.SAMv3RawSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess, SAMRawReceiver, Session
SAM v3 raw session implementation.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanTrue to prefix replies with the destination's key.private 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 SAMRawSession
RAW_SIZE_MAX, recvModifier 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
ConstructorsConstructorDescriptionSAMv3RawSession(String nick, Properties props, SAMv3Handler handler, I2PSession isess, int listenProtocol, int listenPort, SAMv3DatagramServer dgServer) Build a Raw Session on an existing i2p session registered with the given nicknameSAMv3RawSession(String nick, SAMv3DatagramServer dgServer) Build a Raw Datagram Session according to information 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.(package private) static SocketAddressgetSocketAddress(Properties props, SAMv3Handler handler) Get the socket address from session properties.voidreceiveRawBytes(byte[] data, int proto, int fromPort, int toPort) Receive raw data from I2P and forward to the SAM client.voidStop receiving raw data.Methods inherited from class SAMRawSession
messageReceived, sendBytes, sendBytes, shutDownModifier 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
nick
Name the client gave this session.handler
The handler that created this session.server
The UDP server the session is registered with.clientAddress
Where the client's datagrams come from._sendHeader
private final boolean _sendHeaderTrue to prefix replies with the destination's key.
Constructor Details
SAMv3RawSession
public SAMv3RawSession(String nick, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException Build a Raw Datagram Session according to information registered with the given nicknameCaller MUST call start().
- Parameters:
nick- nickname of the sessiondgServer- the datagram server this session reports its senders to- Throws:
IOException- if the nickname is not registered; the lookup throws InterruptedIOExceptionDataFormatException- declared on the superclass constructor, but not raised by the bodyI2PSessionException- if the I2P session cannot be created from the recorded destination
SAMv3RawSession
public SAMv3RawSession(String nick, Properties props, SAMv3Handler handler, I2PSession isess, int listenProtocol, int listenPort, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException Build a Raw Session on an existing i2p session registered with the given nicknameCaller MUST call start().
- Parameters:
nick- nickname of the sessionprops- the session properties, read for PORT and HOSThandler- the SAM handler owning the session recordisess- the already-running I2P session to wrap, not owned herelistenProtocol- the I2CP protocol to bind, or I2PSession.PROTO_ANY for alllistenPort- the local port to bind, or I2PSession.PORT_ANY to let the router choosedgServer- the datagram server this session reports its senders to- Throws:
IOException- declared on this constructor, but not raised by the bodyDataFormatException- likewise declared, but not raised by the bodyI2PSessionException- if the shared session cannot be attached to
Method Details
getNick
getRec
Look up the registered session record for the given nickname, throwing if it has already disappeared.- Parameters:
nick- the registered session nickname to look up- Returns:
- the registered session record
- Throws:
InterruptedIOException- if the nickname is not registered
getSocketAddress
Get the socket address from session properties.- Parameters:
props- the session properties containing PORT and optionally HOSThandler- the SAM handler for client IP fallback- Returns:
- the socket address, or null if PORT is not set
receiveRawBytes
Receive raw data from I2P and forward to the SAM client.- Specified by:
receiveRawBytesin interfaceSAMRawReceiver- Parameters:
data- the raw data payloadproto- the I2CP protocolfromPort- the I2CP from porttoPort- the I2CP to port- Throws:
IOException- if forwarding to the client fails
stopRawReceiving
public void stopRawReceiving()Stop receiving raw data.- Specified by:
stopRawReceivingin interfaceSAMRawReceiver