java.lang.Object
net.i2p.sam.client.SAMClientEventListenerImpl
net.i2p.sam.client.SAMEventHandler
net.i2p.sam.client.SAMStreamSink.SinkEventHandler
- All Implemented Interfaces:
SAMReader.SAMClientEventListener
- Direct Known Subclasses:
SAMStreamSink.SinkEventHandler2
- Enclosing class:
SAMStreamSink
Handles session events and writes received messages to files.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OutputStreamStream to the SAM bridge, used to answer keepalives.Fields inherited from interface SAMReader.SAMClientEventListener
NAMING_REPLY_INVALID_KEY, NAMING_REPLY_KEY_NOT_FOUND, NAMING_REPLY_OK, SESSION_STATUS_DUPLICATE_DEST, SESSION_STATUS_I2P_ERROR, SESSION_STATUS_INVALID_KEY, SESSION_STATUS_OK, STREAM_CLOSED_CANT_REACH_PEER, STREAM_CLOSED_I2P_ERROR, STREAM_CLOSED_OK, STREAM_CLOSED_PEER_NOT_FOUND, STREAM_CLOSED_TIMEOUT, STREAM_STATUS_CANT_REACH_PEER, STREAM_STATUS_I2P_ERROR, STREAM_STATUS_INVALID_KEY, STREAM_STATUS_OK, STREAM_STATUS_TIMEOUTModifier and TypeFieldDescriptionstatic final StringNaming lookup failed because the private key is invalid.static final StringNaming lookup failed because no key matches the requested name.static final StringNaming lookup succeeded.static final StringSession creation failed because the destination is already in use.static final StringSESSION_STATUS_I2P_ERROR.static final StringSession creation failed because the supplied private key is invalid.static final StringSession creation succeeded.static final StringStream closed because the peer became unreachable.static final StringSTREAM_CLOSED_I2P_ERROR.static final StringStream closed normally.static final StringStream closed because the destination was no longer known to the router.static final StringStream closed because the lease expired.static final StringStream connect failed because the peer could not be reached.static final StringSTREAM_STATUS_I2P_ERROR.static final StringStream connect failed because the private key is invalid.static final StringStream connect succeeded.static final StringStream connect failed because the lease expired before it was established.Constructor Summary
ConstructorsConstructorDescriptionSinkEventHandler(I2PAppContext ctx, OutputStream out) Remember the bridge output stream for the event replies.Method Summary
All MethodsModifier and TypeMethodDescriptionvoiddatagramReceived(String dest, byte[] data, int offset, int length, int fromPort, int toPort) Appends the received datagram to the first open sink.voidpingReceived(String data) Answers a bridge keepalive with a matching PONG.voidrawReceived(byte[] data, int offset, int length, int fromPort, int toPort, int protocol) Appends the received raw datagram to the first open sink.voidstreamClosedReceived(String result, String id, String message) Closes the sink file and records the connection lifetime.voidstreamConnectedReceived(String dest, String id) Opens a sink file for a newly connected stream.voidstreamDataReceived(String id, byte[] data, int offset, int length) Appends the received stream data to the sink file.Methods inherited from class SAMEventHandler
helloReplyReceived, namingReplyReceived, sessionStatusReceived, streamStatusReceived, unknownMessageReceived, waitForHelloReply, waitForNamingReply, waitForSessionAddReply, waitForSessionCreateReply, waitForStreamStatusReplyModifier and TypeMethodDescriptionvoidhelloReplyReceived(boolean ok, String version) Records the HELLO outcome and version, then wakes any waiter.voidnamingReplyReceived(String name, String result, String value, String msg) Files a naming reply under its name, value on success and result otherwise.voidsessionStatusReceived(String result, String destination, String msg) May be called twice, first for CREATE and second for ADD.voidstreamStatusReceived(String result, String id, String message) Records the session status result, then wakes any waiter.voidunknownMessageReceived(String major, String minor, Properties params) Logs a message this handler has no handling for.Wait for the connection to be established, returning the server version if everything went ok.waitForNamingReply(String name) Return the destination found matching the name, or null if the key was not able to be retrieved.booleanWait for the session to be added, returning true if everything went ok.booleanWait for the session to be created, returning true if everything went ok.booleanWait for the stream to be created, returning true if everything went ok.Methods inherited from class SAMClientEventListenerImpl
destReplyReceived, pongReceivedModifier and TypeMethodDescriptionvoiddestReplyReceived(String publicKey, String privateKey) Called when a DEST reply arrives.voidpongReceived(String data) Called when a PONG reply arrives.
Field Details
_out
Stream to the SAM bridge, used to answer keepalives.
Constructor Details
SinkEventHandler
Remember the bridge output stream for the event replies.- Parameters:
ctx- the application context for the event handlerout- the bridge output stream, used to answer keepalives
Method Details
streamClosedReceived
Closes the sink file and records the connection lifetime.- Specified by:
streamClosedReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
streamClosedReceivedin classSAMClientEventListenerImpl- Parameters:
result- the close status, one of the STREAM_CLOSED_* constantsid- the stream ID of the stream that was closedmessage- the human-readable explanation supplied by the bridge
streamDataReceived
Appends the received stream data to the sink file.- Specified by:
streamDataReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
streamDataReceivedin classSAMClientEventListenerImpl- Parameters:
id- the stream ID the data arrived ondata- the buffer holding the payloadoffset- the index within data where the payload startslength- the number of payload bytes valid from offset
streamConnectedReceived
Opens a sink file for a newly connected stream.- Specified by:
streamConnectedReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
streamConnectedReceivedin classSAMClientEventListenerImpl- Parameters:
dest- the base64 destination the stream is connected toid- the stream ID assigned by the SAM bridge
pingReceived
Answers a bridge keepalive with a matching PONG.- Specified by:
pingReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
pingReceivedin classSAMClientEventListenerImpl- Parameters:
data- the payload echoed back, limited to the first token of the line
datagramReceived
public void datagramReceived(String dest, byte[] data, int offset, int length, int fromPort, int toPort) Appends the received datagram to the first open sink.- Specified by:
datagramReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
datagramReceivedin classSAMClientEventListenerImpl- Parameters:
dest- the base64 destination that sent the datagramdata- the buffer holding the datagram bodyoffset- the index within data where the body startslength- the number of body bytes valid from offsetfromPort- the source port in host byte ordertoPort- the destination port in host byte order
rawReceived
public void rawReceived(byte[] data, int offset, int length, int fromPort, int toPort, int protocol) Appends the received raw datagram to the first open sink.- Specified by:
rawReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
rawReceivedin classSAMClientEventListenerImpl- Parameters:
data- the buffer holding the raw datagram bodyoffset- the index within data where the body startslength- the number of body bytes valid from offsetfromPort- the source port in host byte ordertoPort- the destination port in host byte orderprotocol- the IP protocol number, or I2PSession.PROTO_DATAGRAM_RAW when unreported