- All Implemented Interfaces:
Service
- Direct Known Subclasses:
CommSystemFacadeImpl, VMCommSystem
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumNetwork connectivity status enumeration for IPv4 and IPv6 transport capabilities.Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringBundle holding the translatable messages this subsystem logs.static final shortWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people.static final shortWe have no network interface at all enabled transports.static final shortOur detection system is broken (SSU bind port failed).static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people We can receive unsolicited connections on IPv6.static final shortWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people We might be able to receive unsolicited connections on IPv6.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortWe have an IPv6 transport enabled and a public IPv6 address.static final shortThese must be increasing in "badness" (see TransportManager.java), but UNKNOWN must be last.static final shortWe are able to talk to peers that we initiate communication with, but cannot receive unsolicited connections, i.e.static final shortOur reachability is unknown on all.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNot instantiable; a RouterContext subclass supplies the implementation.Method Summary
Modifier and TypeMethodDescriptionabstract intHow many peers are we currently connected to, that we have sent a message to or received a message from in the last five minutes.abstract intHow many peers we have sent a message to in the last minute.Create the list of RouterAddress structures based on the router's config.abstract booleanWhether reverse DNS lookups of router IPs are enabled.voidexemptIncoming(Hash peer) Exempt this router hash from any incoming throttles or rejections.voidforceDisconnect(Hash peer) Tell the comm system to disconnect from this peer.voidforceDisconnect(Hash peer, String reason) Tell the comm system to disconnect from this peer with a reason.getCanonicalHostName(String ipAddress) Look up the canonical hostname for the given IP, blocking on DNS if necessary.getCanonicalHostNameSync(String ipAddress) Synchronous canonical hostname lookup for the given IP.The map of all country codes.getCountry(String ip) Get the two-letter country code for the given IP address.getCountry(Hash peer) Get the two-letter country code for the given peer's IP address.getCountryName(String code) Resolve a two-letter country code to its full country name.Get all the peers we are connected to.longgetFramedAveragePeerClockSkew(int percentToInclude) Return framed average clock skew of connected peers in seconds, or null if we cannot answer.byte[]Get the IP address associated with the given destination.getLocalHostName(String ipAddress) Fast hostname lookup that never blocks on network DNS.Localized reachability status string.Median clock skew of connected peers in seconds, or null if we cannot answer.Retrieve recent transport-related error messages for display in the console.Our two-letter country code determined from our external IP.Determine under what conditions we are remotely reachable.Registered transports by style name.Factory for making X25519 key pairs.booleanReport whether outbound bandwidth is operating well below its limit.booleanhaveInboundCapacity(int pct) Report whether inbound bandwidth has capacity for the given percentage load.booleanhaveOutboundCapacity(int pct) Report whether outbound bandwidth has capacity for the given percentage load.voidRouter must call after netdb is initialized.booleanisBacklogged(Hash peer) Check whether the given peer has excessive pending outbound messages.booleanisConnecting(Hash peer) Check if any transport has a connection attempt in progress for the given peer (handshake started but not yet complete).booleanisDummy()Whether this is a dummy implementation with no real transports.abstract booleanisEstablished(Hash peer) Check whether a transport connection exists with the given peer.booleanIs this IP exempt from any incoming throttles or rejections.booleanWhether country blocking is enabled at all.booleanisInStrictCountry(Hash peer) Whether the given peer's country is blocked.booleanWhether the given router's country is blocked.booleanWhether the comm system is fully initialized and running.voidmayDisconnect(Hash peer) Tell the comm system that we may disconnect from this peer.voidnotifyRemoveAddress(boolean ipv6) Tell other transports our address changed.voidnotifyRemoveAddress(RouterAddress address) Tell other transports our address changed.voidnotifyReplaceAddress(RouterAddress address) Tell other transports our address changed.abstract voidQueue an outbound message for delivery through the appropriate transport.voidqueueLookup(byte[] ip) Queue a reverse-DNS lookup for the given IP address.voidRegister a transport for use by the comm system.voidRemove this IP from the exemptions.renderPeerCaps(Hash peer, boolean inline) Render the peer's capabilities as HTML, optionally inline.renderPeerFlag(Hash peer) Render the country flag for the given peer as HTML.renderPeerHTML(Hash peer, boolean extended) Render an HTML snippet identifying the given peer, optionally with extended details.voidrenderStatusHTML(Writer out) Render the transport status section of the router console page with default flags.voidrenderStatusHTML(Writer out, String urlBase, int sortFlags) Render the transport status section of the router console page.voidUnregister a transport from the comm system.abstract booleanwasFailsafeClosed(Hash peer, long withinMs) Whether any transport closed a session to the given peer for idleness within the given window.booleanwasUnreachable(Hash peer) Check whether the given peer was recently unreachable.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Details
ROUTER_BUNDLE_NAME
Bundle holding the translatable messages this subsystem logs.- See Also:
STATUS_OK
public static final short STATUS_OKThese must be increasing in "badness" (see TransportManager.java), but UNKNOWN must be last.We are able to receive unsolicited connections on all enabled transports.
- See Also:
STATUS_IPV4_OK_IPV6_UNKNOWN
public static final short STATUS_IPV4_OK_IPV6_UNKNOWNWe have an IPv6 transport enabled and a public IPv6 address. We can receive unsolicited connections on IPv4. We might be able to receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_OK_IPV6_FIREWALLED
public static final short STATUS_IPV4_OK_IPV6_FIREWALLEDWe have an IPv6 transport enabled and a public IPv6 address. We can receive unsolicited connections on IPv4. We cannot receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_UNKNOWN_IPV6_OK
public static final short STATUS_IPV4_UNKNOWN_IPV6_OKWe have an IPv6 transport enabled and a public IPv6 address. We may be able to receive unsolicited connections on IPv4. We can receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_FIREWALLED_IPV6_OK
public static final short STATUS_IPV4_FIREWALLED_IPV6_OKWe have an IPv6 transport enabled and a public IPv6 address. We cannot receive unsolicited connections on IPv4. We can receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_DISABLED_IPV6_OK
public static final short STATUS_IPV4_DISABLED_IPV6_OKWe have an IPv6 transport enabled and a public IPv6 address. IPv4 is disabled. We can receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_SNAT_IPV6_OK
public static final short STATUS_IPV4_SNAT_IPV6_OKWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people We can receive unsolicited connections on IPv6.- See Also:
STATUS_DIFFERENT
public static final short STATUS_DIFFERENTWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people.- See Also:
STATUS_IPV4_SNAT_IPV6_UNKNOWN
public static final short STATUS_IPV4_SNAT_IPV6_UNKNOWNWe are behind a symmetric NAT which will make our 'from' address look differently when we talk to multiple people We might be able to receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_FIREWALLED_IPV6_UNKNOWN
public static final short STATUS_IPV4_FIREWALLED_IPV6_UNKNOWNWe have an IPv6 transport enabled and a public IPv6 address. We cannot receive unsolicited connections on IPv4. We might be able to receive unsolicited connections on IPv6.- See Also:
STATUS_REJECT_UNSOLICITED
public static final short STATUS_REJECT_UNSOLICITEDWe are able to talk to peers that we initiate communication with, but cannot receive unsolicited connections, i.e. Firewalled, on all enabled transports.- See Also:
STATUS_IPV4_UNKNOWN_IPV6_FIREWALLED
public static final short STATUS_IPV4_UNKNOWN_IPV6_FIREWALLEDWe have an IPv6 transport enabled and a public IPv6 address. We may be able to receive unsolicited connections on IPv4. We cannot receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_DISABLED_IPV6_UNKNOWN
public static final short STATUS_IPV4_DISABLED_IPV6_UNKNOWNWe have an IPv6 transport enabled and a public IPv6 address. IPv4 is disabled. We might be able to receive unsolicited connections on IPv6.- See Also:
STATUS_IPV4_DISABLED_IPV6_FIREWALLED
public static final short STATUS_IPV4_DISABLED_IPV6_FIREWALLEDWe have an IPv6 transport enabled and a public IPv6 address. IPv4 is disabled. We can receive unsolicited connections on IPv6.- See Also:
STATUS_DISCONNECTED
public static final short STATUS_DISCONNECTEDWe have no network interface at all enabled transports.- See Also:
STATUS_HOSED
public static final short STATUS_HOSEDOur detection system is broken (SSU bind port failed).- See Also:
STATUS_UNKNOWN
public static final short STATUS_UNKNOWNOur reachability is unknown on all.- See Also:
Constructor Details
CommSystemFacade
protected CommSystemFacade()Not instantiable; a RouterContext subclass supplies the implementation.
Method Details
processMessage
Queue an outbound message for delivery through the appropriate transport.- Parameters:
msg- the message to send
renderStatusHTML
Render the transport status section of the router console page.- Parameters:
out- receives the HTML for this transport's status sectionurlBase- base URL for links, may be nullsortFlags- flags controlling sort order- Throws:
IOException- on write error
renderStatusHTML
Render the transport status section of the router console page with default flags.- Specified by:
renderStatusHTMLin interfaceService- Parameters:
out- receives the HTML for this transport's status section- Throws:
IOException- on write error
createAddresses
Create the list of RouterAddress structures based on the router's config.- Returns:
- the published addresses, empty when none are configured
countActivePeers
public abstract 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.- Returns:
- the number of active peers
countActiveSendPeers
public abstract int countActiveSendPeers()How many peers we have sent a message to in the last minute.Narrower than
countActivePeers()in both respects that matter: send only, and a one-minute window rather than the transport's active window. The pair answers different questions - how many peers we can reach against how many we are actually driving traffic to right now.- Returns:
- the number of peers sent to in the last minute
haveInboundCapacity
public boolean haveInboundCapacity(int pct) Report whether inbound bandwidth has capacity for the given percentage load.- Parameters:
pct- percentage of bandwidth currently in use- Returns:
- true if capacity is available
haveOutboundCapacity
public boolean haveOutboundCapacity(int pct) Report whether outbound bandwidth has capacity for the given percentage load.- Parameters:
pct- percentage of bandwidth currently in use- Returns:
- true if capacity is available
haveHighOutboundCapacity
public boolean haveHighOutboundCapacity()Report whether outbound bandwidth is operating well below its limit.- Returns:
- true if high outbound capacity is available
getMostRecentErrorMessages
getMedianPeerClockSkew
Median clock skew of connected peers in seconds, or null if we cannot answer. CommSystemFacadeImpl overrides this.- Returns:
- the median peer clock skew
getFramedAveragePeerClockSkew
public long getFramedAveragePeerClockSkew(int percentToInclude) Return framed average clock skew of connected peers in seconds, or null if we cannot answer. CommSystemFacadeImpl overrides this.- Parameters:
percentToInclude- percentage of peers to include in the frame- Returns:
- average skew in seconds
getStatus
Determine under what conditions we are remotely reachable.- Returns:
- the reachability
CommSystemFacade.Status,CommSystemFacade.Status.OKunless an implementation overrides this
getLocalizedStatusString
Localized reachability status string.- Returns:
- the localized status string
isBacklogged
Check whether the given peer has excessive pending outbound messages.- Parameters:
peer- the router to test, identified by its router identity hash- Returns:
- true if the peer is backlogged
wasUnreachable
Check whether the given peer was recently unreachable.- Parameters:
peer- the router to test, identified by its router identity hash- Returns:
- true if the peer was unreachable
isEstablished
Check whether a transport connection exists with the given peer.- Parameters:
peer- the router to test, identified by its router identity hash- Returns:
- true if a connection is established
wasFailsafeClosed
Whether any transport closed a session to the given peer for idleness within the given window.True means this router declined to keep talking to the peer, which is the opposite of the peer having gone away. Callers attribute a later loss of connectivity with it, and must treat a false as "no information" rather than as evidence the peer is at fault: only a transport that remembers the close can answer, and an answer of false covers never-established, still-open, and closed-for-other-reasons alike.
- Parameters:
peer- the peer to ask about, non-nullwithinMs- how far back counts as recent in ms; non-positive means nothing is recent- Returns:
- true when some transport closed a session to the peer that recently
isConnecting
Check if any transport has a connection attempt in progress for the given peer (handshake started but not yet complete).- Parameters:
peer- hash of the peer to check- Returns:
- true if at least one transport is currently establishing
getIP
Get the IP address associated with the given destination.- Parameters:
dest- the destination hash to resolve; no entry means null is returned- Returns:
- IP address bytes or null if unknown
queueLookup
public void queueLookup(byte[] ip) Queue a reverse-DNS lookup for the given IP address.- Parameters:
ip- IP address bytes to look up
mayDisconnect
Tell the comm system that we may disconnect from this peer. This is advisory only.- Parameters:
peer- the peer we may drop
forceDisconnect
Tell the comm system to disconnect from this peer.- Parameters:
peer- the peer to disconnect from
forceDisconnect
getOurCountry
Our two-letter country code determined from our external IP.- Returns:
- the our country
isInStrictCountry
public boolean isInStrictCountry()Whether country blocking is enabled at all.- Returns:
- whether in strict country
isInStrictCountry
Whether the given peer's country is blocked.- Parameters:
peer- peer to check- Returns:
- whether in strict country
isInStrictCountry
Whether the given router's country is blocked.- Parameters:
ri- router info to check- Returns:
- whether in strict country
getCountry
getCountry
getCountryName
getCountries
renderPeerHTML
renderPeerFlag
renderPeerCaps
getCanonicalHostName
getCanonicalHostNameSync
getLocalHostName
Fast hostname lookup that never blocks on network DNS. Returns cached result if available, otherwise does a local ASN lookup. Queues background async RDNS if enabled, updating the cache on success.- Parameters:
ipAddress- the address to resolve, as text- Returns:
- hostname from cache, ASN org name, or null if not resolvable
enableReverseLookups
public abstract boolean enableReverseLookups()Whether reverse DNS lookups of router IPs are enabled. Single source of truth for therouterconsole.enableReverseLookupssetting; used by the comm system, netDb, and the console UI.- Returns:
- true if reverse lookups are enabled
getTransports
getEstablished
Get all the peers we are connected to. This should be more efficient than repeated calls toisEstablished(Hash)if you have to check a lot.- Returns:
- the hashes of all the routers we are connected to, non-null
isDummy
public boolean isDummy()Whether this is a dummy implementation with no real transports.- Returns:
- true for this base implementation, which carries no transports
isRunning
public boolean isRunning()Whether the comm system is fully initialized and running.- Returns:
- true when the comm system is running
notifyReplaceAddress
Tell other transports our address changed.- Parameters:
address- the address that replaced the previous one
notifyRemoveAddress
Tell other transports our address changed.- Parameters:
address- the address that was removed
notifyRemoveAddress
public void notifyRemoveAddress(boolean ipv6) Tell other transports our address changed.- Parameters:
ipv6- true to remove the IPv6 address, false for IPv4
registerTransport
Register a transport for use by the comm system.- Parameters:
t- the transport to register
unregisterTransport
Unregister a transport from the comm system.- Parameters:
t- the transport to unregister
getXDHFactory
initGeoIP
public void initGeoIP()Router must call after netdb is initialized.exemptIncoming
Exempt this router hash from any incoming throttles or rejections.- Parameters:
peer- the router to exempt
isExemptIncoming
Is this IP exempt from any incoming throttles or rejections.- Parameters:
ip- the address to test- Returns:
- whether exempt incoming
removeExemption
Remove this IP from the exemptions.- Parameters:
ip- the address to remove from the exemptions