public class NTCPTransport extends TransportImpl
Transport.AddressSource| Modifier and Type | Field and Description |
|---|---|
(package private) static int | ESTABLISH_TIMEOUThow long from initial connection attempt (accept() or connect()) until
the con must be established to avoid premature close()ing. |
static String | MIN_SIGTYPE_VERSIONRI sigtypes supported in 0.9.16 |
(package private) static int | NTCP2_INT_VERSIONN t c p2 i n t v e r s i o n |
(package private) static String | NTCP2_VERSION"2" |
(package private) static String | NTCP2_VERSION_ALT"2," |
(package private) static int | PQ_INT_VERSION0 to disable, or 3/4/5 for enctypes 5/6/7 |
(package private) static String | PQ_VERSIONP q v e r s i o n |
static String | PROP_BIND_INTERFACEthis is rarely if ever used, default is to bind to wildcard address |
static String | PROP_I2NP_NTCP_AUTO_IPPROP_I2NP_NTCP_AUTO_IP. |
static String | PROP_I2NP_NTCP_AUTO_PORTPROP_I2NP_NTCP_AUTO_PORT. |
static String | PROP_I2NP_NTCP_HOSTNAMEPROP_I2NP_NTCP_HOSTNAME. |
static String | PROP_I2NP_NTCP_PORTPROP_I2NP_NTCP_PORT. |
static String | PROP_NTCP2_IVb64 static IV |
static String | PROP_NTCP2_SPb64 static private key |
static String | STYLESTYLE. |
static String | STYLE2STYLE2. |
_context, ADJUST_COST, CAP_IPV4, CAP_IPV4_IPV6, CAP_IPV6, CONGESTION_COST_ADJUSTMENT, PROP_BOOST_CONNECTION_LIMITS, PROP_IPV6_FIREWALLED| Constructor and Description |
|---|
NTCPTransport(RouterContext ctx,
X25519KeyFactory xdh) |
| Modifier and Type | Method and Description |
|---|---|
void | adjustReaderThreads()Adjust reader threads to match configured count. |
void | adjustSendFinisherThreads(int threads)Adjusts the send finisher thread count for the running pool. |
void | adjustWriterThreads()Adjust writer threads to match configured count. |
void | afterSend(OutNetMessage msg,
boolean sendSuccessful,
boolean allowRequeue,
long msToSend)afterSend. |
boolean | allowConnection()allowConnection. |
TransportBid | bid(RouterInfo toAddress,
int dataSize)bid. |
int | countActivePeers()How many peers have we talked to in the last minute?
As of 0.9.20, actually returns active peer count, not total. |
int | countActiveSendPeers()How many peers are we actively sending messages to (this minute) |
int | countPeers()countPeers. |
(package private) void | establishing(NTCPConnection con)add us to the establishment timeout process |
(package private) void | expireTimedOut()called in the EventPumper no more than once a second or so, closing
any unconnected/unestablished connections |
void | externalAddressReceived(Transport.AddressSource source,
byte[] ip,
int port)UDP changed addresses, tell NTCP and (possibly) restart |
void | externalAddressRemoved(Transport.AddressSource source,
boolean ipv6)Notify a transport of an external address change. |
void | forceDisconnect(Hash peer)Tell the transport to disconnect from this peer. |
void | forceDisconnect(Hash peer,
String reason)Tell the transport to disconnect from this peer with a reason for logging. |
void | forwardPortStatus(byte[] ip,
int port,
int externalPort,
boolean success,
String reason)If we didn't used to be forwarded, and we have an address,
and we are configured to use UPnP, update our RouterAddress
Don't do anything now. |
String | getAltStyle()Get the alternate supported style. |
List<Long> | getClockSkews()Return our peer clock skews on this transport. |
List<Hash> | getEstablished()Connected peers. |
static int | getEstablishTimeout()Get the NTCP establish timeout in ms. |
static long | getFailsafeIterationFreq()Get the failsafe iteration frequency in milliseconds |
(package private) byte[] | getNTCP2StaticIV()The static IV |
(package private) byte[] | getNTCP2StaticPrivkey()The static priv key |
(package private) byte[] | getNTCP2StaticPubkey()The static priv key |
int[] | getPeerCounts()Get peer counts by transport type and direction. |
Collection<NTCPConnection> | getPeers()For /peers UI only. |
(package private) EventPumper | getPumper()Hook for NTCPConnection |
CommSystemFacade.Status | getReachabilityStatus()Maybe we should trust UPnP here and report OK if it opened the port, but
for now we don't. |
(package private) Reader | getReader()Hook for NTCPConnection |
double | getReaderUtilization()Get reader pool utilization as a ratio (0.0-1.0). |
int | getRequestedPort()What INTERNAL port would the transport like to have forwarded by UPnP. |
static long | getSelectorLoopDelay()Get the selector loop delay in milliseconds |
static int | getSendFinisherMaxThreads()Get the send finisher max threads |
static int | getSendFinisherQueueCapacity()Get the send finisher queue capacity |
int | getSendFinisherQueueSize()Returns the current send finisher queue depth. |
double | getSendFinisherUtilization()Get send finisher pool utilization as a ratio (0.0-1.0). |
String | getStyle()Get the transport style. |
(package private) Writer | getWriter()Hook for NTCPConnection |
double | getWriterUtilization()Get writer pool utilization as a ratio (0.0-1.0). |
(package private) X25519KeyFactory | getXDHFactory() |
(package private) NTCPConnection | inboundEstablished(NTCPConnection con)Registers a newly established inbound connection, replacing any existing connection
for the same peer. |
boolean | isAlive() |
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 | isHXHIValid(byte[] hxhi)Incoming connection replay detection. |
void | mayDisconnect(Hash peer)Tell the transport that we may disconnect from this peer. |
protected void | outboundMessageReady()Processes the next outbound message by retrieving or creating a connection,
preparing it for sending, and handling related failures or bans. |
(package private) NTCPConnection | removeCon(NTCPConnection con) |
(package private) void | sendComplete(OutNetMessage msg)queue up afterSend call, which can take some time w/ jobs, etc |
static void | setEstablishTimeout(int ms)Set the NTCP establish timeout, bounded 1500-10000ms. |
static void | setFailsafeIterationFreq(long ms)Set the failsafe iteration frequency, bounded by MIN-MAX |
(package private) void | setLastBadSkew(long skew)A positive number means our clock is ahead of theirs. |
static void | setSelectorLoopDelay(long ms)Set the selector loop delay, bounded 1-100ms |
static void | setSendFinisherMaxThreads(int threads)Set the send finisher max threads |
static void | setSendFinisherQueueCapacity(int capacity)Set the send finisher queue capacity |
void | startListening()Starts the NTCP transport listening process, ensuring only one pumper is running
by checking existing state since the caller may not stop the transport correctly. |
void | stopListening()This doesn't (completely) block, caller should check isAlive()
before calling startListening() or restartListening() |
_t, _t, afterSend, afterSend, afterSend, allowLocal, getContext, getCurrentAddress, getCurrentAddresses, getIP, getIPv6Config, getMaxConnections, getMostRecentErrorMessages, getNextMessage, getSavedLocalAddresses, getSendPool, getSendPoolCapacity, getTargetAddresses, getTransportMaxConnections, hasCurrentAddress, haveCapacity, haveCapacity, isIPv4Firewalled, isIPv6Firewalled, isPubliclyRoutable, isUnreachable, markReachable, markUnreachable, messageReceived, ngettext, removeAddress, removeAddress, renderStatusHTML, renderStatusHTML, replaceAddress, resizeSendPool, saveLocalAddress, send, setIP, setListener, setSendPoolCapacity, stopCleanupJob, updateAddress, wasUnreachablestatic volatile int ESTABLISH_TIMEOUT
public static final String MIN_SIGTYPE_VERSION
static final int NTCP2_INT_VERSION
static final String NTCP2_VERSION
static final String NTCP2_VERSION_ALT
static final int PQ_INT_VERSION
static final String PQ_VERSION
public static final String PROP_BIND_INTERFACE
public static final String PROP_I2NP_NTCP_AUTO_IP
public static final String PROP_I2NP_NTCP_AUTO_PORT
public static final String PROP_I2NP_NTCP_HOSTNAME
public static final String PROP_I2NP_NTCP_PORT
public static final String PROP_NTCP2_IV
public static final String PROP_NTCP2_SP
public static final String STYLE
public static final String STYLE2
public NTCPTransport(RouterContext ctx, X25519KeyFactory xdh)
ctx - the router contextxdh - null to disable NTCP2public void adjustReaderThreads()
public void adjustSendFinisherThreads(int threads)
threads - new thread count (core and max)public void adjustWriterThreads()
public void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend)
afterSend in class TransportImplmsg - message in questionsendSuccessful - true if the peer received itallowRequeue - true if we should try other transports if availablemsToSend - how long it took to transfer the data to the peerpublic 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 overheadpublic int countActivePeers()
countActivePeers in interface TransportcountActivePeers in class TransportImplpublic int countActiveSendPeers()
public int countPeers()
countPeers in interface TransportcountPeers in class TransportImplvoid establishing(NTCPConnection con)
void expireTimedOut()
public void externalAddressReceived(Transport.AddressSource source, byte[] ip, int port)
externalAddressReceived in interface TransportexternalAddressReceived in class TransportImplip - typ. IPv4 or IPv6 non-local; may be null to indicate IPv4 failure or port info onlysource - defined in Transport.javaport - 0 for unknown or unchangedpublic void externalAddressRemoved(Transport.AddressSource source, boolean ipv6)
externalAddressRemoved in interface TransportexternalAddressRemoved in class TransportImplsource - defined in Transport.javaipv6 - true for IPv6, false for IPv4public void forceDisconnect(Hash peer)
peer - hash of the peer to forcefully disconnect frompublic void forceDisconnect(Hash peer, String reason)
peer - the peerreason - reason for disconnection (for logging), may be nullpublic 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 TransportImplpublic List<Long> getClockSkews()
getClockSkews in interface TransportgetClockSkews in class TransportImplpublic static int getEstablishTimeout()
public static long getFailsafeIterationFreq()
byte[] getNTCP2StaticIV()
byte[] getNTCP2StaticPrivkey()
byte[] getNTCP2StaticPubkey()
public int[] getPeerCounts()
public Collection<NTCPConnection> getPeers()
EventPumper getPumper()
public CommSystemFacade.Status getReachabilityStatus()
getReachabilityStatus in interface TransportgetReachabilityStatus in class TransportImplReader getReader()
public double getReaderUtilization()
public int getRequestedPort()
TransportImplgetRequestedPort in interface TransportgetRequestedPort in class TransportImplpublic static long getSelectorLoopDelay()
public static int getSendFinisherMaxThreads()
public static int getSendFinisherQueueCapacity()
public int getSendFinisherQueueSize()
public double getSendFinisherUtilization()
public String getStyle()
Writer getWriter()
public double getWriterUtilization()
X25519KeyFactory getXDHFactory()
NTCPConnection inboundEstablished(NTCPConnection con)
con - The newly established NTCPConnection.public boolean isAlive()
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 isHXHIValid(byte[] hxhi)
hxhi - using first 8 bytes onlypublic void mayDisconnect(Hash peer)
mayDisconnect in interface TransportmayDisconnect in class TransportImplpeer - hash of the peer that may be disconnectedprotected void outboundMessageReady()
outboundMessageReady in class TransportImplNTCPConnection removeCon(NTCPConnection con)
void sendComplete(OutNetMessage msg)
public static void setEstablishTimeout(int ms)
public static void setFailsafeIterationFreq(long ms)
void setLastBadSkew(long skew)
skew - in secondspublic static void setSelectorLoopDelay(long ms)
public static void setSendFinisherMaxThreads(int threads)
public static void setSendFinisherQueueCapacity(int capacity)
public void startListening()
public void stopListening()