net.i2p.sam
Class SAMv2StreamSession

java.lang.Object
  extended by net.i2p.sam.SAMStreamSession
      extended by net.i2p.sam.SAMv2StreamSession

public class SAMv2StreamSession
extends SAMStreamSession

SAMv2 STREAM session class.

Author:
mkvore

Nested Class Summary
 class SAMv2StreamSession.SAMv2StreamSessionSocketReader
          SAM STREAM socket reader, running in its own thread.
 class SAMv2StreamSession.StreamConnector
          SAM STREAM socket connecter, running in its own thread.
protected  class SAMv2StreamSession.v2StreamSender
           
 
Nested classes/interfaces inherited from class net.i2p.sam.SAMStreamSession
SAMStreamSession.DisconnectListener, SAMStreamSession.SAMStreamSessionServer, SAMStreamSession.SAMStreamSessionSocketReader, SAMStreamSession.SAMv1StreamSessionSocketReader, SAMStreamSession.StreamSender, SAMStreamSession.v1StreamSender
 
Field Summary
 
Fields inherited from class net.i2p.sam.SAMStreamSession
canCreate, DEFAULT_FORCE_FLUSH, forceFlush, PROP_FORCE_FLUSH, recv, server, SOCKET_HANDLER_BUF_SIZE, socketMgr
 
Constructor Summary
SAMv2StreamSession(java.io.InputStream destStream, java.lang.String dir, java.util.Properties props, SAMStreamReceiver recv)
          Create a new SAM STREAM session.
SAMv2StreamSession(java.lang.String dest, java.lang.String dir, java.util.Properties props, SAMStreamReceiver recv)
          Create a new SAM STREAM session.
 
Method Summary
 boolean connect(int id, java.lang.String dest, java.util.Properties props)
          Connect the SAM STREAM session to the specified Destination
protected  SAMStreamSession.SAMStreamSessionSocketReader newSAMStreamSessionSocketReader(I2PSocket s, int id)
           
protected  SAMStreamSession.StreamSender newStreamSender(I2PSocket s, int id)
          Lets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer)
 boolean setReceiveLimit(int id, long limit, boolean nolimit)
          Send bytes through a SAM STREAM session.
 
Methods inherited from class net.i2p.sam.SAMStreamSession
checkSocketHandlerId, close, closeConnection, createSocketHandler, getDestination, getSocketReader, removeSocketHandler, sendBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAMv2StreamSession

public SAMv2StreamSession(java.lang.String dest,
                          java.lang.String dir,
                          java.util.Properties props,
                          SAMStreamReceiver recv)
                   throws java.io.IOException,
                          DataFormatException,
                          SAMException
Create a new SAM STREAM session.

Parameters:
dest - Base64-encoded destination (private key)
dir - Session direction ("RECEIVE", "CREATE" or "BOTH")
props - Properties to setup the I2P session
recv - Object that will receive incoming data
Throws:
java.io.IOException
DataFormatException
SAMException

SAMv2StreamSession

public SAMv2StreamSession(java.io.InputStream destStream,
                          java.lang.String dir,
                          java.util.Properties props,
                          SAMStreamReceiver recv)
                   throws java.io.IOException,
                          DataFormatException,
                          SAMException
Create a new SAM STREAM session.

Parameters:
destStream - Input stream containing the destination keys
dir - Session direction ("RECEIVE", "CREATE" or "BOTH")
props - Properties to setup the I2P session
recv - Object that will receive incoming data
Throws:
java.io.IOException
DataFormatException
SAMException
Method Detail

connect

public boolean connect(int id,
                       java.lang.String dest,
                       java.util.Properties props)
                throws DataFormatException,
                       SAMInvalidDirectionException
Connect the SAM STREAM session to the specified Destination

Overrides:
connect in class SAMStreamSession
Parameters:
id - Unique id for the connection
dest - Base64-encoded Destination to connect to
props - Options to be used for connection
Returns:
true if the communication with the SAM client is ok
Throws:
DataFormatException - if the destination is not valid
SAMInvalidDirectionException - if trying to connect through a receive-only session

newStreamSender

protected SAMStreamSession.StreamSender newStreamSender(I2PSocket s,
                                                        int id)
                                                 throws java.io.IOException
Lets us push data through the stream without blocking, (even after exceeding the I2PSocket's buffer)

Overrides:
newStreamSender in class SAMStreamSession
Parameters:
s - I2PSocket
id - Socket ID
Returns:
v2StreamSender
Throws:
java.io.IOException

newSAMStreamSessionSocketReader

protected SAMStreamSession.SAMStreamSessionSocketReader newSAMStreamSessionSocketReader(I2PSocket s,
                                                                                        int id)
                                                                                 throws java.io.IOException
Overrides:
newSAMStreamSessionSocketReader in class SAMStreamSession
Throws:
java.io.IOException

setReceiveLimit

public boolean setReceiveLimit(int id,
                               long limit,
                               boolean nolimit)
Send bytes through a SAM STREAM session.

Overrides:
setReceiveLimit in class SAMStreamSession
Parameters:
id - Stream ID
limit - limitation
nolimit - true to limit
Returns:
True if the data was queued for sending, false otherwise