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
Modifier and TypeFieldDescriptionprotected final long
protected SAMMessageSess
protected SAMMessageSess
protected static final String
protected SAMStreamSession
Fields inherited from class net.i2p.sam.SAMHandler
_log, bridge, i2cpProps, socket, stopHandler, stopLock, thread, verMajor, verMinor
-
Constructor Summary
ConstructorDescriptionSAMv1Handler
(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
Modifier and TypeMethodDescriptionprotected static String
Create a string to be appended to a status.protected boolean
execDatagramMessage
(String opcode, Properties props) protected boolean
execDestMessage
(String opcode, Properties props) protected boolean
execNamingMessage
(String opcode, Properties props) protected boolean
execRawMessage
(String opcode, Properties props) protected boolean
execSessionMessage
(String opcode, Properties props) protected boolean
execStreamClose
(Properties props) protected boolean
execStreamConnect
(Properties props) protected boolean
execStreamMessage
(String opcode, Properties props) protected boolean
execStreamSend
(Properties props) protected final SAMMessageSess
protected final SAMMessageSess
protected final SAMStreamSession
void
handle()
Actually handle the SAM protocol.void
notifyStreamDisconnection
(int id, String result, String msg) Notify that a connection has been closed FIXME: this interface should be cleanervoid
notifyStreamIncomingConnection
(int id, Destination d) Notify about a new incoming connectionvoid
notifyStreamOutgoingConnection
(int id, String result, String msg) Notify about a new outgoing connectionvoid
notifyStreamSendBufferFree
(int id) Notifies that the outwards buffer is free for writingvoid
receiveDatagramBytes
(Destination sender, byte[] data, int proto, int fromPort, int toPort) Send a byte array to a SAM client.void
receiveRawBytes
(byte[] data, int proto, int fromPort, int toPort) Send a byte array to a SAM client, without informations regarding the sender.void
receiveStreamBytes
(int id, ByteBuffer data) Transmit a byte array from I2P to a SAM client.void
Stop receiving data.void
Stop receiving data.void
Stop receiving data.void
streamSendAnswer
(int id, String result, String bufferState) Sends the result of a stream send operationboolean
protected boolean
writeString
(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 Details
-
rawSession
-
datagramSession
-
streamSession
-
_id
protected final long _id -
SESSION_ERROR
- See Also:
-
-
Constructor Details
-
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:
SAMException
IOException
-
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:
SAMException
IOException
-
-
Method Details
-
getRawSession
-
getDatagramSession
-
getStreamSession
-
verifVersion
public boolean verifVersion() -
handle
public void handle()Description copied from class:SAMHandler
Actually handle the SAM protocol.- Specified by:
handle
in classSAMHandler
-
execSessionMessage
-
execDestMessage
-
execNamingMessage
-
execDatagramMessage
-
execRawMessage
-
execStreamMessage
-
execStreamSend
-
execStreamConnect
-
execStreamClose
-
receiveRawBytes
Description copied from interface:SAMRawReceiver
Send a byte array to a SAM client, without informations regarding the sender.- Specified by:
receiveRawBytes
in 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:SAMRawReceiver
Stop receiving data.- Specified by:
stopRawReceiving
in interfaceSAMRawReceiver
-
receiveDatagramBytes
public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException Description copied from interface:SAMDatagramReceiver
Send a byte array to a SAM client.- Specified by:
receiveDatagramBytes
in 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:SAMDatagramReceiver
Stop receiving data.- Specified by:
stopDatagramReceiving
in interfaceSAMDatagramReceiver
-
streamSendAnswer
Description copied from interface:SAMStreamReceiver
Sends the result of a stream send operation- Specified by:
streamSendAnswer
in interfaceSAMStreamReceiver
- Parameters:
id
- Stream IDresult
- informationbufferState
- state of the buffer- Throws:
IOException
-
notifyStreamSendBufferFree
Description copied from interface:SAMStreamReceiver
Notifies that the outwards buffer is free for writing- Specified by:
notifyStreamSendBufferFree
in interfaceSAMStreamReceiver
- Parameters:
id
- stream ID- Throws:
IOException
-
notifyStreamIncomingConnection
Description copied from interface:SAMStreamReceiver
Notify about a new incoming connection- Specified by:
notifyStreamIncomingConnection
in interfaceSAMStreamReceiver
- Parameters:
id
- New connection idd
- Destination- Throws:
IOException
-
notifyStreamOutgoingConnection
Description copied from interface:SAMStreamReceiver
Notify about a new outgoing connection- Specified by:
notifyStreamOutgoingConnection
in interfaceSAMStreamReceiver
- Parameters:
id
- New connection idresult
- message resultmsg
- may be null- Throws:
IOException
-
createMessageString
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
Write a string and message, escaping the message. Writes s + createMessageString(msg) + \n- Parameters:
s
- The string, non-null- Since:
- 0.9.25
-
receiveStreamBytes
Description copied from interface:SAMStreamReceiver
Transmit a byte array from I2P to a SAM client.- Specified by:
receiveStreamBytes
in interfaceSAMStreamReceiver
- Parameters:
id
- Connection iddata
- Byte array to be received- Throws:
IOException
-
notifyStreamDisconnection
Description copied from interface:SAMStreamReceiver
Notify that a connection has been closed FIXME: this interface should be cleaner- Specified by:
notifyStreamDisconnection
in interfaceSAMStreamReceiver
- Parameters:
id
- Connection idresult
- Disconnection reason ("OK" or something else)msg
- may be null- Throws:
IOException
-
stopStreamReceiving
public void stopStreamReceiving()Description copied from interface:SAMStreamReceiver
Stop receiving data.- Specified by:
stopStreamReceiving
in interfaceSAMStreamReceiver
-