Class TransportManager

java.lang.Object
net.i2p.router.transport.TransportManager
All Implemented Interfaces:
TransportEventListener

public class TransportManager extends Object implements TransportEventListener
Keeps track of the enabled transports. Starts UPnP. Pluggable transport support incomplete. Public only for a couple things in the console and Android. To be made package private. Everything external should go through CommSystemFacadeImpl. Not a public API, not for external use.
  • Field Details

  • Constructor Details

    • TransportManager

      public TransportManager(RouterContext context)
  • Method Details

    • registerAndStart

      void registerAndStart(Transport t)
      Pluggable transports. Not for NTCP or SSU.
      Since:
      0.9.16
    • stopAndUnregister

      void stopAndUnregister(Transport t)
      Pluggable transports. Not for NTCP or SSU.
      Since:
      0.9.16
    • getDHFactory

      Hook for pluggable transport creation.
      Returns:
      null if both NTCP1 and SSU are disabled
      Since:
      0.9.16
    • getXDHFactory

      X25519KeyFactory getXDHFactory()
      Factory for making X25519 key pairs.
      Since:
      0.9.46
    • isNTCPEnabled

      public static boolean isNTCPEnabled(RouterContext ctx)
    • initializeAddress

      void initializeAddress()
      Notify all transports of ALL routable interface addresses, including IPv6. It's the transport's job to ignore what it can't handle.
      Since:
      0.9.34
    • externalAddressReceived

      void externalAddressReceived(Transport.AddressSource source, byte[] ip, int port)
      Initialize from interfaces, and callback from UPnP or SSU. See CSFI.notifyReplaceAddress(). Tell all transports... but don't loop.
    • externalAddressRemoved

      void externalAddressRemoved(Transport.AddressSource source, boolean ipv6)
      Remove all ipv4 or ipv6 addresses. See CSFI.notifyRemoveAddress(). Tell all transports... but don't loop.
      Since:
      0.9.20
    • forwardPortStatus

      void forwardPortStatus(String style, byte[] ip, int port, int externalPort, boolean success, String reason)
      callback from UPnP
    • startListening

      void startListening()
    • restart

      void restart()
    • stopListening

      void stopListening()
      Can be restarted.
    • shutdown

      void shutdown()
      Cannot be restarted.
      Since:
      0.9
    • getTransport

      Transport getTransport(String style)
    • getTransportCount

      int getTransportCount()
    • getTransports

      SortedMap<String,Transport> getTransports()
      Returns:
      SortedMap of style to Transport (a copy)
      Since:
      0.9.31
    • countActivePeers

      int countActivePeers()
      How many peers are we currently connected to, that we have sent a message to or received a message from in the last five minutes.
    • countActiveSendPeers

      int countActiveSendPeers()
      How many peers are we currently connected to, that we have sent a message to in the last minute. Unused for anything, to be removed.
    • haveOutboundCapacity

      boolean haveOutboundCapacity(int pct)
      Is at least one transport below its outbound connection limit + some margin Use for throttling in the router.
      Parameters:
      pct - percent of limit 0-100
    • haveHighOutboundCapacity

      boolean haveHighOutboundCapacity()
      Are all transports well below their outbound connection limit Use for throttling in the router.
    • haveInboundCapacity

      boolean haveInboundCapacity(int pct)
      Is at least one transport below its inbound connection limit + some margin Use for throttling in the router.
      Parameters:
      pct - percent of limit 0-100
    • getClockSkews

      List<Long> getClockSkews()
      Return our peer clock skews on all transports. List composed of Long, each element representing a peer skew in seconds. A positive number means our clock is ahead of theirs. Note: this method returns them in whimsical order.
    • getReachabilityStatus

      CommSystemFacade.Status getReachabilityStatus()
      Previously returned short, now enum as of 0.9.20
      Returns:
      the best status of any transport
    • recheckReachability

      @Deprecated void recheckReachability()
      Deprecated.
      unused
    • isBacklogged

      boolean isBacklogged(Hash peer)
    • isEstablished

      boolean isEstablished(Hash peer)
    • getEstablished

      public Set<Hash> getEstablished()
      Returns:
      a new set, may be modified
      Since:
      0.9.34
    • mayDisconnect

      void mayDisconnect(Hash peer)
      Tell the transports that we may disconnect from this peer. This is advisory only.
      Since:
      0.9.24
    • forceDisconnect

      void forceDisconnect(Hash peer)
      Tell the transports to disconnect from this peer.
      Since:
      0.9.38
    • wasUnreachable

      boolean wasUnreachable(Hash peer)
      Was the peer UNreachable (outbound only) on any transport, based on the last time we tried it for each transport? This is NOT reset if the peer contacts us.
    • getIP

      byte[] getIP(Hash peer)
      IP of the peer from the last connection (in or out, any transport). This may be different from that advertised in the netDb, as the peer may be hidden, or connect from a different IP, or change his netDb later, in an attempt to avoid restrictions. For blocking purposes, etc. it's worth checking both the netDb addresses and this address.
      Returns:
      IPv4 or IPv6 or null
    • getAddresses

      List<RouterAddress> getAddresses()
      This forces a rebuild
    • getBid

    • getBids

    • getNextBid

      TransportBid getNextBid(OutNetMessage msg)
    • messageReceived

      public void messageReceived(I2NPMessage message, RouterIdentity fromRouter, Hash fromRouterHash)
      Message received
      Specified by:
      messageReceived in interface TransportEventListener
      Parameters:
      message - non-null
      fromRouter - may be null
      fromRouterHash - may be null, calculated from fromRouter if null
    • transportAddressChanged

      public void transportAddressChanged()
      TransportEventListener calls UPnPManager rescan() and update()
      Specified by:
      transportAddressChanged in interface TransportEventListener
    • getMostRecentErrorMessages

      List<String> getMostRecentErrorMessages()
    • renderStatusHTML

      public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException
      As of 0.9.31, only outputs UPnP status Warning - blocking, very slow, queries the active UPnP router, will take many seconds if it has vanished.
      Throws:
      IOException