## net.i2p.router.transport.udp
Class UDPTransport

    java.lang.Object
      net.i2p.router.transport.TransportImpl
          net.i2p.router.transport.udp.UDPTransport

All Implemented Interfaces:
  Transport, TimedWeightedPriorityMessageQueue.FailedListener

    public class UDPTransport

extends TransportImpl
implements TimedWeightedPriorityMessageQueue.FailedListener

Field Summary
`static int` `DEFAULT_COST`
`static int` `DEFAULT_INTERNAL_PORT` now unused, we pick a random port
`static String` `DEFAULT_SOURCES`
`static int` `EXPIRE_TIMEOUT`
`static String` `PROP_ALLOW_DIRECT` do we allow direct SSU connections, sans introducers?
`static String` `PROP_BIND_INTERFACE` this is rarely if ever used, default is to bind to wildcard address
`static String` `PROP_EXTERNAL_HOST` define this to explicitly set an external IP address
`static String` `PROP_EXTERNAL_PORT` define this to explicitly set an external port
`static String` `PROP_FIXED_PORT` if true (default), we don't change our advertised port no matter what our peers tell us
`static String` `PROP_FORCE_INTRODUCERS` do we require introducers, regardless of our status?
`static String` `PROP_INTERNAL_PORT`
`static String` `PROP_IP` remember IP changes
`static String` `PROP_IP_CHANGE`
`static String` `PROP_LAPTOP_MODE`
`static String` `PROP_PREFER_UDP` If i2np.udp.preferred is set to "always", the UDP bids will always be under the bid from the TCP transport - even if a TCP connection already exists.
`static String` `PROP_SOURCES` allowed sources of address updates
`static int` `PUBLIC_RELAY_COUNT` how many relays offered to us will we use at a time?
`(package private) static long[]` `RATES`
`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
`UDPTransport(RouterContext ctx)`

Method Summary
`List<Hash>` `_getActivePeers()` internal, do not use** return the peers (Hash) of active peers.
`static UDPTransport` `_instance()` internal, do not use**
`(package private) boolean` `addRemotePeerState(PeerState peer)` add the peer info, returning true if it went in properly, false if it was rejected (causes include peer ident already connected, or no remote host info known
`boolean` `allowConnection()`
`TransportBid` `bid(RouterInfo toAddress, long dataSize)`
`int` `countActivePeers()` How many peers active in the last few minutes?
`int` `countActiveSendPeers()` How many peers are we actively sending messages to (this minute)
`int` `countPeers()` How many peers are we connected to? For NTCP, this is the same as active, but SSU actually looks at idle time for countActivePeers()
`(package private) void` `dropPeer(Hash peer, boolean shouldShitlist, String why)`
`(package private) void` `dropPeer(PeerState peer, boolean shouldShitlist, String why)`
`(package private) void` `externalAddressReceived(Hash from, byte[] ourIP, int ourPort)` Someone we tried to contact gave us what they think our IP address is.
`void` `externalAddressReceived(String source, byte[] ip, int port)` From config, UPnP, local i/f, ...
`void` `failed(OutboundMessageState msg)`
`(package private) void` `failed(OutboundMessageState msg, boolean allowPeerFailure)`
`void` `failed(OutNetMessage msg, String reason)`
`void` `forwardPortStatus(int port, boolean success, String reason)` Callback from UPnP.
`Vector<Long>` `getClockSkews()` Return our peer clock skews on this transport.
`int` `getExternalPort()`
`SessionKey` `getIntroKey()` Introduction key that people should use to contact us
`InetAddress` `getLocalAddress()`
`int` `getLocalPort()`
`(package private) String` `getPacketHandlerStatus()`
`PeerState` `getPeerState(Hash remotePeer)` get the state for the peer with the given ident, or null if no state exists
`PeerState` `getPeerState(long relayTag)` get the state for the peer being introduced, or null if we aren't offering to introduce anyone with that tag.
`(package private) PeerState` `getPeerState(RemoteHostId hostInfo)` get the state for the peer at the given remote host/port, or null if no state exists
`short` `getReachabilityStatus()`
`int` `getRequestedPort()` _externalListenPort should always be set (by startup()) before this is called, so the returned value should be > 0
`String` `getStyle()`
`(package private) void` `inboundConnectionReceived()`
`boolean` `introducersRequired()`
`boolean` `isEstablished(Hash dest)`
`(package private) boolean` `isInDropList(RemoteHostId peer)`
`boolean` `isValid(byte[] addr)`
`void` `messageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived)` infinite loop public RouterAddress getCurrentAddress() { if (needsRebuild()) rebuildExternalAddress(false); return super.getCurrentAddress(); }
`protected void` `outboundMessageReady()` This message is called whenever a new message is added to the send pool, and it should not block
`(package private) PeerState` `pickTestPeer(RemoteHostId dontInclude)`
`(package private) void` `rebuildExternalAddress()`
`(package private) void` `rebuildExternalAddress(boolean allowRebuildRouterInfo)`
`void` `recheckReachability()`
`void` `renderStatusHTML(Writer out, int sortFlags)`
`void` `renderStatusHTML(Writer out, String urlBase, int sortFlags)`
`protected void` `replaceAddress(RouterAddress address)` Replace then tell NTCP that we changed.
`protected void` `replaceAddress(RouterAddress address, RouterAddress oldAddress)`
`(package private) void` `send(I2NPMessage msg, PeerState peer)`
`void` `send(OutNetMessage msg)` Asynchronously send the message as requested in the message and, if the send is successful, queue up any msg.getOnSendJob job, and register it with the OutboundMessageRegistry (if it has a reply selector).
`(package private) int` `send(UDPPacket packet)`
`(package private) void` `setReachabilityStatus(short status)`
`void` `shutdown()`
`RouterAddress` `startListening()`
`void` `startup()`
`void` `stopListening()`
`void` `succeeded(OutboundMessageState msg)`
`RouterAddress` `updateAddress()` Rebuild to get updated cost and introducers.

Methods inherited from class net.i2p.router.transport.TransportImpl
`afterSend, afterSend, afterSend, afterSend, getContext, getCurrentAddress, getIP, getMaxConnections, getMostRecentErrorMessages, getNextMessage, haveCapacity, haveCapacity, isBacklogged, isPubliclyRoutable, isUnreachable, markReachable, markUnreachable, markWasUnreachable, renderStatusHTML, setIP, setListener, wasUnreachable`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### STYLE

    public static final String STYLE

See Also:
  Constant Field Values

### PROP_INTERNAL_PORT

    public static final String PROP_INTERNAL_PORT

See Also:
  Constant Field Values

### DEFAULT_INTERNAL_PORT

    public static final int DEFAULT_INTERNAL_PORT

  now unused, we pick a random port

  See Also:
    Constant Field Values

### PROP_EXTERNAL_HOST

    public static final String PROP_EXTERNAL_HOST

  define this to explicitly set an external IP address

  See Also:
    Constant Field Values

### PROP_EXTERNAL_PORT

    public static final String PROP_EXTERNAL_PORT

  define this to explicitly set an external port

  See Also:
    Constant Field Values

### PROP_PREFER_UDP

    public static final String PROP_PREFER_UDP

  If i2np.udp.preferred is set to "always", the UDP bids will always be under the bid from the TCP transport - even if a TCP connection already exists. If it is set to "true", it will prefer UDP unless no UDP session exists and a TCP connection already exists. If it is set to "false" (the default), it will prefer TCP unless no TCP session exists and a UDP connection already exists.

  See Also:
    Constant Field Values

### PROP_FIXED_PORT

    public static final String PROP_FIXED_PORT

  if true (default), we don't change our advertised port no matter what our peers tell us

  See Also:
    Constant Field Values

### PROP_SOURCES

    public static final String PROP_SOURCES

  allowed sources of address updates

  See Also:
    Constant Field Values

### DEFAULT_SOURCES

    public static final String DEFAULT_SOURCES

See Also:
  Constant Field Values

### PROP_IP

    public static final String PROP_IP

  remember IP changes

  See Also:
    Constant Field Values

### PROP_IP_CHANGE

    public static final String PROP_IP_CHANGE

See Also:
  Constant Field Values

### PROP_LAPTOP_MODE

    public static final String PROP_LAPTOP_MODE

See Also:
  Constant Field Values

### PROP_FORCE_INTRODUCERS

    public static final String PROP_FORCE_INTRODUCERS

  do we require introducers, regardless of our status?

  See Also:
    Constant Field Values

### PROP_ALLOW_DIRECT

    public static final String PROP_ALLOW_DIRECT

  do we allow direct SSU connections, sans introducers?

  See Also:
    Constant Field Values

### 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

### PUBLIC_RELAY_COUNT

    public static final int PUBLIC_RELAY_COUNT

  how many relays offered to us will we use at a time?

  See Also:
    Constant Field Values

### DEFAULT_COST

    public static final int DEFAULT_COST

See Also:
  Constant Field Values

### RATES

    static final long[] RATES

### EXPIRE_TIMEOUT

    public static final int EXPIRE_TIMEOUT

See Also:
  Constant Field Values

Constructor Detail

### UDPTransport

    public UDPTransport(RouterContext ctx)

Method Detail

### startup

    public void startup()

### shutdown

    public void shutdown()

### getIntroKey

    public SessionKey getIntroKey()

  Introduction key that people should use to contact us

### getLocalPort

    public int getLocalPort()

### getLocalAddress

    public InetAddress getLocalAddress()

### getExternalPort

    public int getExternalPort()

### getRequestedPort

    public int getRequestedPort()

  _externalListenPort should always be set (by startup()) before this is called, so the returned value should be > 0

  Specified by:
    `getRequestedPort` in interface `Transport`
  Overrides:
    `getRequestedPort` in class `TransportImpl`
  Returns:
    port or -1 for none or 0 for any

### inboundConnectionReceived

    void inboundConnectionReceived()

### externalAddressReceived

    public void externalAddressReceived(String source,
                                        byte[] ip,
                                        int port)

  From config, UPnP, local i/f, ...

  Specified by:
    `externalAddressReceived` in interface `Transport`
  Overrides:
    `externalAddressReceived` in class `TransportImpl`
  Parameters:
    `source` - used for logging only
    `ip` - publicly routable IPv4 only
    `port` - 0 if unknown

### forwardPortStatus

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

  Callback from UPnP. If we we have an IP address and UPnP claims success, believe it. If this is wrong, the peer test will figure it out and change the status. Don't do anything if UPnP claims failure.

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

### externalAddressReceived

    void externalAddressReceived(Hash from,
                                 byte[] ourIP,
                                 int ourPort)

  Someone we tried to contact gave us what they think our IP address is. Right now, we just blindly trust them, changing our IP and port on a whim. this is not good ;) Slight enhancement - require two different peers in a row to agree Todo: - Much better tracking of troublemakers - Disable if we have good local address or UPnP - This gets harder if and when we publish multiple addresses, or IPv6

  Parameters:
    `from` - Hash of inbound destination
    `ourIP` - publicly routable IPv4 only
    `ourPort` - >= 1024

### isValid

    public final boolean isValid(byte[] addr)

### getPeerState

    PeerState getPeerState(RemoteHostId hostInfo)

  get the state for the peer at the given remote host/port, or null if no state exists

### getPeerState

    public PeerState getPeerState(Hash remotePeer)

  get the state for the peer with the given ident, or null if no state exists

### getPeerState

    public PeerState getPeerState(long relayTag)

  get the state for the peer being introduced, or null if we aren't offering to introduce anyone with that tag.

### addRemotePeerState

    boolean addRemotePeerState(PeerState peer)

  add the peer info, returning true if it went in properly, false if it was rejected (causes include peer ident already connected, or no remote host info known

### messageReceived

    public void messageReceived(I2NPMessage inMsg,
                                RouterIdentity remoteIdent,
                                Hash remoteIdentHash,
                                long msToReceive,
                                int bytesReceived)

  infinite loop public RouterAddress getCurrentAddress() { if (needsRebuild()) rebuildExternalAddress(false); return super.getCurrentAddress(); }

  Overrides:
    `messageReceived` in class `TransportImpl`

### isInDropList

    boolean isInDropList(RemoteHostId peer)

### dropPeer

    void dropPeer(Hash peer,
                  boolean shouldShitlist,
                  String why)

### dropPeer

    void dropPeer(PeerState peer,
                  boolean shouldShitlist,
                  String why)

### send

    int send(UDPPacket packet)

### bid

    public TransportBid bid(RouterInfo toAddress,
                            long dataSize)

  Specified by:
    `bid` in interface `Transport`

### getStyle

    public String getStyle()

  Specified by:
    `getStyle` in interface `Transport`

### send

    public void send(OutNetMessage msg)

  Description copied from class: `TransportImpl`
  Asynchronously send the message as requested in the message and, if the send is successful, queue up any msg.getOnSendJob job, and register it with the OutboundMessageRegistry (if it has a reply selector). If the send fails, queue up any msg.getOnFailedSendJob

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

### send

    void send(I2NPMessage msg,
              PeerState peer)

### 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`

### startListening

    public RouterAddress startListening()

  Specified by:
    `startListening` in interface `Transport`

### stopListening

    public void stopListening()

  Specified by:
    `stopListening` in interface `Transport`

### updateAddress

    public RouterAddress updateAddress()

  Rebuild to get updated cost and introducers. Do not tell the router (he is the one calling this)

  Specified by:
    `updateAddress` in interface `Transport`
  Overrides:
    `updateAddress` in class `TransportImpl`
  Since:
    0.7.12

### rebuildExternalAddress

    void rebuildExternalAddress()

### rebuildExternalAddress

    void rebuildExternalAddress(boolean allowRebuildRouterInfo)

### replaceAddress

    protected void replaceAddress(RouterAddress address)

  Replace then tell NTCP that we changed.

  Overrides:
    `replaceAddress` in class `TransportImpl`

### replaceAddress

    protected void replaceAddress(RouterAddress address,
                                  RouterAddress oldAddress)

### introducersRequired

    public boolean introducersRequired()

### getPacketHandlerStatus

    String getPacketHandlerStatus()

### failed

    public void failed(OutboundMessageState msg)

### failed

    void failed(OutboundMessageState msg,
                boolean allowPeerFailure)

### failed

    public void failed(OutNetMessage msg,
                       String reason)

  Specified by:
    `failed` in interface `TimedWeightedPriorityMessageQueue.FailedListener`

### succeeded

    public void succeeded(OutboundMessageState msg)

### countPeers

    public int countPeers()

  Description copied from class: `TransportImpl`
  How many peers are we connected to? For NTCP, this is the same as active, but SSU actually looks at idle time for countActivePeers()

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

### countActivePeers

    public int countActivePeers()

  Description copied from class: `TransportImpl`
  How many peers active in the last few minutes?

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

### countActiveSendPeers

    public int countActiveSendPeers()

  Description copied from class: `TransportImpl`
  How many peers are we actively sending messages to (this minute)

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

### isEstablished

    public boolean isEstablished(Hash dest)

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

### allowConnection

    public boolean allowConnection()

### 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`

### _instance

    public static final UDPTransport _instance()

  internal, do not use**

### _getActivePeers

    public List<Hash> _getActivePeers()

  internal, do not use** return the peers (Hash) of active peers.

### 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`

### setReachabilityStatus

    void setReachabilityStatus(short status)

### getReachabilityStatus

    public short getReachabilityStatus()

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

### recheckReachability

    public void recheckReachability()

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

### pickTestPeer

    PeerState pickTestPeer(RemoteHostId dontInclude)