Package net.i2p.sam
Class SAMStreamSession
java.lang.Object
net.i2p.sam.SAMStreamSession
- All Implemented Interfaces:
Closeable,AutoCloseable,SAMMessageSess
- Direct Known Subclasses:
SAMv2StreamSession,SAMv3StreamSession
SAM STREAM session class.
- Author:
- human
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classclassSAM STREAM session server, running in its own thread.classSAM STREAM socket reader, running in its own thread.classprotected static classLets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer) -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final Logprotected final booleanstatic final Stringprotected final booleanshould we flush every time we get a STREAM SEND, or leave that up to the streaming lib to decide?static final Stringprotected final SAMStreamReceiverprotected final SAMStreamSession.SAMStreamSessionServerprotected static final intprotected final I2PSocketManager -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSAMStreamSession(InputStream destStream, String dir, Properties props, SAMStreamReceiver recv) Create a new SAM STREAM session.SAMStreamSession(String dest, String dir, Properties props, SAMStreamReceiver recv) Create a new SAM STREAM session.protectedSAMStreamSession(I2PSocketManager mgr, Properties props, SAMStreamReceiver recv, int listenport) Create a new SAM STREAM session on an existing socket manager. -
Method Summary
Modifier 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.booleanconnect(int id, String dest, Properties props) Connect the SAM STREAM session to the specified Destinationprotected intcreateSocketHandler(I2PSocket s, int id) Create a new SAM STREAM session socket handler, detaching its thread.Get the SAM STREAM session Destination.intintgetSocketReader(int id) Get a SAM STREAM session socket handler.booleanIs the underlying streaming socket manager destroyed?newSAMStreamSessionSocketReader(I2PSocket s, int id) protected SAMStreamSession.StreamSendernewStreamSender(I2PSocket s, int id) 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.booleanUnsupportedbooleansendBytes(String s, byte[] b, int pr, int fp, int tp, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) Unsupported(package private) booleansetReceiveLimit(int id, long limit, boolean nolimit) voidstart()Start a SAM message-based session.
-
Field Details
-
_log
-
SOCKET_HANDLER_BUF_SIZE
protected static final int SOCKET_HANDLER_BUF_SIZE- See Also:
-
recv
-
server
-
socketMgr
-
canCreate
protected final boolean canCreate -
_isOwnSession
protected final boolean _isOwnSession -
forceFlush
protected final boolean forceFlushshould we flush every time we get a STREAM SEND, or leave that up to the streaming lib to decide? -
PROP_FORCE_FLUSH
- See Also:
-
DEFAULT_FORCE_FLUSH
- See Also:
-
-
Constructor Details
-
SAMStreamSession
public SAMStreamSession(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, and optional offline signature section (same format as PrivateKeyFile)dir- Session direction ("RECEIVE", "CREATE" or "BOTH") or "__v3__" if extended by SAMv3StreamSessionprops- Properties to setup the I2P sessionrecv- Object that will receive incoming data- Throws:
IOExceptionDataFormatExceptionSAMException
-
SAMStreamSession
protected SAMStreamSession(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 binary destination and private keys, and optional offline signature section (same format as PrivateKeyFile)dir- Session direction ("RECEIVE", "CREATE" or "BOTH") or "__v3__" if extended by SAMv3StreamSessionprops- Properties to setup the I2P sessionrecv- Object that will receive incoming data- Throws:
IOExceptionDataFormatExceptionSAMException
-
SAMStreamSession
protected SAMStreamSession(I2PSocketManager mgr, Properties props, SAMStreamReceiver recv, int listenport) throws IOException, DataFormatException, SAMException Create a new SAM STREAM session on an existing socket manager. v3 only.- Parameters:
props- Properties to setup the I2P sessionrecv- Object that will receive incoming data- Throws:
IOExceptionDataFormatExceptionSAMException- Since:
- 0.9.25
-
-
Method Details
-
start
public void start()Description copied from interface:SAMMessageSessStart a SAM message-based session. MUST be called after constructor.- Specified by:
startin interfaceSAMMessageSess
-
getListenProtocol
public int getListenProtocol()- Specified by:
getListenProtocolin interfaceSAMMessageSess
-
getListenPort
public int getListenPort()- Specified by:
getListenPortin interfaceSAMMessageSess
-
getDestination
Get the SAM STREAM session Destination.- Specified by:
getDestinationin interfaceSAMMessageSess- Returns:
- The SAM STREAM session Destination.
-
connect
public boolean connect(int id, String dest, Properties props) throws I2PException, ConnectException, NoRouteToHostException, DataFormatException, InterruptedIOException, SAMInvalidDirectionException, IOException Connect the SAM STREAM session to the specified Destination- Parameters:
id- Unique id for the connectiondest- Base64-encoded Destination to connect toprops- Options to be used for connection- Returns:
- true if successful
- Throws:
DataFormatException- if the destination is not validSAMInvalidDirectionException- if trying to connect through a receive-only sessionConnectException- if the destination refuses connectionsNoRouteToHostException- if the destination can't be reachedInterruptedIOException- if the connection timeoutsI2PException- if there's another I2P-related errorIOException
-
sendBytes
Send bytes through a SAM STREAM session.- Parameters:
id- Stream Idin- Datastream inputsize- Count of bytes to send- Returns:
- True if the data was queued for sending, false otherwise
- Throws:
IOException
-
close
public void close()Close a SAM STREAM session.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSAMMessageSess
-
isDestroyed
public boolean isDestroyed()Is the underlying streaming socket manager destroyed?- Since:
- 0.9.61
-
closeConnection
public boolean closeConnection(int id) Close a connection managed by the SAM STREAM session.- Parameters:
id- Connection id- Returns:
- true on success
-
sendBytes
Unsupported- Specified by:
sendBytesin interfaceSAMMessageSess- Parameters:
s- Destinationb- Bytes to be sent- Returns:
- True if the data was sent, false otherwise
- Throws:
I2PSessionException- always- Since:
- 0.9.25 moved from subclass SAMv3StreamSession to implement SAMMessageSess
-
sendBytes
public boolean sendBytes(String s, byte[] b, int pr, int fp, int tp, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) throws I2PSessionException Unsupported- Specified by:
sendBytesin interfaceSAMMessageSess- Throws:
I2PSessionException- always- Since:
- 0.9.25
-
createSocketHandler
Create a new SAM STREAM session socket handler, detaching its thread.- Parameters:
s- Socket to be handledid- Socket id, or 0 if it must be auto-generated- Returns:
- An id associated to the socket handler
-
getSocketReader
Get a SAM STREAM session socket handler.- Parameters:
id- Handler id- Returns:
- SAM StreamSender handler
-
checkSocketHandlerId
protected boolean checkSocketHandlerId(int id) Check whether a SAM STREAM session socket handler id is still in use.- Parameters:
id- Handler id- Returns:
- True if in use
-
removeSocketHandler
protected void removeSocketHandler(int id) Remove and gracefully close a SAM STREAM session socket handler.- Parameters:
id- Handler id to be removed
-
setReceiveLimit
boolean setReceiveLimit(int id, long limit, boolean nolimit) -
newSAMStreamSessionSocketReader
protected SAMStreamSession.SAMStreamSessionSocketReader newSAMStreamSessionSocketReader(I2PSocket s, int id) throws IOException - Throws:
IOException
-
newStreamSender
- Throws:
IOException
-