Package net.i2p.sam
Class SAMv1Handler
- java.lang.Object
-
- net.i2p.sam.SAMHandler
-
- net.i2p.sam.SAMv1Handler
-
- All Implemented Interfaces:
Runnable,Handler,SAMDatagramReceiver,SAMRawReceiver,SAMStreamReceiver
- Direct Known Subclasses:
SAMv2Handler,SAMv3Handler
class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatagramReceiver, SAMStreamReceiver
Class able to handle a SAM version 1 client connections.- Author:
- human
-
-
Field Summary
Fields Modifier and Type Field Description protected long_idprotected SAMMessageSessdatagramSessionprotected SAMMessageSessrawSessionprotected static StringSESSION_ERRORprotected SAMStreamSessionstreamSession-
Fields inherited from class net.i2p.sam.SAMHandler
_log, bridge, i2cpProps, socket, stopHandler, stopLock, thread, verMajor, verMinor
-
-
Constructor Summary
Constructors Constructor Description SAMv1Handler(SocketChannel s, int verMajor, int verMinor, Properties i2cpProps, SAMBridge parent)Create a new SAM version 1 handler.SAMv1Handler(SocketChannel s, int verMajor, int verMinor, SAMBridge parent)Create a new SAM version 1 handler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static StringcreateMessageString(String msg)Create a string to be appended to a status.protected booleanexecDatagramMessage(String opcode, Properties props)protected booleanexecDestMessage(String opcode, Properties props)protected booleanexecNamingMessage(String opcode, Properties props)protected booleanexecRawMessage(String opcode, Properties props)protected booleanexecSessionMessage(String opcode, Properties props)protected booleanexecStreamClose(Properties props)protected booleanexecStreamConnect(Properties props)protected booleanexecStreamMessage(String opcode, Properties props)protected booleanexecStreamSend(Properties props)protected SAMMessageSessgetDatagramSession()protected SAMMessageSessgetRawSession()protected SAMStreamSessiongetStreamSession()voidhandle()Actually handle the SAM protocol.voidnotifyStreamDisconnection(int id, String result, String msg)Notify that a connection has been closed FIXME: this interface should be cleanervoidnotifyStreamIncomingConnection(int id, Destination d)Notify about a new incoming connectionvoidnotifyStreamOutgoingConnection(int id, String result, String msg)Notify about a new outgoing connectionvoidnotifyStreamSendBufferFree(int id)Notifies that the outwards buffer is free for writingvoidreceiveDatagramBytes(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.voidreceiveStreamBytes(int id, ByteBuffer data)Transmit a byte array from I2P to a SAM client.voidstopDatagramReceiving()Stop receiving data.voidstopRawReceiving()Stop receiving data.voidstopStreamReceiving()Stop receiving data.voidstreamSendAnswer(int id, String result, String bufferState)Sends the result of a stream send operationbooleanverifVersion()protected booleanwriteString(String s, String msg)Write a string and message, escaping the message.-
Methods inherited from class net.i2p.sam.SAMHandler
closeClientSocket, getClientSocket, getWriteLock, run, shouldStop, startHandling, stopHandling, toString, writeBytes, writeString, writeString
-
-
-
-
Field Detail
-
rawSession
protected SAMMessageSess rawSession
-
datagramSession
protected SAMMessageSess datagramSession
-
streamSession
protected SAMStreamSession streamSession
-
_id
protected final long _id
-
SESSION_ERROR
protected static final String SESSION_ERROR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SAMv1Handler
public SAMv1Handler(SocketChannel s, int verMajor, int verMinor, SAMBridge parent) throws SAMException, IOException
Create a new SAM version 1 handler. This constructor expects that the SAM HELLO message has been still answered (and stripped) from the socket input stream.- Parameters:
s- Socket attached to a SAM clientverMajor- SAM major version to manage (should be 1)verMinor- SAM minor version to manage- Throws:
SAMExceptionIOException
-
SAMv1Handler
public SAMv1Handler(SocketChannel s, int verMajor, int verMinor, Properties i2cpProps, SAMBridge parent) throws SAMException, IOException
Create a new SAM version 1 handler. This constructor expects that the SAM HELLO message has been still answered (and stripped) from the socket input stream.- Parameters:
s- Socket attached to a SAM clientverMajor- SAM major version to manage (should be 1)verMinor- SAM minor version to managei2cpProps- properties to configure the I2CP connection (host, port, etc)- Throws:
SAMExceptionIOException
-
-
Method Detail
-
getRawSession
protected final SAMMessageSess getRawSession()
-
getDatagramSession
protected final SAMMessageSess getDatagramSession()
-
getStreamSession
protected final SAMStreamSession getStreamSession()
-
verifVersion
public boolean verifVersion()
-
handle
public void handle()
Description copied from class:SAMHandlerActually handle the SAM protocol.- Specified by:
handlein classSAMHandler
-
execSessionMessage
protected boolean execSessionMessage(String opcode, Properties props)
-
execDestMessage
protected boolean execDestMessage(String opcode, Properties props)
-
execNamingMessage
protected boolean execNamingMessage(String opcode, Properties props)
-
execDatagramMessage
protected boolean execDatagramMessage(String opcode, Properties props)
-
execRawMessage
protected boolean execRawMessage(String opcode, Properties props)
-
execStreamMessage
protected boolean execStreamMessage(String opcode, Properties props)
-
execStreamSend
protected boolean execStreamSend(Properties props)
-
execStreamConnect
protected boolean execStreamConnect(Properties props)
-
execStreamClose
protected boolean execStreamClose(Properties props)
-
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
-
stopRawReceiving
public void stopRawReceiving()
Description copied from interface:SAMRawReceiverStop receiving data.- Specified by:
stopRawReceivingin interfaceSAMRawReceiver
-
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
-
stopDatagramReceiving
public void stopDatagramReceiving()
Description copied from interface:SAMDatagramReceiverStop receiving data.- Specified by:
stopDatagramReceivingin interfaceSAMDatagramReceiver
-
streamSendAnswer
public void streamSendAnswer(int id, String result, String bufferState) throws IOExceptionDescription copied from interface:SAMStreamReceiverSends the result of a stream send operation- Specified by:
streamSendAnswerin interfaceSAMStreamReceiver- Parameters:
id- Stream IDresult- informationbufferState- state of the buffer- Throws:
IOException
-
notifyStreamSendBufferFree
public void notifyStreamSendBufferFree(int id) throws IOExceptionDescription copied from interface:SAMStreamReceiverNotifies that the outwards buffer is free for writing- Specified by:
notifyStreamSendBufferFreein interfaceSAMStreamReceiver- Parameters:
id- stream ID- Throws:
IOException
-
notifyStreamIncomingConnection
public void notifyStreamIncomingConnection(int id, Destination d) throws IOExceptionDescription copied from interface:SAMStreamReceiverNotify about a new incoming connection- Specified by:
notifyStreamIncomingConnectionin interfaceSAMStreamReceiver- Parameters:
id- New connection idd- Destination- Throws:
IOException
-
notifyStreamOutgoingConnection
public void notifyStreamOutgoingConnection(int id, String result, String msg) throws IOExceptionDescription copied from interface:SAMStreamReceiverNotify about a new outgoing connection- Specified by:
notifyStreamOutgoingConnectionin interfaceSAMStreamReceiver- Parameters:
msg- may be nullid- New connection idresult- message result- Throws:
IOException
-
createMessageString
protected static String createMessageString(String msg)
Create a string to be appended to a status.- Parameters:
msg- may be null- Returns:
- non-null, "" if msg is null, MESSAGE=msg or MESSAGE="msg a b c" with leading space if msg is non-null
- Since:
- 0.9.20
-
writeString
protected boolean writeString(String s, String msg)
Write a string and message, escaping the message. Writes s + createMessageString(msg) + \n- Parameters:
s- The string, non-null- Since:
- 0.9.25
-
receiveStreamBytes
public void receiveStreamBytes(int id, ByteBuffer data) throws IOExceptionDescription copied from interface:SAMStreamReceiverTransmit a byte array from I2P to a SAM client.- Specified by:
receiveStreamBytesin interfaceSAMStreamReceiver- Parameters:
id- Connection iddata- Byte array to be received- Throws:
IOException
-
notifyStreamDisconnection
public void notifyStreamDisconnection(int id, String result, String msg) throws IOExceptionDescription copied from interface:SAMStreamReceiverNotify that a connection has been closed FIXME: this interface should be cleaner- Specified by:
notifyStreamDisconnectionin interfaceSAMStreamReceiver- Parameters:
msg- may be nullid- Connection idresult- Disconnection reason ("OK" or something else)- Throws:
IOException
-
stopStreamReceiving
public void stopStreamReceiving()
Description copied from interface:SAMStreamReceiverStop receiving data.- Specified by:
stopStreamReceivingin interfaceSAMStreamReceiver
-
-