public class UDPTransport extends TransportImpl
Transport.AddressSource| Modifier and Type | Field and Description |
|---|---|
static int | DEFAULT_COSTDefault cost value for SSU peer selection. |
static String | DEFAULT_SOURCES+ |
static int | EXPIRE_TIMEOUTDefault introducer expiration in ms. |
(package private) static long | INTRODUCER_EXPIRATION_MARGINDefault introducer expiration in ms. |
static int | MIN_EXPIRE_TIMEOUTMinimum introducer expiration in ms. |
static String | PROP_ALLOW_DIRECTDo we allow direct SSU connections, sans introducers? |
static String | PROP_BIND_INTERFACEThis is rarely if ever used, default is to bind to wildcard address |
static String | PROP_EXTERNAL_HOSTdefine this to explicitly set an external IP address |
static String | PROP_EXTERNAL_PORTdefine this to explicitly set an external port |
static String | PROP_FORCE_INTRODUCERSDo we require introducers, regardless of our status? |
static String | PROP_INTERNAL_PORTConfig key for SSU internal port. |
static String | PROP_INTRO_KEYIntroducer key property. |
static String | PROP_IPremember IP changes |
static String | PROP_IP_CHANGEConfig key tracking last IP address change. |
static String | PROP_IPV6Last IPv6 config. |
static String | PROP_LAPTOP_MODEConfig key for laptop power-saving mode. |
static String | PROP_PREFER_UDPConfig key to prefer UDP transport. |
static String | PROP_SOURCESallowed sources of address updates |
static String | PROP_SSU2_IKEYb64 static IV |
static String | PROP_SSU2_SPb64 static private key |
static int | PUBLIC_RELAY_COUNTHow many relays offered to us will we use at a time? |
(package private) static long[] | RATESShort-term rate limits for SSU. |
(package private) static int | SSU2_INT_VERSIONSSU2 protocol version. |
(package private) static String | SSU2_VERSION"2" |
(package private) static String | SSU2_VERSION_ALT"2," |
static String | STYLESSU transport style identifier. |
static String | STYLE2SSU2 transport style identifier. |
_context, ADJUST_COST, CAP_IPV4, CAP_IPV4_IPV6, CAP_IPV6, CONGESTION_COST_ADJUSTMENT, PROP_BOOST_CONNECTION_LIMITS, PROP_IPV6_FIREWALLED| Constructor and Description |
|---|
UDPTransport(RouterContext ctx,
X25519KeyFactory xdh) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void | addRecentlyClosed(PeerStateDestroyed peer)Start listening for packets on a destroyed connection |
(package private) boolean | addRemotePeerState(PeerState peer)Adds a new peer state or replaces an existing one if the peer identity or address changes. |
void | adjustMessageReceiverThreads()Dynamically adjusts MessageReceiver thread count to match the target. |
void | adjustPacketHandlerThreads()Dynamically adjusts PacketHandler thread count to match the target. |
boolean | allowConnection()Whether a new connection is allowed. |
TransportBid | bid(RouterInfo toAddress,
int dataSize)Data size. |
(package private) boolean | canIntroduce(boolean ipv6)For EstablishmentManager. |
(package private) boolean | canTestAsCharlie(boolean ipv6)Can we be a Charlie right now? |
(package private) void | changePeerAddress(PeerState2 peer,
RemoteHostId newAddress)Remove and add to peersByRemoteHost map |
(package private) void | changePeerPort(PeerState peer,
int newPort)Remove and add to peersByRemoteHost map |
int | countActivePeers()Active peers. |
int | countActiveSendPeers()Active send peers. |
int | countPeers()Count peers. |
(package private) void | dropPeer(Hash peer,
boolean shouldBanlist,
String why)This does not send a session destroy, caller must do that if desired. |
(package private) void | dropPeer(PeerState peer,
boolean shouldBanlist,
String why)This does not send a session destroy, caller must do that if desired. |
(package private) void | externalAddressReceived(Hash from,
byte[] hisIP,
byte[] ourIP,
int ourPort)Someone we tried to contact gave us what they think our IP address is. |
void | externalAddressReceived(Transport.AddressSource source,
byte[] ip,
int port)From config, UPnP, local i/f, ... |
void | fail(UDPEndpoint endpoint)The endpoint has failed. |
void | failed(OutboundMessageState msg)Handle a failed outbound message. |
(package private) void | failed(OutboundMessageState msg,
boolean allowPeerFailure) |
void | failed(OutNetMessage msg,
String reason)Handle a failed outbound network message. |
void | forceDisconnect(Hash peer)Force disconnect a peer. |
void | forceDisconnect(Hash peer,
String reason)Force disconnect with reason. |
void | forwardPortStatus(byte[] ip,
int port,
int externalPort,
boolean success,
String reason)Callback from UPnP. |
String | getAltStyle()An alternate supported style, or null. |
(package private) PacketBuilder2 | getBuilder2() |
List<Long> | getClockSkews()Return our peer clock skews on this transport. |
RouterAddress | getCurrentExternalAddress(boolean isIPv6)Simple fetch of stored IP and port, since
we don't put them in the real, published RouterAddress anymore
if we are firewalled. |
static long | getDataMessageTimeout()The data message timeout in ms. |
List<Hash> | getEstablished()Identities of all currently established peers. |
(package private) EstablishmentManager | getEstablisher()For IntroductionManager |
(package private) byte[] | getExternalIP()Published IP, IPv4 only |
(package private) int | getExternalPort(boolean ipv6)Published or requested port |
(package private) InboundMessageFragments | getInboundFragments() |
(package private) SessionKey | getIntroKey()Introduction key that people should use to contact us,
or null if SSU1 disabled. |
(package private) IntroductionManager | getIntroManager() |
static long | getMaxIbEstablishTime()The inbound establish timeout in ms. |
static long | getMaxObEstablishTime()The outbound establish timeout in ms. |
static int | getMessageReceiverThreads()The current target MessageReceiver thread count. |
double | getMessageReceiverUtilization()Message receiver pool utilization as a ratio (0.0-1.0). |
int | getMTU(boolean ipv6)The MTU for the socket interface. |
(package private) OutboundMessageFragments | getOMF() |
(package private) PacketHandler | getPacketHandler()The packet handler |
static int | getPacketHandlerMaxThreads()The max packet handler threads. |
(package private) String | getPacketHandlerStatus()Packet handler status |
double | getPacketHandlerUtilization()Packet handler pool utilization as a ratio (0.0-1.0). |
int[] | getPeerCounts()Peer counts. |
Collection<PeerState> | getPeers()For /peers UI only. |
(package private) PeerState | getPeerState(Hash remotePeer)get the state for the peer with the given ident, or null
if no state exists |
(package private) PeerState2 | getPeerState(long rcvConnID)state by SSU2 connection ID |
(package private) PeerState | getPeerState(RemoteHostId hostInfo)Retrieves the current connection state for a peer identified by their remote host and port. |
(package private) List<PeerState> | getPeerStatesByIP(RemoteHostId hostInfo)states for all peers at the given remote host, ignoring port. |
(package private) PeerTestManager | getPeerTestManager() |
CommSystemFacade.Status | getReachabilityStatus()Current reachability status, possibly overridden by configuration. |
int | getReceiverQueueCapacity()Returns the maximum capacity of the MessageReceiver queue. |
int | getReceiverQueueSize()The current queue depth of the MessageReceiver. |
(package private) PeerStateDestroyed | getRecentlyClosed(long rcvConnID)Was the state for this SSU2 receive connection ID recently closed? |
int | getRequestedPort()The current or configured internal IPv4 port. |
int | getSSU2MTU(boolean ipv6)The SSU2 MTU for the socket interface. |
(package private) byte[] | getSSU2StaticIntroKey()The static Intro key |
(package private) byte[] | getSSU2StaticPrivKey()The static priv key |
(package private) byte[] | getSSU2StaticPubKey()The static pub key |
(package private) int | getSSUVersion(RouterAddress addr)valid SSU version of Bob's SSU address
for our outbound connections as Alice. |
String | getStyle()Transport style string "SSU". |
(package private) RouterAddress | getTargetAddress(RouterInfo target)first available address we can use. |
int | getTotalOutboundQueueDepth()Total outbound messages queued across all UDP peers. |
Tuner | getTuner()The transport tuner. |
(package private) X25519KeyFactory | getXDHFactory() |
(package private) boolean | hasIPv6Address()For PeerTestManager |
(package private) void | inboundConnectionReceived(boolean isIPv6)Inbound connection received |
(package private) boolean | introducersMaybeRequired(boolean ipv6)MIGHT we require introducers?
This is like introducersRequired, but if we aren't sure, this returns true. |
boolean | isBacklogged(Hash dest) |
boolean | isConnecting(Hash dest)Check if a connection attempt is in progress for the given peer. |
boolean | isEstablished(Hash dest) |
(package private) boolean | isInDropList(RemoteHostId peer)Is in drop list |
(package private) boolean | isSymNatted()Is IPv4 Symmetric NATted? |
(package private) boolean | isTooClose(byte[] ip)Is this IP too close to ours to trust it for
things like relaying? |
boolean | isValid(byte[] addr)An IPv6 address is only valid if we are configured to support IPv6
AND we have a public IPv6 address. |
void | mayDisconnect(Hash peer)Tell the transport that we may disconnect from this peer. |
void | messageReceived(I2NPMessage inMsg,
RouterIdentity remoteIdent,
Hash remoteIdentHash,
long msToReceive,
int bytesReceived)messageReceived. |
protected void | outboundMessageReady()Not used for UDP. |
(package private) PeerState | pickTestPeer(PeerTestState.Role peerRole,
int version,
boolean isIPv6,
RemoteHostId dontInclude)Pick a Bob (if we are Alice) or a Charlie (if we are Bob). |
protected void | removeAddress(boolean ipv6)Remove then tell NTCP that we changed. |
protected void | removeAddress(RouterAddress address)Remove then tell NTCP that we changed. |
(package private) void | removeRecentlyClosed(PeerStateDestroyed peer)Stop listening for packets on a destroyed connection |
protected void | replaceAddress(RouterAddress address)Replace then tell NTCP that we changed. |
(package private) void | send(I2NPMessage msg,
List<OutNetMessage> msgs,
PeerState peer)"injected" message from the EstablishmentManager, plus pending messages to send,
so the messages may be bundled efficiently. |
(package private) void | send(I2NPMessage msg,
PeerState peer)"injected" message from the EstablishmentManager. |
(package private) void | send(List<I2NPMessage> msgs,
PeerState peer)"injected" messages from the EstablishmentManager. |
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) void | send(UDPPacket packet)This sends it directly out, bypassing OutboundMessageFragments. |
(package private) void | sendDestroy(PeerState peer,
int reasonCode)Send a session destroy message, bypassing OMF and PacketPusher. |
(package private) void | sendIfEstablished(OutNetMessage msg)Send only if established, otherwise fail immediately. |
static void | setDataMessageTimeout(long ms)Data message timeout. |
static void | setMaxIbEstablishTime(long ms)Inbound establish timeout. |
static void | setMaxObEstablishTime(long ms)Outbound establish timeout. |
static void | setMessageReceiverThreads(int threads)Target MessageReceiver thread count. |
static void | setPacketHandlerMaxThreads(int handlers)Max packet handler threads. |
(package private) void | setReachabilityStatus(CommSystemFacade.Status status,
boolean isIPv6) |
void | shutdown()Stop all UDP endpoints, handlers, and background threads. |
void | startListening()Start the transport listener. |
void | stopListening()Stop listening. |
void | succeeded(OutboundMessageState msg)Handle a successful outbound message. |
List<RouterAddress> | updateAddress()Rebuild to get updated cost and introducers. |
_t, _t, afterSend, afterSend, afterSend, afterSend, allowLocal, externalAddressRemoved, getContext, getCurrentAddress, getCurrentAddresses, getIP, getIPv6Config, getMaxConnections, getMostRecentErrorMessages, getNextMessage, getSavedLocalAddresses, getSendPool, getSendPoolCapacity, getTargetAddresses, getTransportMaxConnections, hasCurrentAddress, haveCapacity, haveCapacity, isIPv4Firewalled, isIPv6Firewalled, isPubliclyRoutable, isUnreachable, markReachable, markUnreachable, ngettext, renderStatusHTML, renderStatusHTML, resizeSendPool, saveLocalAddress, setIP, setListener, setSendPoolCapacity, stopCleanupJob, wasUnreachablepublic static final int DEFAULT_COST
public static final String DEFAULT_SOURCES
public static final int EXPIRE_TIMEOUT
static final long INTRODUCER_EXPIRATION_MARGIN
public static final int MIN_EXPIRE_TIMEOUT
public static final String PROP_ALLOW_DIRECT
public static final String PROP_BIND_INTERFACE
public static final String PROP_EXTERNAL_HOST
public static final String PROP_EXTERNAL_PORT
public static final String PROP_FORCE_INTRODUCERS
public static final String PROP_INTERNAL_PORT
public static final String PROP_INTRO_KEY
public static final String PROP_IP
public static final String PROP_IP_CHANGE
public static final String PROP_IPV6
public static final String PROP_LAPTOP_MODE
public static final String PROP_PREFER_UDP
public static final String PROP_SOURCES
public static final String PROP_SSU2_IKEY
public static final String PROP_SSU2_SP
public static final int PUBLIC_RELAY_COUNT
static final long[] RATES
static final int SSU2_INT_VERSION
static final String SSU2_VERSION
static final String SSU2_VERSION_ALT
public static final String STYLE
public static final String STYLE2
public UDPTransport(RouterContext ctx, X25519KeyFactory xdh)
ctx - the router contextxdh - non-nullvoid addRecentlyClosed(PeerStateDestroyed peer)
boolean addRemotePeerState(PeerState peer)
peer - the peer state to add or updatepublic void adjustMessageReceiverThreads()
public void adjustPacketHandlerThreads()
public boolean allowConnection()
public TransportBid bid(RouterInfo toAddress, int dataSize)
toAddress - the target router's contact informationdataSize - size of message payload, assumes full 16-byte header,
transports should adjust as necessary for their overheadboolean canIntroduce(boolean ipv6)
boolean canTestAsCharlie(boolean ipv6)
void changePeerAddress(PeerState2 peer, RemoteHostId newAddress)
void changePeerPort(PeerState peer, int newPort)
public int countActivePeers()
countActivePeers in interface TransportcountActivePeers in class TransportImplpublic int countActiveSendPeers()
public int countPeers()
countPeers in interface TransportcountPeers in class TransportImplvoid dropPeer(Hash peer, boolean shouldBanlist, String why)
shouldBanlist - doesn't really, only sets unreachablevoid dropPeer(PeerState peer, boolean shouldBanlist, String why)
shouldBanlist - doesn't really, only sets unreachablevoid externalAddressReceived(Hash from, byte[] hisIP, byte[] ourIP, int ourPort)
from - Hash of inbound destinationhisIP - the IP of the peer telling usourIP - publicly routable IPv4 or IPv6 only, non-nullourPort - >= 1024public void externalAddressReceived(Transport.AddressSource source, byte[] ip, int port)
externalAddressReceived in interface TransportexternalAddressReceived in class TransportImplsource - as defined in Transport.SOURCE_xxxip - publicly routable IPv4 or IPv6, null okport - 0 if unknownpublic void fail(UDPEndpoint endpoint)
endpoint - the endpointpublic void failed(OutboundMessageState msg)
msg - the outbound messagevoid failed(OutboundMessageState msg, boolean allowPeerFailure)
public void failed(OutNetMessage msg, String reason)
msg - the outbound network messagereason - the failure reasonpublic void forceDisconnect(Hash peer)
peer - hash of the peer to forcefully disconnect frompublic void forceDisconnect(Hash peer, String reason)
peer - hash of the peer to forcefully disconnect fromreason - reason for disconnection (for logging)public void forwardPortStatus(byte[] ip,
int port,
int externalPort,
boolean success,
String reason)forwardPortStatus in interface TransportforwardPortStatus in class TransportImplip - may be nullport - the internal portexternalPort - the external port, which for now should always be the same as
the internal port if the forwarding was successful.public String getAltStyle()
getAltStyle in class TransportImplPacketBuilder2 getBuilder2()
public List<Long> getClockSkews()
getClockSkews in interface TransportgetClockSkews in class TransportImplpublic RouterAddress getCurrentExternalAddress(boolean isIPv6)
isIPv6 - true for IPv6, false for IPv4public static long getDataMessageTimeout()
public List<Hash> getEstablished()
EstablishmentManager getEstablisher()
byte[] getExternalIP()
int getExternalPort(boolean ipv6)
InboundMessageFragments getInboundFragments()
SessionKey getIntroKey()
IntroductionManager getIntroManager()
public static long getMaxIbEstablishTime()
public static long getMaxObEstablishTime()
public static int getMessageReceiverThreads()
public double getMessageReceiverUtilization()
public int getMTU(boolean ipv6)
ipv6 - true for IPv6, false for IPv4OutboundMessageFragments getOMF()
PacketHandler getPacketHandler()
public static int getPacketHandlerMaxThreads()
String getPacketHandlerStatus()
public double getPacketHandlerUtilization()
public int[] getPeerCounts()
public Collection<PeerState> getPeers()
PeerState getPeerState(Hash remotePeer)
PeerState2 getPeerState(long rcvConnID)
PeerState getPeerState(RemoteHostId hostInfo)
hostInfo - the remote host and port of the peerList<PeerState> getPeerStatesByIP(RemoteHostId hostInfo)
PeerTestManager getPeerTestManager()
public CommSystemFacade.Status getReachabilityStatus()
getReachabilityStatus in interface TransportgetReachabilityStatus in class TransportImplpublic int getReceiverQueueCapacity()
public int getReceiverQueueSize()
PeerStateDestroyed getRecentlyClosed(long rcvConnID)
public int getRequestedPort()
getRequestedPort in interface TransportgetRequestedPort in class TransportImplpublic int getSSU2MTU(boolean ipv6)
ipv6 - true for IPv6, false for IPv4byte[] getSSU2StaticIntroKey()
byte[] getSSU2StaticPrivKey()
byte[] getSSU2StaticPubKey()
int getSSUVersion(RouterAddress addr)
public String getStyle()
RouterAddress getTargetAddress(RouterInfo target)
public int getTotalOutboundQueueDepth()
public Tuner getTuner()
X25519KeyFactory getXDHFactory()
boolean hasIPv6Address()
void inboundConnectionReceived(boolean isIPv6)
boolean introducersMaybeRequired(boolean ipv6)
public boolean isBacklogged(Hash dest)
isBacklogged in interface TransportisBacklogged in class TransportImpldest - peer hashpublic boolean isConnecting(Hash dest)
TransportImplisConnecting in interface TransportisConnecting in class TransportImpldest - hash of the peer to checkpublic boolean isEstablished(Hash dest)
isEstablished in interface TransportisEstablished in class TransportImpldest - peer hashboolean isInDropList(RemoteHostId peer)
boolean isSymNatted()
boolean isTooClose(byte[] ip)
ip - IPv4 or IPv6public final boolean isValid(byte[] addr)
addr - may be null, returns falsepublic void mayDisconnect(Hash peer)
mayDisconnect in interface TransportmayDisconnect in class TransportImplpeer - hash of the peer that may be disconnectedpublic void messageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived)
messageReceived in class TransportImplinMsg - non-nullremoteIdent - may be nullremoteIdentHash - may be null, calculated from remoteIdent if nullmsToReceive - the msToReceiveprotected void outboundMessageReady()
outboundMessageReady in class TransportImplPeerState pickTestPeer(PeerTestState.Role peerRole, int version, boolean isIPv6, RemoteHostId dontInclude)
peerRole - The role of the peer we are looking for, BOB or CHARLIE only (NOT our role)version - 1 or 2 for role CHARLIE; ignored for role BOBisIPv6 - true to get a v6-capable peer backdontInclude - may be nullprotected void removeAddress(boolean ipv6)
removeAddress in class TransportImplipv6 - true to remove all IPv6 addresses, false to remove all IPv4 addressesprotected void removeAddress(RouterAddress address)
removeAddress in class TransportImpladdress - the addressvoid removeRecentlyClosed(PeerStateDestroyed peer)
protected void replaceAddress(RouterAddress address)
replaceAddress in class TransportImpladdress - the new address or null to remove allvoid send(I2NPMessage msg, List<OutNetMessage> msgs, PeerState peer)
msg - may be null if nothing to injectmsgs - non-null, may be emptypeer - all messages MUST be going to this peervoid send(I2NPMessage msg, PeerState peer)
peer - the message MUST be going to this peervoid send(List<I2NPMessage> msgs, PeerState peer)
peer - all messages MUST be going to this peerpublic void send(OutNetMessage msg)
TransportImplsend in interface Transportsend in class TransportImplmsg - the message to send, containing destination, payload, and callbacksvoid send(UDPPacket packet)
void sendDestroy(PeerState peer, int reasonCode)
reasonCode - SSU2 only, ignored for SSU1void sendIfEstablished(OutNetMessage msg)
public static void setDataMessageTimeout(long ms)
ms - the data message timeout, bounded 15000-120000mspublic static void setMaxIbEstablishTime(long ms)
ms - the inbound establish timeout, bounded 1500-5000mspublic static void setMaxObEstablishTime(long ms)
ms - the outbound establish timeout, bounded 1500-5000mspublic static void setMessageReceiverThreads(int threads)
threads - message receiver thread countpublic static void setPacketHandlerMaxThreads(int handlers)
handlers - max packet handler threadsvoid setReachabilityStatus(CommSystemFacade.Status status, boolean isIPv6)
isIPv6 - Is the change an IPv6 change?public void shutdown()
public void startListening()
public void stopListening()
public void succeeded(OutboundMessageState msg)
msg - the outbound messagepublic List<RouterAddress> updateAddress()
updateAddress in interface TransportupdateAddress in class TransportImpl