Package net.i2p.sam
Class PrimarySession
- java.lang.Object
-
- net.i2p.sam.SAMStreamSession
-
- net.i2p.sam.SAMv3StreamSession
-
- net.i2p.sam.PrimarySession
-
- All Implemented Interfaces:
Closeable,AutoCloseable,I2PSessionListener,I2PSessionMuxedListener,SAMDatagramReceiver,SAMMessageSess,SAMRawReceiver,Session
class PrimarySession extends SAMv3StreamSession implements SAMDatagramReceiver, SAMRawReceiver, SAMMessageSess, I2PSessionMuxedListener
A session that does nothing, but implements interfaces for raw, datagram, and streaming for convenience. We extend SAMv3StreamSession as we must have it set up the I2PSession, in case user adds a STREAM session (and he probably will). This session receives all data from I2P, but you can't send any data on it.- Since:
- 0.9.25
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.i2p.sam.SAMStreamSession
SAMStreamSession.DisconnectListener, SAMStreamSession.SAMStreamSessionServer, SAMStreamSession.SAMStreamSessionSocketReader, SAMStreamSession.SAMv1StreamSessionSocketReader, SAMStreamSession.StreamSender
-
-
Field Summary
-
Fields inherited from class net.i2p.sam.SAMStreamSession
_isOwnSession, _log, canCreate, DEFAULT_FORCE_FLUSH, forceFlush, PROP_FORCE_FLUSH, recv, server, SOCKET_HANDLER_BUF_SIZE, socketMgr
-
-
Constructor Summary
Constructors Constructor Description PrimarySession(String nick, SAMv3DatagramServer dgServer, SAMv3Handler handler, Properties props)Build a Session according to information registered with the given nickname.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(SAMv3Handler handler, boolean verbose)Accept a single incoming STREAM on the socket stolen from the handler.Stringadd(String nick, String style, Properties props)Add a sessionvoidclose()Close the primary session and all subsessions.voidconnect(SAMv3Handler handler, String dest, Properties props)Connect the SAM STREAM session to the specified Destination for a single connection, using the socket stolen from the handler.voiddisconnected(I2PSession session)Notify the client that the session has been terminated.voiderrorOccurred(I2PSession session, String message, Throwable error)Notify the client that some error occurred.intgetListenPort()intgetListenProtocol()voidmessageAvailable(I2PSession session, int msgId, long size)Will be called only if you register via setSessionListener() or addSessionListener().voidmessageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort)Instruct the client that the given session has received a message Will be called only if you register via addMuxedSessionListener().voidreceiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort)Send a byte array to a SAM client.voidreceiveRawBytes(byte[] data, int proto, int fromPort, int toPort)Send a byte array to a SAM client, without informations regarding the sender.Stringremove(String nick, Properties props)Remove a sessionvoidreportAbuse(I2PSession session, int severity)Instruct the client that the session specified seems to be under attack and that the client may wish to move its destination to another router.voidstart()Overridden to start the acceptor.voidstartForwardingIncoming(Properties props, boolean sendPorts)Forward sockets from I2P to the host/port provided.voidstopDatagramReceiving()Does nothing.voidstopForwardingIncoming()does nothingvoidstopRawReceiving()Does nothing.-
Methods inherited from class net.i2p.sam.SAMv3StreamSession
getDB, getNick, getSocketServer, queueSocket
-
Methods inherited from class net.i2p.sam.SAMStreamSession
checkSocketHandlerId, closeConnection, connect, createSocketHandler, getDestination, getSocketReader, newSAMStreamSessionSocketReader, newStreamSender, removeSocketHandler, sendBytes, sendBytes, sendBytes, setReceiveLimit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.i2p.sam.SAMMessageSess
getDestination, sendBytes, sendBytes
-
-
-
-
Constructor Detail
-
PrimarySession
public PrimarySession(String nick, SAMv3DatagramServer dgServer, SAMv3Handler handler, Properties props) throws IOException, DataFormatException, SAMException
Build a Session according to information registered with the given nickname. Caller MUST call start().- Parameters:
nick- nickname of the session- Throws:
IOExceptionDataFormatExceptionSAMException
-
-
Method Detail
-
start
public void start()
Overridden to start the acceptor.- Specified by:
startin interfaceSAMMessageSess- Overrides:
startin classSAMStreamSession
-
add
public String add(String nick, String style, Properties props)
Add a session- Returns:
- null for success, or error message
-
remove
public String remove(String nick, Properties props)
Remove a session- Parameters:
props- ignored, may be null- Returns:
- null for success, or error message
-
receiveDatagramBytes
public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException
Description copied from interface:SAMDatagramReceiverSend a byte array to a SAM client.- Specified by:
receiveDatagramBytesin interfaceSAMDatagramReceiver- Parameters:
sender- Destinationdata- Byte array to be receivedproto- I2CP protocolfromPort- I2CP from porttoPort- I2CP to port- Throws:
IOException- always
-
stopDatagramReceiving
public void stopDatagramReceiving()
Does nothing.- Specified by:
stopDatagramReceivingin interfaceSAMDatagramReceiver
-
receiveRawBytes
public void receiveRawBytes(byte[] data, int proto, int fromPort, int toPort) throws IOExceptionDescription copied from interface:SAMRawReceiverSend a byte array to a SAM client, without informations regarding the sender.- Specified by:
receiveRawBytesin interfaceSAMRawReceiver- Parameters:
data- Byte array to be receivedproto- I2CP protocolfromPort- I2CP from porttoPort- I2CP to port- Throws:
IOException- always
-
stopRawReceiving
public void stopRawReceiving()
Does nothing.- Specified by:
stopRawReceivingin interfaceSAMRawReceiver
-
connect
public void connect(SAMv3Handler handler, String dest, Properties props) throws I2PException
Description copied from class:SAMv3StreamSessionConnect the SAM STREAM session to the specified Destination for a single connection, using the socket stolen from the handler.- Overrides:
connectin classSAMv3StreamSession- Parameters:
handler- The handler that communicates with the requesting clientdest- Base64-encoded Destination to connect toprops- Options to be used for connection- Throws:
I2PException- always
-
accept
public void accept(SAMv3Handler handler, boolean verbose) throws SAMException
Description copied from class:SAMv3StreamSessionAccept a single incoming STREAM on the socket stolen from the handler. As of version 3.2 (0.9.24), multiple simultaneous accepts are allowed. Accepts and forwarding may not be done at the same time.- Overrides:
acceptin classSAMv3StreamSession- Parameters:
handler- The handler that communicates with the requesting clientverbose- If true, SAM will send the Base64-encoded peer Destination of an incoming socket as the first line of data sent to its client on the handler socket- Throws:
SAMException- always
-
startForwardingIncoming
public void startForwardingIncoming(Properties props, boolean sendPorts) throws SAMException
Description copied from class:SAMv3StreamSessionForward sockets from I2P to the host/port provided. Accepts and forwarding may not be done at the same time.- Overrides:
startForwardingIncomingin classSAMv3StreamSession- Throws:
SAMException- always
-
stopForwardingIncoming
public void stopForwardingIncoming()
does nothing- Overrides:
stopForwardingIncomingin classSAMv3StreamSession
-
getListenProtocol
public int getListenProtocol()
- Specified by:
getListenProtocolin interfaceSAMMessageSess- Overrides:
getListenProtocolin classSAMStreamSession
-
getListenPort
public int getListenPort()
- Specified by:
getListenPortin interfaceSAMMessageSess- Overrides:
getListenPortin classSAMStreamSession
-
close
public void close()
Close the primary session and all subsessions. Overridden to stop the acceptor and the subsessions.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSAMMessageSess- Overrides:
closein classSAMv3StreamSession
-
disconnected
public void disconnected(I2PSession session)
Description copied from interface:I2PSessionMuxedListenerNotify the client that the session has been terminated. All registered listeners will be called.- Specified by:
disconnectedin interfaceI2PSessionListener- Specified by:
disconnectedin interfaceI2PSessionMuxedListener
-
errorOccurred
public void errorOccurred(I2PSession session, String message, Throwable error)
Description copied from interface:I2PSessionMuxedListenerNotify the client that some error occurred. All registered listeners will be called.- Specified by:
errorOccurredin interfaceI2PSessionListener- Specified by:
errorOccurredin interfaceI2PSessionMuxedListenererror- can be null? or not?
-
messageAvailable
public void messageAvailable(I2PSession session, int msgId, long size)
Description copied from interface:I2PSessionMuxedListenerWill be called only if you register via setSessionListener() or addSessionListener(). And if you are doing that, just use I2PSessionListener. If you register via addSessionListener(), this will be called only for the proto(s) and toport(s) you register for. After this is called, the client should call receiveMessage(msgId). There is currently no method for the client to reject the message. If the client does not call receiveMessage() within a timeout period (currently 30 seconds), the session will delete the message and log an error.- Specified by:
messageAvailablein interfaceI2PSessionListener- Specified by:
messageAvailablein interfaceI2PSessionMuxedListener- Parameters:
session- session to notifymsgId- message number availablesize- size of the message - why it's a long and not an int is a mystery
-
messageAvailable
public void messageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort)
Description copied from interface:I2PSessionMuxedListenerInstruct the client that the given session has received a message Will be called only if you register via addMuxedSessionListener(). Will be called only for the proto(s) and toport(s) you register for. After this is called, the client should call receiveMessage(msgId). There is currently no method for the client to reject the message. If the client does not call receiveMessage() within a timeout period (currently 30 seconds), the session will delete the message and log an error. Only one listener is called for a given message, even if more than one have registered. See I2PSessionDemultiplexer for details.- Specified by:
messageAvailablein interfaceI2PSessionMuxedListener- Parameters:
session- session to notifymsgId- message number availablesize- size of the message - why it's a long and not an int is a mysteryproto- 1-254 or 0 for unspecifiedfromPort- 1-65535 or 0 for unspecifiedtoPort- 1-65535 or 0 for unspecified- Since:
- 0.9.24
-
reportAbuse
public void reportAbuse(I2PSession session, int severity)
Description copied from interface:I2PSessionMuxedListenerInstruct the client that the session specified seems to be under attack and that the client may wish to move its destination to another router. All registered listeners will be called. Unused. Not fully implemented.- Specified by:
reportAbusein interfaceI2PSessionListener- Specified by:
reportAbusein interfaceI2PSessionMuxedListener- Parameters:
session- session to report abuse toseverity- how bad the abuse is
-
-