net.i2p.router.transport.ntcp

## Class NTCPTransport

- java.lang.Object
- - net.i2p.router.transport.TransportImpl
  - - net.i2p.router.transport.ntcp.NTCPTransport

- All Implemented Interfaces:
    Transport

      public class NTCPTransport
      extends TransportImpl

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ESTABLISH_TIMEOUT` how long from initial connection attempt (accept() or connect()) until the con must be established to avoid premature close()ing
    `static String` | `PROP_BIND_INTERFACE` this is rarely if ever used, default is to bind to wildcard address
    `static String` | `STYLE`

    - ### Fields inherited from class net.i2p.router.transport.TransportImpl

      `_context, ADJUST_COST`

    - ### Fields inherited from interface net.i2p.router.transport.Transport

      `SOURCE_CONFIG, SOURCE_INTERFACE, SOURCE_UPNP`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NTCPTransport(RouterContext ctx)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend)` The transport is done sending this message.
    `boolean` | `allowConnection()`
    `TransportBid` | `bid(RouterInfo toAddress, long dataSize)`
    `int` | `countActivePeers()` How many peers can we talk to right now?
    `int` | `countActiveSendPeers()` How many peers are we actively sending messages to (this minute)
    `(package private) void` | `establishing(NTCPConnection con)` add us to the establishment timeout process
    `(package private) void` | `expireTimedOut()` called in the EventPumper no more than once a second or so, closing any unconnected/unestablished connections
    `void` | `forwardPortStatus(int port, boolean success, String reason)` If we didn't used to be forwarded, and we have an address, and we are configured to use UPnP, update our RouterAddress Don't do anything now.
    `Vector<Long>` | `getClockSkews()` Return our peer clock skews on this transport.
    `(package private) EventPumper` | `getPumper()`
    `short` | `getReachabilityStatus()` Maybe we should trust UPnP here and report OK if it opened the port, but for now we don't.
    `(package private) Reader` | `getReader()`
    `int` | `getRequestedPort()` What port would the transport like to have forwarded by UPnP.
    `String` | `getStyle()`
    `(package private) Writer` | `getWriter()`
    `(package private) void` | `inboundEstablished(NTCPConnection con)`
    `boolean` | `isAlive()`
    `boolean` | `isBacklogged(Hash dest)`
    `boolean` | `isEstablished(Hash dest)`
    `protected void` | `outboundMessageReady()` This message is called whenever a new message is added to the send pool, and it should not block
    `(package private) void` | `removeCon(NTCPConnection con)`
    `void` | `renderStatusHTML(Writer out, int sortFlags)`
    `void` | `renderStatusHTML(Writer out, String urlBase, int sortFlags)`
    `RouterAddress` | `restartListening(RouterAddress addr)` Only called by CSFI.
    `(package private) void` | `sendComplete(OutNetMessage msg)` queue up afterSend call, which can take some time w/ jobs, etc
    `(package private) void` | `setLastBadSkew(long skew)`
    `RouterAddress` | `startListening()` Called by TransportManager.
    `void` | `stopListening()` This doesn't (completely) block, caller should check isAlive() before calling startListening() or restartListening()

    - ### Methods inherited from class net.i2p.router.transport.TransportImpl

      `afterSend, afterSend, afterSend, countPeers, externalAddressReceived, getContext, getCurrentAddress, getIP, getMaxConnections, getMostRecentErrorMessages, getNextMessage, haveCapacity, haveCapacity, isPubliclyRoutable, isUnreachable, markReachable, markUnreachable, markWasUnreachable, messageReceived, recheckReachability, renderStatusHTML, replaceAddress, send, setIP, setListener, updateAddress, wasUnreachable`

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

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

- - ### Field Detail

    - #### PROP_BIND_INTERFACE

          public static final String PROP_BIND_INTERFACE

      this is rarely if ever used, default is to bind to wildcard address
      See Also:
        Constant Field Values

    - #### ESTABLISH_TIMEOUT

          public static final int ESTABLISH_TIMEOUT

      how long from initial connection attempt (accept() or connect()) until the con must be established to avoid premature close()ing
      See Also:
        Constant Field Values

    - #### STYLE

          public static final String STYLE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NTCPTransport

          public NTCPTransport(RouterContext ctx)

  - ### Method Detail

    - #### inboundEstablished

          void inboundEstablished(NTCPConnection con)

    - #### outboundMessageReady

          protected void outboundMessageReady()

      Description copied from class: `TransportImpl`
      This message is called whenever a new message is added to the send pool, and it should not block
      Specified by:
        `outboundMessageReady` in class `TransportImpl`

    - #### afterSend

          public void afterSend(OutNetMessage msg,
                       boolean sendSuccessful,
                       boolean allowRequeue,
                       long msToSend)

      Description copied from class: `TransportImpl`
      The transport is done sending this message. This is the method that actually does all of the cleanup - firing off jobs, requeueing, updating stats, etc.
      Overrides:
        `afterSend` in class `TransportImpl`
      Parameters:
        `msg` - message in question
        `sendSuccessful` - true if the peer received it
        `allowRequeue` - true if we should try other transports if available
        `msToSend` - how long it took to transfer the data to the peer

    - #### bid

          public TransportBid bid(RouterInfo toAddress,
                         long dataSize)

    - #### allowConnection

          public boolean allowConnection()

    - #### sendComplete

          void sendComplete(OutNetMessage msg)

      queue up afterSend call, which can take some time w/ jobs, etc

    - #### isEstablished

          public boolean isEstablished(Hash dest)

      Specified by:
        `isEstablished` in interface `Transport`
      Overrides:
        `isEstablished` in class `TransportImpl`

    - #### isBacklogged

          public boolean isBacklogged(Hash dest)

      Specified by:
        `isBacklogged` in interface `Transport`
      Overrides:
        `isBacklogged` in class `TransportImpl`

    - #### removeCon

          void removeCon(NTCPConnection con)

    - #### countActivePeers

          public int countActivePeers()

      How many peers can we talk to right now?
      Specified by:
        `countActivePeers` in interface `Transport`
      Overrides:
        `countActivePeers` in class `TransportImpl`

    - #### countActiveSendPeers

          public int countActiveSendPeers()

      How many peers are we actively sending messages to (this minute)
      Specified by:
        `countActiveSendPeers` in interface `Transport`
      Overrides:
        `countActiveSendPeers` in class `TransportImpl`

    - #### setLastBadSkew

          void setLastBadSkew(long skew)

      Parameters:
        `skew` - in seconds

    - #### getClockSkews

          public Vector<Long> getClockSkews()

      Return our peer clock skews on this transport. Vector composed of Long, each element representing a peer skew in seconds.
      Specified by:
        `getClockSkews` in interface `Transport`
      Overrides:
        `getClockSkews` in class `TransportImpl`

    - #### startListening

          public RouterAddress startListening()

      Called by TransportManager. Caller should stop the transport first, then verify stopped with isAlive() Unfortunately TransportManager doesn't do that, so we check here to prevent two pumpers.
      Returns:
        appears to be ignored by caller

    - #### restartListening

          public RouterAddress restartListening(RouterAddress addr)

      Only called by CSFI. Caller should stop the transport first, then verify stopped with isAlive()
      Returns:
        appears to be ignored by caller

    - #### isAlive

          public boolean isAlive()

    - #### getReader

          Reader getReader()

    - #### getWriter

          Writer getWriter()

    - #### getStyle

          public String getStyle()

    - #### getPumper

          EventPumper getPumper()

    - #### establishing

          void establishing(NTCPConnection con)

      add us to the establishment timeout process

    - #### expireTimedOut

          void expireTimedOut()

      called in the EventPumper no more than once a second or so, closing any unconnected/unestablished connections

    - #### forwardPortStatus

          public void forwardPortStatus(int port,
                               boolean success,
                               String reason)

      If we didn't used to be forwarded, and we have an address, and we are configured to use UPnP, update our RouterAddress Don't do anything now. If it fails, we don't know if it's because there is no firewall, or if the firewall rejected the request. So we just use the SSU reachability status to decide whether to enable inbound NTCP. SSU will have CSFI build a new NTCP address when it transitions to OK.
      Specified by:
        `forwardPortStatus` in interface `Transport`
      Overrides:
        `forwardPortStatus` in class `TransportImpl`

    - #### getRequestedPort

          public int getRequestedPort()

      Description copied from class: `TransportImpl`
      What port would the transport like to have forwarded by UPnP. This can't be passed via getCurrentAddress(), as we have to open the port before we can publish the address.
      Specified by:
        `getRequestedPort` in interface `Transport`
      Overrides:
        `getRequestedPort` in class `TransportImpl`
      Returns:
        port or -1 for none or 0 for any

    - #### getReachabilityStatus

          public short getReachabilityStatus()

      Maybe we should trust UPnP here and report OK if it opened the port, but for now we don't. Just go through and if we have one inbound connection, we must be good. As we drop idle connections pretty quickly, this will be fairly accurate. We have to be careful here because much of the router console code assumes that the reachability status is really just the UDP status.
      Specified by:
        `getReachabilityStatus` in interface `Transport`
      Overrides:
        `getReachabilityStatus` in class `TransportImpl`

    - #### stopListening

          public void stopListening()

      This doesn't (completely) block, caller should check isAlive() before calling startListening() or restartListening()

    - #### renderStatusHTML

          public void renderStatusHTML(Writer out,
                              int sortFlags)
                                throws IOException

      Throws:
        `IOException`

    - #### renderStatusHTML

          public void renderStatusHTML(Writer out,
                              String urlBase,
                              int sortFlags)
                                throws IOException

      Specified by:
        `renderStatusHTML` in interface `Transport`
      Overrides:
        `renderStatusHTML` in class `TransportImpl`
      Throws:
        `IOException`