class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatagramReceiver, SAMStreamReceiver
| Modifier and Type | Field and Description |
|---|---|
protected long | _id_id. |
protected SAMMessageSess | datagramSessiondatagramSession. |
protected SAMMessageSess | rawSessionrawSession. |
protected static String | SESSION_ERRORSESSION_ERROR. |
protected SAMStreamSession | streamSessionstreamSession. |
_log, bridge, i2cpProps, socket, stopHandler, stopLock, thread, verMajor, verMinor| Constructor and 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. |
| Modifier and Type | Method and Description |
|---|---|
protected static String | createMessageString(String msg)Create a string to be appended to a status. |
protected boolean | execDatagramMessage(String opcode,
Properties props)Parse and execute a DATAGRAM message. |
protected boolean | execDestMessage(String opcode,
Properties props)Parse and execute a DEST message. |
protected boolean | execNamingMessage(String opcode,
Properties props)Parse and execute a NAMING message. |
protected boolean | execRawMessage(String opcode,
Properties props)Parse and execute a RAW message. |
protected boolean | execSessionMessage(String opcode,
Properties props)Parse and execute a SESSION message. |
protected boolean | execStreamClose(Properties props)Parse and execute a STREAM CLOSE message. |
protected boolean | execStreamConnect(Properties props)Parse and execute a STREAM CONNECT message. |
protected boolean | execStreamMessage(String opcode,
Properties props)Parse and execute a STREAM message. |
protected boolean | execStreamSend(Properties props)Parse and execute a STREAM SEND message. |
protected SAMMessageSess | getDatagramSession() |
protected SAMMessageSess | getRawSession() |
protected SAMStreamSession | getStreamSession() |
void | handle()Handle a SAM v1 client connection by reading and dispatching commands
in a loop until the connection is closed or an error occurs. |
void | notifyStreamDisconnection(int id,
String result,
String msg)Notify the SAM client that a stream connection has been disconnected. |
void | notifyStreamIncomingConnection(int id,
Destination d)Notify the SAM client of an incoming stream connection. |
void | notifyStreamOutgoingConnection(int id,
String result,
String msg)Notify about a new outgoing connection |
void | notifyStreamSendBufferFree(int id)Notify the SAM client that the stream send buffer is free for more data. |
void | receiveDatagramBytes(Destination sender,
byte[] data,
int proto,
int fromPort,
int toPort)Receive datagram bytes from the network and forward them to the SAM client. |
void | receiveRawBytes(byte[] data,
int proto,
int fromPort,
int toPort)Receive raw bytes from the network and forward them to the SAM client. |
void | receiveStreamBytes(int id,
ByteBuffer data)Receive stream bytes from the network and forward them to the SAM client. |
void | stopDatagramReceiving()Stop receiving datagram bytes and close the client socket. |
void | stopRawReceiving()Stop receiving raw bytes and close the client socket. |
void | stopStreamReceiving()Stop receiving stream bytes and close the client socket. |
void | streamSendAnswer(int id,
String result,
String bufferState)Notify the SAM client of the result of a stream SEND operation. |
boolean | verifVersion()Verify the SAM protocol version is supported by this handler. |
protected boolean | writeString(String s,
String msg)Write a string and message, escaping the message. |
closeClientSocket, getClientSocket, getWriteLock, run, shouldStop, startHandling, stopHandling, toString, writeBytes, writeString, writeStringprotected final long _id
protected SAMMessageSess datagramSession
protected SAMMessageSess rawSession
protected static final String SESSION_ERROR
protected SAMStreamSession streamSession
public SAMv1Handler(SocketChannel s, int verMajor, int verMinor, Properties i2cpProps, SAMBridge parent) throws SAMException, IOException
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)parent - the SAM bridge managing this handlerSAMException - if the version is not supportedIOException - if an I/O error occurspublic SAMv1Handler(SocketChannel s, int verMajor, int verMinor, SAMBridge parent) throws SAMException, IOException
s - Socket attached to a SAM clientverMajor - SAM major version to manage (should be 1)verMinor - SAM minor version to manageparent - the SAM bridge managing this handlerSAMException - if the version is not supportedIOException - if an I/O error occursprotected static String createMessageString(String msg)
msg - may be nullprotected boolean execDatagramMessage(String opcode, Properties props)
opcode - the DATAGRAM sub-command (e.g. SEND)props - the parsed message propertiesprotected boolean execDestMessage(String opcode, Properties props)
opcode - the DEST sub-command (e.g. GENERATE)props - the parsed message propertiesprotected boolean execNamingMessage(String opcode, Properties props)
opcode - the NAMING sub-command (e.g. LOOKUP)props - the parsed message propertiesprotected boolean execRawMessage(String opcode, Properties props)
opcode - the RAW sub-command (e.g. SEND)props - the parsed message propertiesprotected boolean execSessionMessage(String opcode, Properties props)
opcode - the SESSION sub-command (e.g. CREATE)props - the parsed message propertiesprotected boolean execStreamClose(Properties props)
props - the parsed message propertiesprotected boolean execStreamConnect(Properties props)
props - the parsed message propertiesprotected boolean execStreamMessage(String opcode, Properties props)
opcode - the STREAM sub-command (e.g. SEND, CONNECT, CLOSE)props - the parsed message propertiesprotected boolean execStreamSend(Properties props)
props - the parsed message propertiesprotected final SAMMessageSess getDatagramSession()
protected final SAMMessageSess getRawSession()
protected final SAMStreamSession getStreamSession()
public void handle()
handle in class SAMHandlerpublic void notifyStreamDisconnection(int id,
String result,
String msg)
throws IOExceptionnotifyStreamDisconnection in interface SAMStreamReceiverid - the stream connection IDresult - the result code (e.g. OK, TIMEOUT)msg - optional message, may be nullIOException - if writing to the client socket failspublic void notifyStreamIncomingConnection(int id,
Destination d)
throws IOExceptionnotifyStreamIncomingConnection in interface SAMStreamReceiverid - the stream connection IDd - the destination of the remote peerIOException - if writing to the client socket failspublic void notifyStreamOutgoingConnection(int id,
String result,
String msg)
throws IOExceptionSAMStreamReceivernotifyStreamOutgoingConnection in interface SAMStreamReceivermsg - may be nullid - New connection idresult - message resultIOExceptionpublic void notifyStreamSendBufferFree(int id)
throws IOExceptionnotifyStreamSendBufferFree in interface SAMStreamReceiverid - the stream connection IDIOException - if writing to the client socket failspublic void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException
receiveDatagramBytes in interface SAMDatagramReceiversender - the destination of the datagram senderdata - the received datagram dataproto - the protocol numberfromPort - the source porttoPort - the destination portIOException - if writing to the client socket failspublic void receiveRawBytes(byte[] data,
int proto,
int fromPort,
int toPort)
throws IOExceptionreceiveRawBytes in interface SAMRawReceiverdata - the received raw dataproto - the protocol numberfromPort - the source porttoPort - the destination portIOException - if writing to the client socket failspublic void receiveStreamBytes(int id,
ByteBuffer data)
throws IOExceptionreceiveStreamBytes in interface SAMStreamReceiverid - the stream connection IDdata - the received dataIOException - if writing to the client socket failspublic void stopDatagramReceiving()
stopDatagramReceiving in interface SAMDatagramReceiverpublic void stopRawReceiving()
stopRawReceiving in interface SAMRawReceiverpublic void stopStreamReceiving()
stopStreamReceiving in interface SAMStreamReceiverpublic void streamSendAnswer(int id,
String result,
String bufferState)
throws IOExceptionstreamSendAnswer in interface SAMStreamReceiverid - the stream connection IDresult - the result code (e.g. OK, TIMEOUT)bufferState - the current buffer stateIOException - if writing to the client socket failspublic boolean verifVersion()