java.lang.Object
net.i2p.sam.SAMStreamSession
net.i2p.sam.SAMv2StreamSession
- All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
SAMv2 STREAM session class.
Nested Class Summary
Modifier and TypeClassDescriptionclassSAM STREAM socket reader, running in its own thread.private classSAM STREAM socket connecter, running in its own thread.private classThread sending the v2 stream data.Nested classes/interfaces inherited from class SAMStreamSession
SAMStreamSession.DisconnectListener, SAMStreamSession.SAMStreamSessionServer, SAMStreamSession.SAMStreamSessionSocketReader, SAMStreamSession.SAMv1StreamSessionSocketReader, SAMStreamSession.StreamSenderModifier and TypeClassDescriptionprotected classCloses SAM session when the underlying I2P manager disconnects.classSAM STREAM session server, running in its own thread.static classReads bytes off one tunnel socket and pushes them to the SAM client.classSAMv1StreamSessionSocketReader.protected static classLets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer).Field Summary
Fields inherited from class SAMStreamSession
_isOwnSession, _log, canCreate, DEFAULT_FORCE_FLUSH, forceFlush, PROP_FORCE_FLUSH, recv, server, SOCKET_HANDLER_BUF_SIZE, socketMgrModifier and TypeFieldDescriptionprotected final booleanWhether this is our own session, as opposed to a remote peer's.protected final LogLogger for this session's messages.protected final booleanWhether this session may create outgoing connections.static final StringDefault forSAMStreamSession.PROP_FORCE_FLUSH.protected final booleanShould we flush every time we get a STREAM SEND, or leave that up to the streaming lib to decide?static final StringConfig key for flushing on every STREAM SEND.protected final SAMStreamReceiverThe receiver that decodes incoming SAM messages.protected final SAMStreamSession.SAMStreamSessionServerThe server this session belongs to.protected static final intRead buffer size for each socket reader.protected final I2PSocketManagerThe socket manager used for outgoing connections.Constructor Summary
ConstructorsConstructorDescriptionSAMv2StreamSession(InputStream destStream, String dir, Properties props, SAMStreamReceiver recv) Create a new SAM STREAM session.SAMv2StreamSession(String dest, String dir, Properties props, SAMStreamReceiver recv) Create a new SAM STREAM session.Method Summary
Public MethodsModifier and TypeMethodDescriptionbooleanconnect(int id, String dest, Properties props) Connect the SAM STREAM session to the specified Destination.newSAMStreamSessionSocketReader(I2PSocket s, int id) Creates the version 2 socket reader for this session.protected SAMStreamSession.StreamSendernewStreamSender(I2PSocket s, int id) Lets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer).booleansetReceiveLimit(int id, long limit, boolean nolimit) Set a receive limit on a stream.Methods inherited from class SAMStreamSession
checkSocketHandlerId, close, closeConnection, createSocketHandler, getDestination, getListenPort, getListenProtocol, getSocketReader, isDestroyed, lookupDest, removeSocketHandler, sendBytes, sendBytes, sendBytes, startModifier and TypeMethodDescriptionprotected booleancheckSocketHandlerId(int id) Check whether a SAM STREAM session socket handler id is still in use.voidclose()Close a SAM STREAM session.booleancloseConnection(int id) Close a connection managed by the SAM STREAM session.protected intcreateSocketHandler(I2PSocket s, int id) Create a new SAM STREAM session socket handler, detaching its thread.Get the SAM STREAM session Destination.intGet the port for this session's listener.intGet the I2CP protocol for this session's listener.getSocketReader(int id) Get a SAM STREAM session socket handler.booleanIs the underlying streaming socket manager destroyed?lookupDest(String name) Lookup a destination through the I2CP session.protected voidremoveSocketHandler(int id) Remove and gracefully close a SAM STREAM session socket handler.booleansendBytes(int id, InputStream in, int size) Send bytes through a SAM STREAM session.booleanSending bytes is not supported in a STREAM or MASTER session; always throws.booleansendBytes(String s, byte[] b, int pr, int fp, int tp, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) Sending bytes is not supported in a STREAM or MASTER session; always throws.voidstart()Start the SAM STREAM session server, if applicable.
Constructor Details
SAMv2StreamSession
public SAMv2StreamSession(String dest, String dir, Properties props, SAMStreamReceiver recv) throws IOException, DataFormatException, SAMException Create a new SAM STREAM session.Caller MUST call start().
- Parameters:
dest- Base64-encoded destination and private keys (same format as PrivateKeyFile)dir- Session direction ("RECEIVE", "CREATE" or "BOTH")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 bodySAMException- if dir names no known direction, ifi2cp.tcp.portis not a number, or if the I2P session cannot be created
SAMv2StreamSession
public SAMv2StreamSession(InputStream destStream, String dir, Properties props, SAMStreamReceiver recv) throws IOException, DataFormatException, SAMException Create a new SAM STREAM session.Caller MUST call start().
- Parameters:
destStream- Input stream containing the destination and private keys (same format as PrivateKeyFile)dir- Session direction ("RECEIVE", "CREATE" or "BOTH")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 bodySAMException- if dir names no known direction, ifi2cp.tcp.portis not a number, or if the I2P session cannot be created
Method Details
connect
public boolean connect(int id, String dest, Properties props) throws DataFormatException, SAMInvalidDirectionException Connect the SAM STREAM session to the specified Destination.- Overrides:
connectin classSAMStreamSession- Parameters:
id- Unique id for the connectiondest- Base64-encoded Destination to connect toprops- Options to be used for connection- Returns:
- true if the communication with the SAM client is ok
- Throws:
DataFormatException- if the destination is not validSAMInvalidDirectionException- if trying to connect through a receive-only session
newStreamSender
Lets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer).- Overrides:
newStreamSenderin classSAMStreamSession- Parameters:
s- I2PSocketid- the caller's own socket id, passed through to the sender- Returns:
- v2StreamSender
- Throws:
IOException- if the socket's output stream cannot be obtained
newSAMStreamSessionSocketReader
protected SAMStreamSession.SAMStreamSessionSocketReader newSAMStreamSessionSocketReader(I2PSocket s, int id) throws IOException Creates the version 2 socket reader for this session.- Overrides:
newSAMStreamSessionSocketReaderin classSAMStreamSession- Parameters:
s- Socket to be handledid- Unique id assigned to the handler- Returns:
- the socket reader
- Throws:
IOException- if the socket reader cannot be created
setReceiveLimit
public boolean setReceiveLimit(int id, long limit, boolean nolimit) Set a receive limit on a stream.- Overrides:
setReceiveLimitin classSAMStreamSession- Parameters:
id- the SAM stream id whose reader gets the limitlimit- the receive limit in bytesnolimit- true for unlimited- Returns:
- true if the limit was set, false if the reader was not found