net.i2p.client.streaming.impl

## Class ConnectionManager

- java.lang.Object
- - net.i2p.client.streaming.impl.ConnectionManager

-     class ConnectionManager
      extends Object

  Coordinate all of the connections for a single local destination.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `ConnectionManager.PingNotifier` The callback interface for a pong.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_BLACKLIST`
    `(package private) static String` | `PROP_MAX_PONG_DELAY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConnectionManager(I2PAppContext context, I2PSession session, ConnectionOptions defaultOptions, IncomingConnectionFilter connectionFilter)` Manage all conns for this session

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `answerPings()` do we respond to pings that aren't on an existing connection?
    `Connection` | `connect(Destination peer, ConnectionOptions opts, I2PSession session)` Build a new connection to the given peer.
    `void` | `disconnectAllHard()` Something b0rked hard, so kill all of our connections without mercy.
    `boolean` | `getAllowIncomingConnections()`
    `(package private) Connection` | `getConnectionByInboundId(long id)`
    `(package private) Connection` | `getConnectionByOutboundId(long id)` not guaranteed to be unique, but in case we receive more than one packet on an inbound connection that we havent ack'ed yet...
    `ConnectionHandler` | `getConnectionHandler()`
    `MessageHandler` | `getMessageHandler()`
    `PacketHandler` | `getPacketHandler()`
    `PacketQueue` | `getPacketQueue()`
    `I2PSession` | `getSession()` This is the primary session only
    `long` | `getSoTimeout()` Get the socket accept() timeout.
    `Set<Connection>` | `listConnections()` return a set of Connection objects
    `boolean` | `ping(Destination peer, int fromPort, int toPort, long timeoutMs)` blocking
    `boolean` | `ping(Destination peer, int fromPort, int toPort, long timeoutMs, boolean blocking)`
    `boolean` | `ping(Destination peer, int fromPort, int toPort, long timeoutMs, boolean blocking, ConnectionManager.PingNotifier notifier)`
    `byte[]` | `ping(Destination peer, int fromPort, int toPort, long timeoutMs, byte[] payload)` blocking
    `boolean` | `ping(Destination peer, long timeoutMs)` blocking
    `Connection` | `receiveConnection(Packet synPacket)` Create a new connection based on the SYN packet we received.
    `boolean` | `receivePing(Connection con, Packet ping)` Process a ping by checking for throttling, etc., then sending a pong.
    `(package private) void` | `receivePong(long pingId, ByteArray payload)`
    `void` | `removeConnection(Connection con)` Drop the (already closed) connection on the floor.
    `void` | `setAllowIncomingConnections(boolean allow)`
    `void` | `setSoTimeout(long x)` Set the socket accept() timeout.
    `void` | `shutdown()` Kill all connections and the timers.
    `String` | `toString()`
    `void` | `updateOptions()`
    `void` | `updateOptsFromShare(Connection con)`
    `void` | `updateShareOpts(Connection con)`
    `boolean` | `wasRecentlyClosed(long inboundID)` Was this conn recently closed?

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### PROP_BLACKLIST

          public static final String PROP_BLACKLIST

      See Also:
        Constant Field Values

    - #### PROP_MAX_PONG_DELAY

          static final String PROP_MAX_PONG_DELAY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ConnectionManager

          public ConnectionManager(I2PAppContext context,
                                   I2PSession session,
                                   ConnectionOptions defaultOptions,
                                   IncomingConnectionFilter connectionFilter)

      Manage all conns for this session
      Parameters:
        `session` - the primary session, packets may come in on subsessions also

  - ### Method Detail

    - #### answerPings

          public boolean answerPings()

      do we respond to pings that aren't on an existing connection?

    - #### connect

          public Connection connect(Destination peer,
                                    ConnectionOptions opts,
                                    I2PSession session)

      Build a new connection to the given peer. This blocks if there is no connection delay, otherwise it returns immediately.
      Parameters:
        `peer` - Destination to contact, non-null
        `opts` - Connection's options
        `session` - generally the session from the constructor, but could be a subsession
      Returns:
        new connection, or null if we have exceeded our limit

    - #### disconnectAllHard

          public void disconnectAllHard()

      Something b0rked hard, so kill all of our connections without mercy. Don't bother sending close packets. This will not close the ServerSocket. This will not kill the timer threads. CAN continue to use the manager.

    - #### getAllowIncomingConnections

          public boolean getAllowIncomingConnections()

      Returns:
        if we should accept connections

    - #### getConnectionByInboundId

          Connection getConnectionByInboundId(long id)

    - #### getConnectionByOutboundId

          Connection getConnectionByOutboundId(long id)

      not guaranteed to be unique, but in case we receive more than one packet on an inbound connection that we havent ack'ed yet...

    - #### getConnectionHandler

          public ConnectionHandler getConnectionHandler()

    - #### getMessageHandler

          public MessageHandler getMessageHandler()

    - #### getPacketHandler

          public PacketHandler getPacketHandler()

    - #### getPacketQueue

          public PacketQueue getPacketQueue()

    - #### getSession

          public I2PSession getSession()

      This is the primary session only

    - #### getSoTimeout

          public long getSoTimeout()

      Get the socket accept() timeout.
      Returns:
        accept timeout in ms.

    - #### listConnections

          public Set<Connection> listConnections()

      return a set of Connection objects
      Returns:
        set of Connection objects

    - #### ping

          public boolean ping(Destination peer,
                              int fromPort,
                              int toPort,
                              long timeoutMs)

      blocking
      Parameters:
        `timeoutMs` - greater than zero
      Returns:
        true if pong received

    - #### ping

          public boolean ping(Destination peer,
                              int fromPort,
                              int toPort,
                              long timeoutMs,
                              boolean blocking)

      Parameters:
        `timeoutMs` - greater than zero
      Returns:
        true if blocking and pong received

    - #### ping

          public boolean ping(Destination peer,
                              int fromPort,
                              int toPort,
                              long timeoutMs,
                              boolean blocking,
                              ConnectionManager.PingNotifier notifier)

      Parameters:
        `timeoutMs` - greater than zero
        `notifier` - may be null
      Returns:
        true if blocking and pong received

    - #### ping

          public byte[] ping(Destination peer,
                             int fromPort,
                             int toPort,
                             long timeoutMs,
                             byte[] payload)

      blocking
      Parameters:
        `timeoutMs` - greater than zero
        `payload` - non-null, include in packet, up to 32 bytes may be returned in pong not copied, do not modify
      Returns:
        the payload received in the pong, zero-length if none, null on failure or timeout

    - #### ping

          public boolean ping(Destination peer,
                              long timeoutMs)

      blocking
      Parameters:
        `timeoutMs` - greater than zero
      Returns:
        true if pong received

    - #### receiveConnection

          public Connection receiveConnection(Packet synPacket)

      Create a new connection based on the SYN packet we received.
      Parameters:
        `synPacket` - SYN packet to process
      Returns:
        created Connection with the packet's data already delivered to it, or null if the syn's streamId was already taken, or if the connection was rejected

    - #### receivePing

          public boolean receivePing(Connection con,
                                     Packet ping)

      Process a ping by checking for throttling, etc., then sending a pong.
      Parameters:
        `con` - null if unknown
        `ping` - Ping packet to process, must have From and Sig fields, with signature already verified, only if answerPings() returned true
      Returns:
        true if we sent a pong

    - #### receivePong

          void receivePong(long pingId,
                           ByteArray payload)

      Parameters:
        `payload` - may be null

    - #### removeConnection

          public void removeConnection(Connection con)

      Drop the (already closed) connection on the floor.
      Parameters:
        `con` - Connection to drop.

    - #### setAllowIncomingConnections

          public void setAllowIncomingConnections(boolean allow)

    - #### setSoTimeout

          public void setSoTimeout(long x)

      Set the socket accept() timeout.
      Parameters:
        `x` -

    - #### shutdown

          public void shutdown()

      Kill all connections and the timers. Don't bother sending close packets. As of 0.9.17, this will close the ServerSocket, killing one thread in accept(). CANNOT continue to use the manager or restart.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### updateOptions

          public void updateOptions()

    - #### updateOptsFromShare

          public void updateOptsFromShare(Connection con)

    - #### updateShareOpts

          public void updateShareOpts(Connection con)

    - #### wasRecentlyClosed

          public boolean wasRecentlyClosed(long inboundID)

      Was this conn recently closed?