class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatagramReceiver, SAMStreamReceiver
Modifier and Type | Field and Description |
---|---|
protected long |
_id |
protected SAMMessageSess |
datagramSession |
protected SAMMessageSess |
rawSession |
protected static String |
SESSION_ERROR |
protected SAMStreamSession |
streamSession |
_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) |
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 SAMMessageSess |
getDatagramSession() |
protected SAMMessageSess |
getRawSession() |
protected SAMStreamSession |
getStreamSession() |
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 cleaner
|
void |
notifyStreamIncomingConnection(int id,
Destination d)
Notify about a new incoming connection
|
void |
notifyStreamOutgoingConnection(int id,
String result,
String msg)
Notify about a new outgoing connection
|
void |
notifyStreamSendBufferFree(int id)
Notifies that the outwards buffer is free for writing
|
void |
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 |
stopDatagramReceiving()
Stop receiving data.
|
void |
stopRawReceiving()
Stop receiving data.
|
void |
stopStreamReceiving()
Stop receiving data.
|
void |
streamSendAnswer(int id,
String result,
String bufferState)
Sends the result of a stream send operation
|
boolean |
verifVersion() |
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, writeString
protected SAMMessageSess rawSession
protected SAMMessageSess datagramSession
protected SAMStreamSession streamSession
protected final long _id
protected static final String SESSION_ERROR
public 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 manageSAMException
IOException
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)SAMException
IOException
protected final SAMMessageSess getRawSession()
protected final SAMMessageSess getDatagramSession()
protected final SAMStreamSession getStreamSession()
public boolean verifVersion()
public void handle()
SAMHandler
handle
in class SAMHandler
protected boolean execSessionMessage(String opcode, Properties props)
protected boolean execDestMessage(String opcode, Properties props)
protected boolean execNamingMessage(String opcode, Properties props)
protected boolean execDatagramMessage(String opcode, Properties props)
protected boolean execRawMessage(String opcode, Properties props)
protected boolean execStreamMessage(String opcode, Properties props)
protected boolean execStreamSend(Properties props)
protected boolean execStreamConnect(Properties props)
protected boolean execStreamClose(Properties props)
public void receiveRawBytes(byte[] data, int proto, int fromPort, int toPort) throws IOException
SAMRawReceiver
receiveRawBytes
in interface SAMRawReceiver
data
- Byte array to be receivedproto
- I2CP protocolfromPort
- I2CP from porttoPort
- I2CP to portIOException
public void stopRawReceiving()
SAMRawReceiver
stopRawReceiving
in interface SAMRawReceiver
public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException
SAMDatagramReceiver
receiveDatagramBytes
in interface SAMDatagramReceiver
sender
- Destinationdata
- Byte array to be receivedproto
- I2CP protocolfromPort
- I2CP from porttoPort
- I2CP to portIOException
public void stopDatagramReceiving()
SAMDatagramReceiver
stopDatagramReceiving
in interface SAMDatagramReceiver
public void streamSendAnswer(int id, String result, String bufferState) throws IOException
SAMStreamReceiver
streamSendAnswer
in interface SAMStreamReceiver
id
- Stream IDresult
- informationbufferState
- state of the bufferIOException
public void notifyStreamSendBufferFree(int id) throws IOException
SAMStreamReceiver
notifyStreamSendBufferFree
in interface SAMStreamReceiver
id
- stream IDIOException
public void notifyStreamIncomingConnection(int id, Destination d) throws IOException
SAMStreamReceiver
notifyStreamIncomingConnection
in interface SAMStreamReceiver
id
- New connection idd
- DestinationIOException
public void notifyStreamOutgoingConnection(int id, String result, String msg) throws IOException
SAMStreamReceiver
notifyStreamOutgoingConnection
in interface SAMStreamReceiver
msg
- may be nullid
- New connection idresult
- message resultIOException
protected static String createMessageString(String msg)
msg
- may be nullprotected boolean writeString(String s, String msg)
s
- The string, non-nullpublic void receiveStreamBytes(int id, ByteBuffer data) throws IOException
SAMStreamReceiver
receiveStreamBytes
in interface SAMStreamReceiver
id
- Connection iddata
- Byte array to be receivedIOException
public void notifyStreamDisconnection(int id, String result, String msg) throws IOException
SAMStreamReceiver
notifyStreamDisconnection
in interface SAMStreamReceiver
msg
- may be nullid
- Connection idresult
- Disconnection reason ("OK" or something else)IOException
public void stopStreamReceiving()
SAMStreamReceiver
stopStreamReceiving
in interface SAMStreamReceiver