net.i2p.router.transport
Class TransportManager

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

public class TransportManager
extends Object
implements TransportEventListener


Nested Class Summary
(package private) static class TransportManager.Port
           
 
Field Summary
static String PROP_ENABLE_NTCP
          default true
static String PROP_ENABLE_UDP
          default true
static String PROP_ENABLE_UPNP
          default true
 
Constructor Summary
TransportManager(RouterContext context)
           
 
Method Summary
 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.
 int countActiveSendPeers()
          How many peers are we currently connected to, that we have sent a message to in the last minute.
 void externalAddressReceived(Transport.AddressSource source, byte[] ip, int port)
          Initialize from interfaces, and callback from UPnP or SSU.
 void externalAddressRemoved(Transport.AddressSource source, boolean ipv6)
          Remove all ipv4 or ipv6 addresses.
 void forwardPortStatus(String style, byte[] ip, int port, int externalPort, boolean success, String reason)
          callback from UPnP
 List<RouterAddress> getAddresses()
          This forces a rebuild
 TransportBid getBid(OutNetMessage msg)
           
 List<TransportBid> getBids(OutNetMessage msg)
           
 Vector<Long> getClockSkews()
          Return our peer clock skews on all transports.
(package private)  DHSessionKeyBuilder.Factory getDHFactory()
          Hook for pluggable transport creation.
 byte[] getIP(Hash dest)
          IP of the peer from the last connection (in or out, any transport).
 List<String> getMostRecentErrorMessages()
           
 TransportBid getNextBid(OutNetMessage msg)
           
 CommSystemFacade.Status getReachabilityStatus()
          Previously returned short, now enum as of 0.9.20
 Transport getTransport(String style)
           
(package private)  int getTransportCount()
           
 boolean haveHighOutboundCapacity()
          Are all transports well below their outbound connection limit Use for throttling in the router.
 boolean haveInboundCapacity(int pct)
          Is at least one transport below its inbound connection limit + some margin Use for throttling in the router.
 boolean haveOutboundCapacity(int pct)
          Is at least one transport below its outbound connection limit + some margin Use for throttling in the router.
 boolean isBacklogged(Hash dest)
           
 boolean isEstablished(Hash dest)
           
static boolean isNTCPEnabled(RouterContext ctx)
           
 void messageReceived(I2NPMessage message, RouterIdentity fromRouter, Hash fromRouterHash)
          Message received
 void recheckReachability()
          Deprecated. unused
(package private)  void registerAndStart(Transport t)
          Pluggable transports.
 void renderStatusHTML(Writer out, String urlBase, int sortFlags)
          Warning - blocking, very slow, queries the active UPnP router, will take many seconds if it has vanished.
 void restart()
           
 void shutdown()
          Cannot be restarted.
 void startListening()
           
(package private)  void stopAndUnregister(Transport t)
          Pluggable transports.
 void stopListening()
          Can be restarted.
 void transportAddressChanged()
           
 boolean wasUnreachable(Hash dest)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_ENABLE_UDP

public static final String PROP_ENABLE_UDP
default true

See Also:
Constant Field Values

PROP_ENABLE_NTCP

public static final String PROP_ENABLE_NTCP
default true

See Also:
Constant Field Values

PROP_ENABLE_UPNP

public static final String PROP_ENABLE_UPNP
default true

See Also:
Constant Field Values
Constructor Detail

TransportManager

public TransportManager(RouterContext context)
Method Detail

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

DHSessionKeyBuilder.Factory getDHFactory()
Hook for pluggable transport creation.

Since:
0.9.16

isNTCPEnabled

public static boolean isNTCPEnabled(RouterContext ctx)

externalAddressReceived

public 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

public 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

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


startListening

public void startListening()

restart

public void restart()

stopListening

public void stopListening()
Can be restarted.


shutdown

public void shutdown()
Cannot be restarted.

Since:
0.9

getTransport

public Transport getTransport(String style)

getTransportCount

int getTransportCount()

countActivePeers

public 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

public 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

public 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

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


haveInboundCapacity

public 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

public Vector<Long> getClockSkews()
Return our peer clock skews on all transports. Vector 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

public CommSystemFacade.Status getReachabilityStatus()
Previously returned short, now enum as of 0.9.20

Returns:
the best status of any transport

recheckReachability

public void recheckReachability()
Deprecated. unused


isBacklogged

public boolean isBacklogged(Hash dest)

isEstablished

public boolean isEstablished(Hash dest)

wasUnreachable

public boolean wasUnreachable(Hash dest)
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

public byte[] getIP(Hash dest)
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

public List<RouterAddress> getAddresses()
This forces a rebuild


getBid

public TransportBid getBid(OutNetMessage msg)

getBids

public List<TransportBid> getBids(OutNetMessage msg)

getNextBid

public 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()
Specified by:
transportAddressChanged in interface TransportEventListener

getMostRecentErrorMessages

public List<String> getMostRecentErrorMessages()

renderStatusHTML

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

Throws:
IOException