Changeset 9f433b2e


Ignore:
Timestamp:
Jul 14, 2011 6:53:10 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
252f1047
Parents:
0ca035d
Message:
  • Streaming:
    • Hook I2CP ports through to I2PSocket
    • Javadocs, init cleanups, final
Location:
apps
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java

    r0ca035d r9f433b2e  
    7171
    7272    public void setSocketErrorListener(SocketErrorListener lsnr);
     73
     74    /**
     75     *  The remote port.
     76     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     77     *  @since 0.8.9
     78     */
     79    public int getPort();
     80
     81    /**
     82     *  The local port.
     83     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     84     *  @since 0.8.9
     85     */
     86    public int getLocalPort();
     87
    7388    /**
    7489     * Allow notification of underlying errors communicating across I2P without
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java

    r0ca035d r9f433b2e  
    88import net.i2p.I2PAppContext;
    99import net.i2p.I2PException;
     10import net.i2p.client.I2PSession;
    1011import net.i2p.client.I2PSessionException;
    1112import net.i2p.data.Destination;
     
    301302    public long getCreatedOn() { return _createdOn; }
    302303    public long getClosedOn() { return _closedOn; }
     304   
     305    /**
     306     * The remote port.
     307     * @return 0 always
     308     * @since 0.8.9
     309     */
     310    public int getPort() {
     311        return I2PSession.PORT_UNSPECIFIED;
     312    }
     313
     314    /**
     315     * The local port.
     316     * @return 0 always
     317     * @since 0.8.9
     318     */
     319    public int getLocalPort() {
     320        return I2PSession.PORT_UNSPECIFIED;
     321    }
    303322   
    304323   
     
    672691        }
    673692    }
    674    
     693
    675694    @Override
    676695    public String toString() { return "" + hashCode(); }
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java

    r0ca035d r9f433b2e  
    9191     * stream and connected to the default I2CP host and port.
    9292     *
    93      * @param myPrivateKeyStream private key stream
     93     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    9494     * @return the newly created socket manager, or null if there were errors
    9595     */
     
    102102     * stream and connected to the default I2CP host and port.
    103103     *
    104      * @param myPrivateKeyStream private key stream
     104     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    105105     * @param opts I2CP options
    106106     * @return the newly created socket manager, or null if there were errors
     
    115115     * port
    116116     *
    117      * @param myPrivateKeyStream private key stream
     117     * @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
    118118     * @param i2cpHost I2CP host
    119119     * @param i2cpPort I2CP port
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java

    r0ca035d r9f433b2e  
    33/**
    44 * Define the configuration for streaming and verifying data on the socket.
    5  *
     5 * Use I2PSocketManager.buildOptions() to get one of these.
    66 */
    77public interface I2PSocketOptions {
     
    8282     */
    8383    public void setWriteTimeout(long ms);
     84
     85    /**
     86     *  The remote port.
     87     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     88     *  @since 0.8.9
     89     */
     90    public int getPort();
     91
     92    /**
     93     *  The remote port.
     94     *  @param port 0 - 65535
     95     *  @since 0.8.9
     96     */
     97    public void setPort(int port);
     98
     99    /**
     100     *  The local port.
     101     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     102     *  @since 0.8.9
     103     */
     104    public int getLocalPort();
     105
     106    /**
     107     *  The local port.
     108     *  @param port 0 - 65535
     109     *  @since 0.8.9
     110     */
     111    public void setLocalPort(int port);
    84112}
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptionsImpl.java

    r0ca035d r9f433b2e  
    55/**
    66 * Define the configuration for streaming and verifying data on the socket.
    7  *
     7 * Use I2PSocketManager.buildOptions() to get one of these.
    88 */
    99class I2PSocketOptionsImpl implements I2PSocketOptions {
     
    1212    private long _writeTimeout;
    1313    private int _maxBufferSize;
     14    private int _localPort;
     15    private int _remotePort;
    1416   
    1517    public static final int DEFAULT_BUFFER_SIZE = 1024*64;
     
    1719    public static final int DEFAULT_CONNECT_TIMEOUT = 60*1000;
    1820   
     21    /**
     22     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     23     *  from System properties. Does not set local port or remote port.
     24     */
    1925    public I2PSocketOptionsImpl() {
    2026        this(System.getProperties());
    2127    }
    2228   
     29    /**
     30     *  Initializes from System properties then copies over all options.
     31     *  @param opts may be null
     32     */
    2333    public I2PSocketOptionsImpl(I2PSocketOptions opts) {
    2434        this(System.getProperties());
     
    2838            _writeTimeout = opts.getWriteTimeout();
    2939            _maxBufferSize = opts.getMaxBufferSize();
     40            _localPort = opts.getLocalPort();
     41            _remotePort = opts.getPort();
    3042        }
    3143    }
    3244
     45    /**
     46     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     47     *  from properties. Does not set local port or remote port.
     48     *  @param opts may be null
     49     */
    3350    public I2PSocketOptionsImpl(Properties opts) {
    3451        init(opts);
    3552    }
    3653   
     54    /**
     55     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     56     *  from properties. Does not set local port or remote port.
     57     *  @param opts may be null
     58     */
    3759    public void setProperties(Properties opts) {
    3860        if (opts == null) return;
     
    4769    }
    4870   
     71    /**
     72     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     73     *  from properties. Does not set local port or remote port.
     74     */
    4975    protected void init(Properties opts) {
    5076        _maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
     
    145171        _writeTimeout = ms;
    146172    }
     173
     174    /**
     175     *  The remote port.
     176     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     177     *  @since 0.8.9
     178     */
     179    public int getPort() {
     180        return _remotePort;
     181    }
     182
     183    /**
     184     *  The remote port.
     185     *  @param port 0 - 65535
     186     *  @since 0.8.9
     187     */
     188    public void setPort(int port) {
     189        _remotePort = port;
     190    }
     191
     192    /**
     193     *  The local port.
     194     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     195     *  @since 0.8.9
     196     */
     197    public int getLocalPort() {
     198        return _localPort;
     199    }
     200
     201    /**
     202     *  The local port.
     203     *  @param port 0 - 65535
     204     *  @since 0.8.9
     205     */
     206    public void setLocalPort(int port) {
     207        _localPort = port;
     208    }
    147209}
  • apps/streaming/java/src/net/i2p/client/streaming/Connection.java

    r0ca035d r9f433b2e  
    2424 */
    2525class Connection {
    26     private I2PAppContext _context;
    27     private Log _log;
    28     private ConnectionManager _connectionManager;
     26    private final I2PAppContext _context;
     27    private final Log _log;
     28    private final ConnectionManager _connectionManager;
    2929    private Destination _remotePeer;
    3030    private long _sendStreamId;
    3131    private long _receiveStreamId;
    3232    private long _lastSendTime;
    33     private AtomicLong _lastSendId;
     33    private final AtomicLong _lastSendId;
    3434    private boolean _resetReceived;
    3535    private boolean _resetSent;
     
    3737    private boolean _connected;
    3838    private boolean _hardDisconnected;
    39     private MessageInputStream _inputStream;
    40     private MessageOutputStream _outputStream;
    41     private SchedulerChooser _chooser;
     39    private final MessageInputStream _inputStream;
     40    private final MessageOutputStream _outputStream;
     41    private final SchedulerChooser _chooser;
    4242    private long _nextSendTime;
    4343    private long _ackedPackets;
    44     private long _createdOn;
     44    private final long _createdOn;
    4545    private long _closeSentOn;
    4646    private long _closeReceivedOn;
     
    5252    /** Packet ID (Long) to PacketLocal for sent but unacked packets */
    5353    private final Map<Long, PacketLocal> _outboundPackets;
    54     private PacketQueue _outboundQueue;
    55     private ConnectionPacketHandler _handler;
     54    private final PacketQueue _outboundQueue;
     55    private final ConnectionPacketHandler _handler;
    5656    private ConnectionOptions _options;
    57     private ConnectionDataReceiver _receiver;
     57    private final ConnectionDataReceiver _receiver;
    5858    private I2PSocketFull _socket;
    5959    /** set to an error cause if the connection could not be established */
     
    7171    /** how many messages have been resent and not yet ACKed? */
    7272    private int _activeResends;
    73     private ConEvent _connectionEvent;
    74     private int _randomWait;
     73    private final ConEvent _connectionEvent;
     74    private final int _randomWait;
     75    private int _localPort;
     76    private int _remotePort;
    7577   
    7678    private long _lifetimeBytesSent;
     
    8789    public static final int MAX_WINDOW_SIZE = 128;
    8890   
    89     public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser, PacketQueue queue, ConnectionPacketHandler handler) {
     91    public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser,
     92                      PacketQueue queue, ConnectionPacketHandler handler) {
    9093        this(ctx, manager, chooser, queue, handler, null);
    9194    }
    92     public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser, PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts) {
     95
     96    public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser,
     97                      PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts) {
    9398        _context = ctx;
    9499        _connectionManager = manager;
     
    102107        _outputStream = new MessageOutputStream(_context, _receiver, (opts == null ? Packet.MAX_PAYLOAD_SIZE : opts.getMaxMessageSize()));
    103108        _outboundPackets = new TreeMap();
     109        if (opts != null) {
     110            _localPort = opts.getLocalPort();
     111            _remotePort = opts.getPort();
     112        }
    104113        _options = (opts != null ? opts : new ConnectionOptions());
    105114        _outputStream.setWriteTimeout((int)_options.getWriteTimeout());
     
    107116        _lastSendId = new AtomicLong(-1);
    108117        _nextSendTime = -1;
    109         _ackedPackets = 0;
    110118        _createdOn = _context.clock().now();
    111119        _closeSentOn = -1;
    112120        _closeReceivedOn = -1;
    113         _unackedPacketsReceived = 0;
    114121        _congestionWindowEnd = _options.getWindowSize()-1;
    115122        _highestAckedThrough = -1;
     
    117124        _lastCongestionTime = -1;
    118125        _lastCongestionHighestUnacked = -1;
    119         _resetReceived = false;
    120126        _connected = true;
    121127        _disconnectScheduledOn = -1;
     
    124130        _ackSinceCongestion = true;
    125131        _connectLock = new Object();
    126         _activeResends = 0;
    127132        _resetSentOn = -1;
    128         _isInbound = false;
    129         _updatedShareOpts = false;
    130133        _connectionEvent = new ConEvent();
    131         _hardDisconnected = false;
    132134        _randomWait = _context.random().nextInt(10*1000); // just do this once to reduce usage
    133135        _context.statManager().createRateStat("stream.con.windowSizeAtCongestion", "How large was our send window when we send a dup?", "Stream", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
     
    679681    public void setSocket(I2PSocketFull socket) { _socket = socket; }
    680682   
     683    /**
     684     * The remote port.
     685     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     686     *  @since 0.8.9
     687     */
     688    public int getPort() {
     689        return _remotePort;
     690    }
     691
     692    /**
     693     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     694     *  @since 0.8.9
     695     */
     696    public int getLocalPort() {
     697        return _localPort;
     698    }
     699
    681700    public String getConnectionError() { return _connectionError; }
    682701    public void setConnectionError(String err) { _connectionError = err; }
     
    782801   
    783802    public int getLastCongestionSeenAt() { return _lastCongestionSeenAt; }
    784    
     803
    785804    void congestionOccurred() {
    786805        // if we hit congestion and e.g. 5 packets are resent,
     
    963982     */
    964983    public MessageInputStream getInputStream() { return _inputStream; }
     984
    965985    /** stream that the local peer sends data to the remote peer on
    966986     * @return the outbound message stream
    967987     */
    968988    public MessageOutputStream getOutputStream() { return _outputStream; }
    969    
    970         @Override
     989
     990    @Override
    971991    public String toString() {
    972992        StringBuilder buf = new StringBuilder(128);
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionDataReceiver.java

    r0ca035d r9f433b2e  
    1414 */
    1515class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
    16     private I2PAppContext _context;
    17     private Log _log;
    18     private Connection _connection;
     16    private final I2PAppContext _context;
     17    private final Log _log;
     18    private final Connection _connection;
    1919    private static final MessageOutputStream.WriteStatus _dummyStatus = new DummyStatus();
    2020   
     21    /**
     22     *  @param con non-null
     23     */
    2124    public ConnectionDataReceiver(I2PAppContext ctx, Connection con) {
    2225        _context = ctx;
     
    4245     */
    4346    public boolean writeInProcess() {
    44         Connection con = _connection;
    45         if (con != null)
    46             return con.getUnackedPacketsSent() >= con.getOptions().getWindowSize();
    47         return false;
     47        return _connection.getUnackedPacketsSent() >= _connection.getOptions().getWindowSize();
    4848    }
    4949   
     
    6161    public MessageOutputStream.WriteStatus writeData(byte[] buf, int off, int size) {
    6262        Connection con = _connection;
    63         if (con == null) return _dummyStatus;
     63        //if (con == null) return _dummyStatus;
    6464        boolean doSend = true;
    6565        if ( (size <= 0) && (con.getLastSendId() >= 0) ) {
     
    122122    public PacketLocal send(byte buf[], int off, int size, boolean forceIncrement) {
    123123        Connection con = _connection;
    124         if (con == null) return null;
     124        //if (con == null) return null;
    125125        long before = System.currentTimeMillis();
    126126        PacketLocal packet = buildPacket(con, buf, off, size, forceIncrement);
     
    186186            packet.setOptionalFrom(con.getSession().getMyDestination());
    187187            packet.setOptionalMaxSize(con.getOptions().getMaxMessageSize());
     188            packet.setLocalPort(con.getLocalPort());
     189            packet.setRemotePort(con.getPort());
    188190        }
    189191        if (con.getSendStreamId() == Packet.STREAM_ID_UNKNOWN) {
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionHandler.java

    r0ca035d r9f433b2e  
    1919 */
    2020class ConnectionHandler {
    21     private I2PAppContext _context;
    22     private Log _log;
    23     private ConnectionManager _manager;
    24     private LinkedBlockingQueue<Packet> _synQueue;
     21    private final I2PAppContext _context;
     22    private final Log _log;
     23    private final ConnectionManager _manager;
     24    private final LinkedBlockingQueue<Packet> _synQueue;
    2525    private boolean _active;
    2626    private int _acceptTimeout;
     
    4242        _manager = mgr;
    4343        _synQueue = new LinkedBlockingQueue<Packet>(MAX_QUEUE_SIZE);
    44         _active = false;
    4544        _acceptTimeout = DEFAULT_ACCEPT_TIMEOUT;
    4645    }
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    r0ca035d r9f433b2e  
    2222 */
    2323class ConnectionManager {
    24     private I2PAppContext _context;
    25     private Log _log;
    26     private I2PSession _session;
    27     private MessageHandler _messageHandler;
    28     private PacketHandler _packetHandler;
    29     private ConnectionHandler _connectionHandler;
    30     private PacketQueue _outboundQueue;
    31     private SchedulerChooser _schedulerChooser;
    32     private ConnectionPacketHandler _conPacketHandler;
    33     private TCBShare _tcbShare;
     24    private final I2PAppContext _context;
     25    private final Log _log;
     26    private final I2PSession _session;
     27    private final MessageHandler _messageHandler;
     28    private final PacketHandler _packetHandler;
     29    private final ConnectionHandler _connectionHandler;
     30    private final PacketQueue _outboundQueue;
     31    private final SchedulerChooser _schedulerChooser;
     32    private final ConnectionPacketHandler _conPacketHandler;
     33    private final TCBShare _tcbShare;
    3434    /** Inbound stream ID (Long) to Connection map */
    35     private ConcurrentHashMap<Long, Connection> _connectionByInboundId;
     35    private final ConcurrentHashMap<Long, Connection> _connectionByInboundId;
    3636    /** Ping ID (Long) to PingRequest */
    3737    private final Map<Long, PingRequest> _pendingPings;
     
    3939    private boolean _throttlersInitialized;
    4040    private int _maxConcurrentStreams;
    41     private ConnectionOptions _defaultOptions;
     41    private final ConnectionOptions _defaultOptions;
    4242    private volatile int _numWaiting;
    4343    private long _soTimeout;
     
    6060        _conPacketHandler = new ConnectionPacketHandler(_context);
    6161        _tcbShare = new TCBShare(_context);
    62         _session.setSessionListener(_messageHandler);
     62        // PROTO_ANY is for backward compatibility (pre-0.7.1)
     63        // TODO change proto to PROTO_STREAMING someday.
     64        // Right now we get everything, and rely on Datagram to specify PROTO_UDP.
     65        // PacketQueue has sent PROTO_STREAMING since the beginning of mux support (0.7.1)
     66        _session.addMuxedSessionListener(_messageHandler, I2PSession.PROTO_ANY, I2PSession.PORT_ANY);
    6367        _outboundQueue = new PacketQueue(_context, _session, this);
    64         _allowIncoming = false;
    65         _numWaiting = 0;
    6668        /** Socket timeout for accept() */
    6769        _soTimeout = -1;
     
    142144     */
    143145    public Connection receiveConnection(Packet synPacket) {
    144         Connection con = new Connection(_context, this, _schedulerChooser, _outboundQueue, _conPacketHandler, new ConnectionOptions(_defaultOptions));
     146        ConnectionOptions opts = new ConnectionOptions(_defaultOptions);
     147        opts.setPort(synPacket.getRemotePort());
     148        opts.setLocalPort(synPacket.getLocalPort());
     149        Connection con = new Connection(_context, this, _schedulerChooser, _outboundQueue, _conPacketHandler, opts);
    145150        _tcbShare.updateOptsFromShare(con);
    146151        con.setInbound();
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java

    r0ca035d r9f433b2e  
    107107     *  some parts that could use more research.
    108108     *
     109     *<pre>
    109110     *  1024 Tunnel Message
    110111     *  - 21 Header (see router/tunnel/BatchedPreprocessor.java)
     
    170171     *   3 msgs: 2722
    171172     *   4 msgs: 3714
    172      *
     173     *</pre>
    173174     *
    174175     * Before release 0.6.1.14 this was 4096.
     
    206207    public static final int MIN_MESSAGE_SIZE = 512;
    207208
     209    /**
     210     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     211     *  from System properties. Does not set local port or remote port.
     212     */
    208213    public ConnectionOptions() {
    209214        super();
    210215    }
    211216   
     217    /**
     218     *  Sets max buffer size, connect timeout, read timeout, and write timeout
     219     *  from properties. Does not set local port or remote port.
     220     *  @param opts may be null
     221     */
    212222    public ConnectionOptions(Properties opts) {
    213223        super(opts);
    214224    }
    215225   
     226    /**
     227     *  Initializes from System properties then copies over all options.
     228     *  @param opts may be null
     229     */
    216230    public ConnectionOptions(I2PSocketOptions opts) {
    217231        super(opts);
    218232    }
    219233   
     234    /**
     235     *  Initializes from System properties then copies over all options.
     236     *  @param opts may be null
     237     */
    220238    public ConnectionOptions(ConnectionOptions opts) {
    221239        super(opts);
     
    236254            setCongestionAvoidanceGrowthRateFactor(opts.getCongestionAvoidanceGrowthRateFactor());
    237255            setSlowStartGrowthRateFactor(opts.getSlowStartGrowthRateFactor());
    238             setWriteTimeout(opts.getWriteTimeout());
    239             setReadTimeout(opts.getReadTimeout());
     256            // handled in super()
     257            // not clear why added by jr 12/22/2005
     258            //setWriteTimeout(opts.getWriteTimeout());
     259            //setReadTimeout(opts.getReadTimeout());
    240260            setAnswerPings(opts.getAnswerPings());
    241261            initLists(opts);
     
    249269    }
    250270   
    251         @Override
     271    @Override
    252272    protected void init(Properties opts) {
    253273        super.init(opts);
     
    263283        setWindowSize(getInt(opts, PROP_INITIAL_WINDOW_SIZE, INITIAL_WINDOW_SIZE));
    264284        setMaxResends(getInt(opts, PROP_MAX_RESENDS, DEFAULT_MAX_SENDS));
    265         setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
     285        // handled in super()
     286        //setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
    266287        setInactivityTimeout(getInt(opts, PROP_INACTIVITY_TIMEOUT, 90*1000));
    267288        setInactivityAction(getInt(opts, PROP_INACTIVITY_ACTION, INACTIVITY_ACTION_SEND));
     
    269290        setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 1));
    270291        setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 1));
     292        // overrides default in super()
    271293        setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
    272294        setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
     
    280302    }
    281303   
    282         @Override
     304    @Override
    283305    public void setProperties(Properties opts) {
    284306        super.setProperties(opts);
     
    304326        if (opts.containsKey(PROP_MAX_RESENDS))
    305327            setMaxResends(getInt(opts, PROP_MAX_RESENDS, DEFAULT_MAX_SENDS));
    306         if (opts.containsKey(PROP_WRITE_TIMEOUT))
    307             setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
     328        // handled in super()
     329        //if (opts.containsKey(PROP_WRITE_TIMEOUT))
     330        //    setWriteTimeout(getInt(opts, PROP_WRITE_TIMEOUT, -1));
    308331        if (opts.containsKey(PROP_INACTIVITY_TIMEOUT))
    309332            setInactivityTimeout(getInt(opts, PROP_INACTIVITY_TIMEOUT, 90*1000));
     
    317340        if (opts.containsKey(PROP_CONNECT_TIMEOUT))
    318341            // wow 5 minutes!!! FIXME!!
     342            // overrides default in super()
    319343            setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
    320344        if (opts.containsKey(PROP_ANSWER_PINGS))
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java

    r0ca035d r9f433b2e  
    1616 */
    1717class ConnectionPacketHandler {
    18     private I2PAppContext _context;
    19     private Log _log;
     18    private final I2PAppContext _context;
     19    private final Log _log;
    2020   
    2121    public ConnectionPacketHandler(I2PAppContext context) {
  • apps/streaming/java/src/net/i2p/client/streaming/I2PServerSocketFull.java

    r0ca035d r9f433b2e  
    99 */
    1010class I2PServerSocketFull implements I2PServerSocket {
    11     private I2PSocketManagerFull _socketManager;
     11    private final I2PSocketManagerFull _socketManager;
    1212   
    1313    public I2PServerSocketFull(I2PSocketManagerFull mgr) {
  • apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java

    r0ca035d r9f433b2e  
    55import java.io.OutputStream;
    66
     7import net.i2p.client.I2PSession;
    78import net.i2p.data.Destination;
    89
     
    128129            c.disconnectComplete();
    129130    }
    130         @Override
     131   
     132    /**
     133     * The remote port.
     134     * @return the port or 0 if unknown
     135     * @since 0.8.9
     136     */
     137    public int getPort() {
     138        Connection c = _connection;
     139        return c == null ? I2PSession.PORT_UNSPECIFIED : c.getPort();
     140    }
     141
     142    /**
     143     * The local port.
     144     * @return the port or 0 if unknown
     145     * @since 0.8.9
     146     */
     147    public int getLocalPort() {
     148        Connection c = _connection;
     149        return c == null ? I2PSession.PORT_UNSPECIFIED : c.getLocalPort();
     150    }
     151
     152    @Override
    131153    public String toString() {
    132154        Connection c = _connection;
  • apps/streaming/java/src/net/i2p/client/streaming/MessageHandler.java

    r0ca035d r9f433b2e  
    88import net.i2p.client.I2PSession;
    99import net.i2p.client.I2PSessionException;
    10 import net.i2p.client.I2PSessionListener;
     10import net.i2p.client.I2PSessionMuxedListener;
    1111import net.i2p.util.Log;
    1212
     
    1616 *
    1717 */
    18 class MessageHandler implements I2PSessionListener {
    19     private ConnectionManager _manager;
    20     private I2PAppContext _context;
    21     private Log _log;
     18class MessageHandler implements I2PSessionMuxedListener {
     19    private final ConnectionManager _manager;
     20    private final I2PAppContext _context;
     21    private final Log _log;
    2222    private final Set<I2PSocketManager.DisconnectListener> _listeners;
    2323   
     
    3232    /** Instruct the client that the given session has received a message with
    3333     * size # of bytes.
     34     * This shouldn't be called anymore since we are registering as a muxed listener.
    3435     * @param session session to notify
    3536     * @param msgId message number available
     
    3738     */
    3839    public void messageAvailable(I2PSession session, int msgId, long size) {
     40        messageAvailable(session, msgId, size, I2PSession.PROTO_UNSPECIFIED,
     41                         I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
     42    }
     43
     44    /** Instruct the client that the given session has received a message with
     45     * size # of bytes.
     46     * @param session session to notify
     47     * @param msgId message number available
     48     * @param size size of the message
     49     */
     50    public void messageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort) {
    3951        byte data[] = null;
    4052        try {
     
    5062        try {
    5163            packet.readPacket(data, 0, data.length);
     64            packet.setRemotePort(fromPort);
     65            packet.setLocalPort(toPort);
    5266            _manager.getPacketHandler().receivePacket(packet);
    5367        } catch (IllegalArgumentException iae) {
  • apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java

    r0ca035d r9f433b2e  
    6464        _dataReceiver = receiver;
    6565        _dataLock = new Object();
    66         _written = 0;
    67         _closed = false;
    6866        _writeTimeout = -1;
    6967        _passiveFlushDelay = passiveFlushDelay;
    7068        _nextBufferSize = -1;
    7169        _sendPeriodBeginTime = ctx.clock().now();
    72         _sendPeriodBytes = 0;
    73         _sendBps = 0;
    7470        _context.statManager().createRateStat("stream.sendBps", "How fast we pump data through the stream", "Stream", new long[] { 60*1000, 5*60*1000, 60*60*1000 });
    7571        _flusher = new Flusher();
  • apps/streaming/java/src/net/i2p/client/streaming/Packet.java

    r0ca035d r9f433b2e  
    1414
    1515/**
     16 * This contains solely the data that goes out on the wire,
     17 * including the local and remote port which is embedded in
     18 * the I2CP overhead, not in the packet itself.
     19 * For local state saved for outbound packets, see PacketLocal.
     20 *
     21 * <p>
     22 *
    1623 * Contain a single packet transferred as part of a streaming connection. 
    1724 * The data format is as follows:<ul>
     
    6875    private int _optionDelay;
    6976    private int _optionMaxSize;
     77    private int _localPort;
     78    private int _remotePort;
    7079   
    7180    /**
     
    149158    protected static final int MAX_DELAY_REQUEST = 65535;
    150159
     160    /**
     161     *  Does no initialization.
     162     *  See readPacket() for inbound packets, and the setters for outbound packets.
     163     */
    151164    public Packet() { }
    152165   
     
    317330    }
    318331   
     332    /**
     333     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     334     *  @since 0.8.9
     335     */
     336    public int getLocalPort() {
     337        return _localPort;
     338    }
     339
     340    /**
     341     *  Must be called to change the port, not set by readPacket()
     342     *  as the port is out-of-band in the I2CP header.
     343     *  @since 0.8.9
     344     */
     345    public void setLocalPort(int port) {
     346        _localPort = port;
     347    }
     348   
     349    /**
     350     *  @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
     351     *  @since 0.8.9
     352     */
     353    public int getRemotePort() {
     354        return _remotePort;
     355    }
     356
     357    /**
     358     *  Must be called to change the port, not set by readPacket()
     359     *  as the port is out-of-band in the I2CP header.
     360     *  @since 0.8.9
     361     */
     362    public void setRemotePort(int port) {
     363        _remotePort = port;
     364    }
     365
    319366    /**
    320367     * Write the packet to the buffer (starting at the offset) and return
  • apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java

    r0ca035d r9f433b2e  
    1717 */
    1818class PacketHandler {
    19     private ConnectionManager _manager;
    20     private I2PAppContext _context;
    21     private Log _log;
     19    private final ConnectionManager _manager;
     20    private final I2PAppContext _context;
     21    private final Log _log;
    2222    //private int _lastDelay;
    2323    //private int _dropped;
  • apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java

    r0ca035d r9f433b2e  
    1414 */
    1515class PacketLocal extends Packet implements MessageOutputStream.WriteStatus {
    16     private I2PAppContext _context;
    17     private Log _log;
    18     private Connection _connection;
     16    private final I2PAppContext _context;
     17    private final Log _log;
     18    private final Connection _connection;
    1919    private Destination _to;
    2020    private SessionKey _keyUsed;
    2121    private Set _tagsSent;
    22     private long _createdOn;
     22    private final long _createdOn;
    2323    private int _numSends;
    2424    private long _lastSend;
     
    3030    private SimpleTimer2.TimedEvent _resendEvent;
    3131   
     32    /** not bound to a connection */
    3233    public PacketLocal(I2PAppContext ctx, Destination to) {
    3334        this(ctx, to, null);
    3435    }
     36
    3537    public PacketLocal(I2PAppContext ctx, Destination to, Connection con) {
    3638        _context = ctx;
     
    4143        _lastSend = -1;
    4244        _cancelledOn = -1;
    43         _nackCount = 0;
    44         _retransmitted = false;
    4545    }
    4646   
     
    139139    public int getNumSends() { return _numSends; }
    140140    public long getLastSend() { return _lastSend; }
     141
     142    /** @return null if not bound */
    141143    public Connection getConnection() { return _connection; }
    142144
  • apps/streaming/java/src/net/i2p/client/streaming/PacketQueue.java

    r0ca035d r9f433b2e  
    2020 */
    2121class PacketQueue {
    22     private I2PAppContext _context;
    23     private Log _log;
    24     private I2PSession _session;
    25     private ConnectionManager _connectionManager;
    26     private ByteCache _cache = ByteCache.getInstance(64, 36*1024);
     22    private final I2PAppContext _context;
     23    private final Log _log;
     24    private final I2PSession _session;
     25    private final ConnectionManager _connectionManager;
     26    private final ByteCache _cache = ByteCache.getInstance(64, 36*1024);
    2727   
    2828    public PacketQueue(I2PAppContext context, I2PSession session, ConnectionManager mgr) {
     
    9999                // I2PSessionMuxedImpl no tags
    100100                sent = _session.sendMessage(packet.getTo(), buf, 0, size, null, null, expires,
    101                                  I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
     101                                 I2PSession.PROTO_STREAMING, packet.getLocalPort(), packet.getRemotePort());
    102102            else
    103103                // I2PSessionImpl2
     
    108108                // I2PSessionMuxedImpl no tags
    109109                sent = _session.sendMessage(packet.getTo(), buf, 0, size, null, null,
    110                                  I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
     110                                 I2PSession.PROTO_STREAMING, packet.getLocalPort(), packet.getRemotePort());
    111111            end = _context.clock().now();
    112112           
  • apps/streaming/java/src/net/i2p/client/streaming/StandardSocket.java

    r0ca035d r9f433b2e  
    108108
    109109    /**
    110      *  @return -1 always
     110     *  @return the port or 0 if unknown
    111111     */
    112112    @Override
    113113    public int getLocalPort() {
    114         return -1;
     114        return _socket.getLocalPort();
    115115    }
    116116
     
    140140
    141141    /**
    142      *  @return 0 always
     142     *  @return the port or 0 if unknown
    143143     */
    144144    @Override
    145145    public int getPort() {
    146         return 0;
     146        return _socket.getPort();
    147147    }
    148148
  • apps/streaming/java/src/net/i2p/client/streaming/TCBShare.java

    r0ca035d r9f433b2e  
    2222 */
    2323class TCBShare {
    24     private I2PAppContext _context;
    25     private Log _log;
    26     private Map<Destination, Entry> _cache;
    27     private CleanEvent _cleaner;
     24    private final I2PAppContext _context;
     25    private final Log _log;
     26    private final Map<Destination, Entry> _cache;
     27    private final CleanEvent _cleaner;
    2828
    2929    private static final long EXPIRE_TIME = 30*60*1000;
Note: See TracChangeset for help on using the changeset viewer.