Package net.i2p.router.transport.ntcp
Class NTCPTransport
java.lang.Object
net.i2p.router.transport.TransportImpl
net.i2p.router.transport.ntcp.NTCPTransport
- All Implemented Interfaces:
Transport
public class NTCPTransport extends TransportImpl
The NIO TCP transport
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.i2p.router.transport.Transport
Transport.AddressSource -
Field Summary
Fields Modifier and Type Field Description static intESTABLISH_TIMEOUThow long from initial connection attempt (accept() or connect()) until the con must be established to avoid premature close()ingstatic StringMIN_SIGTYPE_VERSIONRI sigtypes supported in 0.9.16(package private) static intNTCP2_INT_VERSION(package private) static StringNTCP2_VERSION"2"(package private) static StringNTCP2_VERSION_ALT"2,"static StringPROP_BIND_INTERFACEthis is rarely if ever used, default is to bind to wildcard addressstatic StringPROP_I2NP_NTCP_AUTO_IPstatic StringPROP_I2NP_NTCP_AUTO_PORTstatic StringPROP_I2NP_NTCP_HOSTNAMEstatic StringPROP_I2NP_NTCP_PORTstatic StringPROP_NTCP2_IVb64 static IVstatic StringPROP_NTCP2_SPb64 static private keystatic StringSTYLEstatic StringSTYLE2Fields inherited from class net.i2p.router.transport.TransportImpl
_context, _currentAddresses, ADJUST_COST, CAP_IPV4, CAP_IPV4_IPV6, CAP_IPV6, CONGESTION_COST_ADJUSTMENT, PROP_IPV6_FIREWALLED -
Constructor Summary
Constructors Constructor Description NTCPTransport(RouterContext ctx, DHSessionKeyBuilder.Factory dh, X25519KeyFactory xdh) -
Method Summary
Modifier and Type Method Description voidafterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend)The transport is done sending this message.booleanallowConnection()TransportBidbid(RouterInfo toAddress, int dataSize)intcountActivePeers()How many peers have we talked to in the last minute? As of 0.9.20, actually returns active peer count, not total.intcountActiveSendPeers()How many peers are we actively sending messages to (this minute)intcountPeers()How many peers are we connected to?(package private) voidestablishing(NTCPConnection con)add us to the establishment timeout process(package private) voidexpireTimedOut()called in the EventPumper no more than once a second or so, closing any unconnected/unestablished connectionsvoidexternalAddressReceived(Transport.AddressSource source, byte[] ip, int port)UDP changed addresses, tell NTCP and (possibly) restartvoidexternalAddressRemoved(Transport.AddressSource source, boolean ipv6)Notify a transport of an external address change.voidforceDisconnect(Hash peer)Tell the transport to disconnect from this peer.voidforwardPortStatus(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.StringgetAltStyle()An alternate supported styleList<Long>getClockSkews()Return our peer clock skews on this transport.Set<Hash>getEstablished()Connected peers.(package private) byte[]getNTCP2StaticIV()The static IV(package private) byte[]getNTCP2StaticPrivkey()The static priv key(package private) byte[]getNTCP2StaticPubkey()The static priv keyCollection<NTCPConnection>getPeers()For /peers UI only.(package private) EventPumpergetPumper()Hook for NTCPConnectionCommSystemFacade.StatusgetReachabilityStatus()Maybe we should trust UPnP here and report OK if it opened the port, but for now we don't.(package private) ReadergetReader()Hook for NTCPConnectionintgetRequestedPort()What INTERNAL port would the transport like to have forwarded by UPnP.StringgetStyle()The unique identity of this Transport(package private) WritergetWriter()Hook for NTCPConnection(package private) X25519KeyFactorygetXDHFactory()(package private) NTCPConnectioninboundEstablished(NTCPConnection con)booleanisAlive()booleanisBacklogged(Hash dest)booleanisEstablished(Hash dest)(package private) booleanisHXHIValid(byte[] hxhi)Incoming connection replay detection.voidmayDisconnect(Hash peer)Tell the transport that we may disconnect from this peer.protected voidoutboundMessageReady()This message is called whenever a new message is added to the send pool, and it should not block Only used by NTCP.(package private) NTCPConnectionremoveCon(NTCPConnection con)voidrenderStatusHTML(Writer out, int sortFlags)voidrenderStatusHTML(Writer out, String urlBase, int sortFlags)Deprecated.as of 0.9.31(package private) voidsendComplete(OutNetMessage msg)queue up afterSend call, which can take some time w/ jobs, etc(package private) voidsetLastBadSkew(long skew)A positive number means our clock is ahead of theirs.voidstartListening()Called by TransportManager.voidstopListening()This doesn't (completely) block, caller should check isAlive() before calling startListening() or restartListening()Methods inherited from class net.i2p.router.transport.TransportImpl
_t, _t, afterSend, afterSend, afterSend, allowLocal, getCurrentAddress, getCurrentAddresses, getIP, getIPv6Config, getMaxConnections, getMostRecentErrorMessages, getNextMessage, getSavedLocalAddresses, getTargetAddresses, hasCurrentAddress, haveCapacity, haveCapacity, isIPv4Firewalled, isIPv6Firewalled, isPubliclyRoutable, isUnreachable, markReachable, markUnreachable, messageReceived, ngettext, recheckReachability, removeAddress, removeAddress, renderStatusHTML, replaceAddress, saveLocalAddress, send, setIP, setListener, updateAddress, wasUnreachable
-
Field Details
-
PROP_I2NP_NTCP_HOSTNAME
- See Also:
- Constant Field Values
-
PROP_I2NP_NTCP_PORT
- See Also:
- Constant Field Values
-
PROP_I2NP_NTCP_AUTO_PORT
- See Also:
- Constant Field Values
-
PROP_I2NP_NTCP_AUTO_IP
- See Also:
- Constant Field Values
-
PROP_BIND_INTERFACE
this is rarely if ever used, default is to bind to wildcard address- See Also:
- Constant Field Values
-
MIN_SIGTYPE_VERSION
RI sigtypes supported in 0.9.16- See Also:
- Constant Field Values
-
STYLE
- See Also:
- Constant Field Values
-
STYLE2
- See Also:
- Constant Field Values
-
NTCP2_INT_VERSION
static final int NTCP2_INT_VERSION- See Also:
- Constant Field Values
-
NTCP2_VERSION
"2" -
NTCP2_VERSION_ALT
"2," -
PROP_NTCP2_SP
b64 static private key- See Also:
- Constant Field Values
-
PROP_NTCP2_IV
b64 static IV- See Also:
- Constant Field Values
-
ESTABLISH_TIMEOUT
public static final int ESTABLISH_TIMEOUThow long from initial connection attempt (accept() or connect()) until the con must be established to avoid premature close()ing- See Also:
- Constant Field Values
-
-
Constructor Details
-
NTCPTransport
- Parameters:
dh- unused, ignoredxdh- null to disable NTCP2
-
-
Method Details
-
inboundEstablished
- Parameters:
con- that is established- Returns:
- the previous connection to the same peer, must be closed by caller, null if no such.
-
outboundMessageReady
protected void outboundMessageReady()Description copied from class:TransportImplThis message is called whenever a new message is added to the send pool, and it should not block Only used by NTCP. SSU throws UOE.- Specified by:
outboundMessageReadyin classTransportImpl
-
afterSend
public void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend)Description copied from class:TransportImplThe transport is done sending this message. This is the method that actually does all of the cleanup - firing off jobs, requeueing, updating stats, etc.- Overrides:
afterSendin classTransportImpl- Parameters:
msg- 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 peer
-
bid
dataSize- assumes full 16-byte header, transports should adjust as necessary- Returns:
- a bid or null if unwilling to send
-
allowConnection
public boolean allowConnection() -
sendComplete
queue up afterSend call, which can take some time w/ jobs, etc -
isEstablished
- Specified by:
isEstablishedin interfaceTransport- Overrides:
isEstablishedin classTransportImpl
-
isBacklogged
- Specified by:
isBackloggedin interfaceTransport- Overrides:
isBackloggedin classTransportImpl
-
mayDisconnect
Tell the transport that we may disconnect from this peer. This is advisory only.- Specified by:
mayDisconnectin interfaceTransport- Overrides:
mayDisconnectin classTransportImpl- Since:
- 0.9.24
-
forceDisconnect
Tell the transport to disconnect from this peer.- Since:
- 0.9.38
-
removeCon
- Returns:
- usually the con passed in, but possibly a second connection with the same peer... only con or null as of 0.9.37
-
countPeers
public int countPeers()Description copied from class:TransportImplHow many peers are we connected to?- Specified by:
countPeersin interfaceTransport- Specified by:
countPeersin classTransportImpl
-
getPeers
For /peers UI only. Not a public API, not for external use.- Returns:
- not a copy, do not modify
- Since:
- 0.9.31
-
getEstablished
Connected peers.- Returns:
- a copy, modifiable
- Since:
- 0.9.34
-
countActivePeers
public 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.- Specified by:
countActivePeersin interfaceTransport- Specified by:
countActivePeersin classTransportImpl
-
countActiveSendPeers
public int countActiveSendPeers()How many peers are we actively sending messages to (this minute)- Specified by:
countActiveSendPeersin interfaceTransport- Specified by:
countActiveSendPeersin classTransportImpl
-
setLastBadSkew
void setLastBadSkew(long skew)A positive number means our clock is ahead of theirs.- Parameters:
skew- in seconds
-
getClockSkews
Return our peer clock skews on this transport. List composed of Long, each element representing a peer skew in seconds. A positive number means our clock is ahead of theirs.- Specified by:
getClockSkewsin interfaceTransport- Overrides:
getClockSkewsin classTransportImpl
-
isHXHIValid
boolean isHXHIValid(byte[] hxhi)Incoming connection replay detection. As there is no timestamp in the first message, we can't detect something long-delayed. To be fixed in next version of NTCP.- Parameters:
hxhi- using first 8 bytes only- Returns:
- valid
- Since:
- 0.9.12
-
startListening
public void startListening()Called by TransportManager. Caller should stop the transport first, then verify stopped with isAlive() Unfortunately TransportManager doesn't do that, so we check here to prevent two pumpers. -
isAlive
public boolean isAlive() -
getReader
Reader getReader()Hook for NTCPConnection -
getWriter
Writer getWriter()Hook for NTCPConnection -
getStyle
Description copied from interface:TransportThe unique identity of this Transport- Returns:
- always "NTCP"
-
getAltStyle
An alternate supported style- Overrides:
getAltStylein classTransportImpl- Returns:
- "NTCP2" always
- Since:
- 0.9.35
-
getPumper
EventPumper getPumper()Hook for NTCPConnection -
getXDHFactory
X25519KeyFactory getXDHFactory()- Returns:
- null if not configured for NTCP2
- Since:
- 0.9.36
-
establishing
add us to the establishment timeout process -
expireTimedOut
void expireTimedOut()called in the EventPumper no more than once a second or so, closing any unconnected/unestablished connections -
getNTCP2StaticPubkey
byte[] getNTCP2StaticPubkey()The static priv key- Since:
- 0.9.36
-
getNTCP2StaticPrivkey
byte[] getNTCP2StaticPrivkey()The static priv key- Since:
- 0.9.35
-
getNTCP2StaticIV
byte[] getNTCP2StaticIV()The static IV- Since:
- 0.9.36
-
externalAddressReceived
UDP changed addresses, tell NTCP and (possibly) restart- Specified by:
externalAddressReceivedin interfaceTransport- Specified by:
externalAddressReceivedin classTransportImpl- Parameters:
ip- 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 unchanged- Since:
- IPv6 moved from CSFI.notifyReplaceAddress()
-
externalAddressRemoved
Notify a transport of an external address change. This may be from a local interface, UPnP, a config change, etc. This should not be called if the ip didn't change (from that source's point of view), or is a local address. May be called multiple times for IPv4 or IPv6. The transport should also do its own checking on whether to accept notifications from this source. This can be called after the transport is running. TODO externalAddressRemoved(source, ip, port)- Specified by:
externalAddressRemovedin interfaceTransport- Overrides:
externalAddressRemovedin classTransportImpl- Parameters:
source- defined in Transport.java- Since:
- 0.9.20
-
forwardPortStatus
public 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. If it fails, we don't know if it's because there is no firewall, or if the firewall rejected the request. So we just use the SSU reachability status to decide whether to enable inbound NTCP. SSU will have CSFI build a new NTCP address when it transitions to OK.- Specified by:
forwardPortStatusin interfaceTransport- Overrides:
forwardPortStatusin classTransportImpl- Parameters:
ip- 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.
-
getRequestedPort
public int getRequestedPort()Description copied from class:TransportImplWhat INTERNAL port would the transport like to have forwarded by UPnP. This can't be passed via getCurrentAddress(), as we have to open the port before we can publish the address, and that's the external port anyway.- Specified by:
getRequestedPortin interfaceTransport- Overrides:
getRequestedPortin classTransportImpl- Returns:
- current IPv4 port, else NTCP configured port, else -1 (but not UDP port if auto)
-
getReachabilityStatus
Maybe we should trust UPnP here and report OK if it opened the port, but for now we don't. Just go through and if we have one inbound connection, we must be good. As we drop idle connections pretty quickly, this will be fairly accurate. We have to be careful here because much of the router console code assumes that the reachability status is really just the UDP status. This only returns OK, DISABLED, or UNKNOWN for IPv4 and IPv6. We leave the FIREWALLED status for UDP. Previously returned short, now enum as of 0.9.20- Specified by:
getReachabilityStatusin interfaceTransport- Specified by:
getReachabilityStatusin classTransportImpl
-
stopListening
public void stopListening()This doesn't (completely) block, caller should check isAlive() before calling startListening() or restartListening() -
renderStatusHTML
- Throws:
IOException
-
renderStatusHTML
@Deprecated public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOExceptionDeprecated.as of 0.9.31Does nothing- Specified by:
renderStatusHTMLin interfaceTransport- Overrides:
renderStatusHTMLin classTransportImpl- Throws:
IOException
-