java.lang.Object
net.i2p.sam.client.SAMStreamSink
Swiss army knife tester. Saves our transient b64 destination to myKeyFile where SAMStreamSend can get it. Saves received data to a file (in sinkDir).
Usage: SAMStreamSink [options] myKeyFile sinkDir
See apps/sam/doc/README-test.txt for info on test setup. Receives data in one of 7 modes. Optionally uses SSL. Configurable SAM client version.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classReceives datagram or raw messages and writes them to files.private classForwards received messages to a local port.private static classSends periodic ping messages on the stream.private classOne open SAM session receiving messages.private classHandles session events and writes received messages to files.private classHandler for the second master session stream.Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringExtra connection options from the command line.private final I2PAppContextThe app context.private final StringFile holding our destination.private booleanWhether SAM version 3 is used.private booleanWhether SAM version 3.2 or later is used.private final LogLogger for the SAM client.private SAMReaderReader for the SAM session replies.private SAMReaderReader for the second master session stream.private final Map<String, SAMStreamSink.Sink> Connection id (Integer) to peer (Flooder).private final StringHost of the SAM bridge.private final StringPort of the SAM bridge.private final StringDirectory the received files are written to.private StringSession id used with SAM version 3.private static final intMode number for datagram receive.private static final intMode number for stream forwarding.private static final intMode number for SSL stream forwarding.private static final intMode number for a master session.private static final intMode number for raw receive.private static final intMode number for raw receive with headers.private static I2PSSLSocketFactoryFactory for the SSL bridge connections.private static final intMode number for stream receive.private static final StringThe usage message printed on bad arguments.private static final intMode number for version 1 datagram receive.private static final intMode number for version 1 raw receive.private static final intDefault datagram port for SAM version 3.private static final intDefault forward port for SAM version 3.Constructor Summary
ConstructorsConstructorDescriptionSAMStreamSink(I2PAppContext ctx, String samHost, String samPort, String destFile, String sinkDir) Holds the SAM bridge connection that received streams are written from.Method Summary
Modifier and TypeMethodDescriptionprivate Socketconnect(boolean isSSL) Opens the connection to the SAM bridge.private Stringhandshake(OutputStream samOut, String version, boolean isMaster, SAMEventHandler eventHandler, int mode, String user, String password, String sopts) Send the HELLO and log in.static voidCommand line entry point, connecting to a SAM bridge and writing streams to disk.voidConnects to the bridge, handshakes, and starts the receiving threads.private booleanWrites our destination to the destination file.
Field Details
_context
The app context._log
Logger for the SAM client._samHost
Host of the SAM bridge._samPort
Port of the SAM bridge._destFile
File holding our destination._sinkDir
Directory the received files are written to._conOptions
Extra connection options from the command line._reader
Reader for the SAM session replies._reader2
Reader for the second master session stream._isV3
private boolean _isV3Whether SAM version 3 is used._isV32
private boolean _isV32Whether SAM version 3.2 or later is used._v3ID
Session id used with SAM version 3._remotePeers
Connection id (Integer) to peer (Flooder).sslSocketFactory
Factory for the SSL bridge connections.STREAM
DG
V1DG
private static final int V1DGMode number for version 1 datagram receive.- See Also:
RAW
V1RAW
RAWHDR
private static final int RAWHDRMode number for raw receive with headers.- See Also:
FORWARD
FORWARDSSL
private static final int FORWARDSSLMode number for SSL stream forwarding.- See Also:
MASTER
USAGE
The usage message printed on bad arguments.- See Also:
V3FORWARDPORT
private static final int V3FORWARDPORTDefault forward port for SAM version 3.- See Also:
V3DGPORT
private static final int V3DGPORTDefault datagram port for SAM version 3.- See Also:
Constructor Details
SAMStreamSink
public SAMStreamSink(I2PAppContext ctx, String samHost, String samPort, String destFile, String sinkDir) Holds the SAM bridge connection that received streams are written from.- Parameters:
ctx- the I2P contextsamHost- the hostname of the SAM bridgesamPort- the port of the SAM bridgedestFile- the file naming our own destinationsinkDir- the directory received streams are written to
Method Details
main
Command line entry point, connecting to a SAM bridge and writing streams to disk.- Parameters:
args- the command line: getopt flags, then the destination file and sink dir
startup
public void startup(String version, boolean isSSL, int mode, String user, String password, String sessionOpts) Connects to the bridge, handshakes, and starts the receiving threads.- Parameters:
version- the SAM protocol version to handshake with, e.g. "3.3"isSSL- true to use TLS when connecting to the SAM bridgemode- the stream mode constant, optionally plus MASTERuser- the bridge authentication user name, or null for nonepassword- the bridge authentication password, or null for nonesessionOpts- the comma-separated SAM session options
connect
Opens the connection to the SAM bridge.- Parameters:
isSSL- whether to connect over SSL- Returns:
- the connected socket
- Throws:
IOException- if the bridge cannot be reached
handshake
private String handshake(OutputStream samOut, String version, boolean isMaster, SAMEventHandler eventHandler, int mode, String user, String password, String sopts) Send the HELLO and log in.- Parameters:
samOut- where to write the HELLO and session commandsversion- maximum SAM protocol version to request, e.g. "3.3"isMaster- is this the control socketeventHandler- reads the HELLO and status replies from the socketmode- STREAM, FORWARD or FORWARDSSL, selects the initial STREAM command on a non-master socketuser- SAM authentication user, sent only together with a passwordpassword- SAM authentication password, sent only together with a usersopts- extra session options appended to the SESSION command- Returns:
- our b64 dest or null
writeDest
Writes our destination to the destination file.- Parameters:
dest- the destination to write- Returns:
- true on success