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

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

  • 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 our destination.
    • _sinkDir

      private final String _sinkDir
      Directory the received files are written to.
    • _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, SAMStreamSink.Sink> _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 receive.
      See Also:
    • DG

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

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

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

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

      private static final int RAWHDR
      Mode number for raw receive with headers.
      See Also:
    • FORWARD

      private static final int FORWARD
      Mode number for stream forwarding.
      See Also:
    • FORWARDSSL

      private static final int FORWARDSSL
      Mode number for SSL stream forwarding.
      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:
    • V3FORWARDPORT

      private static final int V3FORWARDPORT
      Default forward port for SAM version 3.
      See Also:
    • V3DGPORT

      private static final int V3DGPORT
      Default 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 context
      samHost - the hostname of the SAM bridge
      samPort - the port of the SAM bridge
      destFile - the file naming our own destination
      sinkDir - the directory received streams are written to
  • Method Details

    • main

      public static void main(String[] args)
      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 bridge
      mode - the stream mode constant, optionally plus MASTER
      user - the bridge authentication user name, or null for none
      password - the bridge authentication password, or null for none
      sessionOpts - the comma-separated SAM session options
    • 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 sopts)
      Send the HELLO and log in.
      Parameters:
      samOut - where to write the HELLO and session commands
      version - maximum SAM protocol version to request, e.g. "3.3"
      isMaster - is this the control socket
      eventHandler - reads the HELLO and status replies from the socket
      mode - STREAM, FORWARD or FORWARDSSL, selects the initial STREAM command on a non-master socket
      user - SAM authentication user, sent only together with a password
      password - SAM authentication password, sent only together with a user
      sopts - extra session options appended to the SESSION command
      Returns:
      our b64 dest or null
    • writeDest

      private boolean writeDest(String dest)
      Writes our destination to the destination file.
      Parameters:
      dest - the destination to write
      Returns:
      true on success