java.lang.Object
net.i2p.sam.client.SAMStreamSend

public class SAMStreamSendextends Object
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.

  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      Logger for the SAM client.
    • _samHost

      private final String _samHost
      Host of the SAM bridge.
    • _samPort

      private final String _samPort
      Port of the SAM bridge.
    • _destFile

      private final String _destFile
      File holding the peer destination.
    • _dataFile

      private final String _dataFile
      File holding the data to send.
    • _conOptions

      private String _conOptions
      Extra connection options from the command line.
    • _reader

      private SAMReader _reader
      Reader for the SAM session replies.
    • _reader2

      private SAMReader _reader2
      Reader for the second master session stream.
    • _isV3

      private boolean _isV3
      Whether SAM version 3 is used.
    • _isV32

      private boolean _isV32
      Whether SAM version 3.2 or later is used.
    • _v3ID

      private String _v3ID
      Session id used with SAM version 3.
    • _remotePeers

      private final Map<String, SAMStreamSend.Sender> _remotePeers
      Connection id (Integer) to peer (Flooder).
    • sslSocketFactory

      private static I2PSSLSocketFactory sslSocketFactory
      Factory for the SSL bridge connections.
    • STREAM

      private static final int STREAM
      Mode number for stream send.
      See Also:
    • DG

      private static final int DG
      Mode number for datagram send.
      See Also:
    • V1DG

      private static final int V1DG
      Mode number for version 1 datagram send.
      See Also:
    • RAW

      private static final int RAW
      Mode number for raw send.
      See Also:
    • V1RAW

      private static final int V1RAW
      Mode number for version 1 raw send.
      See Also:
    • MASTER

      private static final int MASTER
      Mode number for a master session.
      See Also:
    • USAGE

      private static final String 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 manager
      samHost - the host name or address of the SAM bridge to connect to
      samPort - the SAM bridge port, as a string because it comes from the command line
      destFile - path to the file holding the destination private key to send from
      dataFile - path to the file whose bytes are streamed over the resulting tunnel
  • Method Details

    • main

      public static void main(String[] args)
      Streams a file over a SAM stream connect, for testing the bridge.
      Parameters:
      args - the command line options parsed by Getopt; the last two name the files
    • 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 password
      isSSL - true to connect to the bridge over TLS rather than plaintext
      mode - the stream connect mode, one of STREAM, PACKET or STREAM_RAW, optionally or'ed with MASTER to use a master session
      user - the bridge username, or null when the bridge requires no authentication
      password - the password matching user, or null for no authentication
      sessionOpts - space separated session options appended to the STREAM CONNECT command
    • connect

      private Socket connect(boolean isSSL) throws IOException
      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 to
      version - the maximum SAM version to request, e.g. "3.5"
      isMaster - is this the control socket
      eventHandler - the handler that waits for the HELLO reply and later events
      mode - the session mode, one of the STREAM, DG, V1DG or V1RAW constants, with the MASTER bit added for a master session
      user - the SAM user name to log in with, null if no authentication
      password - the SAM password to log in with, null if no authentication
      opts - extra SESSION CREATE options to append, may be empty
      Returns:
      our b64 dest or null
    • send

      private void send(OutputStream samOut, SAMEventHandler eventHandler, int mode) throws IOException
      Sends the data file over the SAM session.
      Parameters:
      samOut - the SAM command stream
      eventHandler - handler for the session events
      mode - the send mode
      Throws:
      IOException - if the send fails