java.lang.Object
net.i2p.sam.client.SAMStreamSend
Swiss army knife tester. Sends a file (datafile) to a peer (b64 dest in peerDestFile).
Usage: SAMStreamSend [options] peerDestFile dataFile
See apps/sam/doc/README-test.txt for info on test setup. Sends data in one of 5 modes. Optionally uses SSL. Configurable SAM client version.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classOne open SAM session sending data.private classHandles session events for the send.Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringExtra connection options from the command line.private final I2PAppContextThe app context.private final StringFile holding the data to send.private final StringFile holding the peer 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, SAMStreamSend.Sender> Connection id (Integer) to peer (Flooder).private final StringHost of the SAM bridge.private final StringPort of the SAM bridge.private StringSession id used with SAM version 3.private static final intMode number for datagram send.private static final intMode number for a master session.private static final intMode number for raw send.private static I2PSSLSocketFactoryFactory for the SSL bridge connections.private static final intMode number for stream send.private static final StringThe usage message printed on bad arguments.private static final intMode number for version 1 datagram send.private static final intMode number for version 1 raw send.Constructor Summary
ConstructorsConstructorDescriptionSAMStreamSend(I2PAppContext ctx, String samHost, String samPort, String destFile, String dataFile) Holds the command line arguments for one stream send.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 opts) Send the HELLO and log in.static voidStreams a file over a SAM stream connect, for testing the bridge.private voidsend(OutputStream samOut, SAMEventHandler eventHandler, int mode) Sends the data file over the SAM session.voidNegotiates a SAM session and connects it to the destination stream.
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 the peer destination._dataFile
File holding the data to send._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
RAW
V1RAW
MASTER
USAGE
The usage message printed on bad arguments.- See Also:
Constructor Details
SAMStreamSend
public SAMStreamSend(I2PAppContext ctx, String samHost, String samPort, String destFile, String dataFile) Holds the command line arguments for one stream send.- Parameters:
ctx- the application context supplying the log managersamHost- the host name or address of the SAM bridge to connect tosamPort- the SAM bridge port, as a string because it comes from the command linedestFile- path to the file holding the destination private key to send fromdataFile- path to the file whose bytes are streamed over the resulting tunnel
Method Details
main
startup
public void startup(String version, boolean isSSL, int mode, String user, String password, String sessionOpts) Negotiates a SAM session and connects it to the destination stream.- Parameters:
version- the SAM protocol version to negotiate, at least 3.2 for user and passwordisSSL- true to connect to the bridge over TLS rather than plaintextmode- the stream connect mode, one of STREAM, PACKET or STREAM_RAW, optionally or'ed with MASTER to use a master sessionuser- the bridge username, or null when the bridge requires no authenticationpassword- the password matchinguser, or null for no authenticationsessionOpts- space separated session options appended to the STREAM CONNECT command
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 opts) Send the HELLO and log in.- Parameters:
samOut- the stream to write the HELLO and session commands toversion- the maximum SAM version to request, e.g. "3.5"isMaster- is this the control socketeventHandler- the handler that waits for the HELLO reply and later eventsmode- the session mode, one of the STREAM, DG, V1DG or V1RAW constants, with the MASTER bit added for a master sessionuser- the SAM user name to log in with, null if no authenticationpassword- the SAM password to log in with, null if no authenticationopts- extra SESSION CREATE options to append, may be empty- Returns:
- our b64 dest or null
send
Sends the data file over the SAM session.- Parameters:
samOut- the SAM command streameventHandler- handler for the session eventsmode- the send mode- Throws:
IOException- if the send fails