Package net.i2p.router.transport
Class TransportImpl
java.lang.Object
net.i2p.router.transport.TransportImpl
- All Implemented Interfaces:
Transport
- Direct Known Subclasses:
NTCPTransport,UDPTransport
Defines a way to send a message to another peer and start listening for messages
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.i2p.router.transport.Transport
Transport.AddressSource -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RouterContextprotected final List<RouterAddress>protected static final booleanDo we increase the advertised cost when approaching conn limits?static final Stringstatic final Stringstatic final Stringprotected static final intTODO change to 2protected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringTranslateprotected StringTranslateprotected voidafterSend(OutNetMessage msg, boolean sendSuccessful) The transport is done sending this messageprotected voidafterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue) The transport is done sending this messageprotected voidafterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend) The transport is done sending this message.protected voidafterSend(OutNetMessage msg, boolean sendSuccessful, long msToSend) The transport is done sending this messagebooleanAre we allowed to connect to local addresses?(package private) static voidabstract 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 are we currently connected to, that we have sent a message to in the last minute.abstract intHow many peers are we connected to?abstract voidexternalAddressReceived(Transport.AddressSource source, byte[] ip, int port) Notify a transport of an external address change.voidexternalAddressRemoved(Transport.AddressSource source, boolean ipv6) Notify a transport of an external address change.voidforwardPortStatus(byte[] ip, int port, int externalPort, boolean success, String reason) Notify a transport of the results of trying to forward a port.An alternate supported style, or null.Return our peer clock skews on a transport.getCurrentAddress(boolean ipv6) What address are we currently listening to? Replaces getCurrentAddress() Note: An address without a host is considered IPv4.What addresses are we currently listening to? Replaces getCurrentAddress()static byte[]IP of the peer from the last connection (in or out, any transport).intPer-transport connection limitprotected OutNetMessageNonblocking call to pull the next outbound message off the queue.abstract CommSystemFacade.StatusPreviously returned short, now enum as of 0.9.20intWhat INTERNAL port would the transport like to have forwarded by UPnP.protected Collection<InetAddress>Return and then clear all saved local addresses.getTargetAddresses(RouterInfo target) Get all available address we can use, shuffled and then sorted by cost/preference.booleanDo we have any current address?booleanCan we initiate or accept a connection to another peer, saving some marginbooleanhaveCapacity(int pct) booleanisBacklogged(Hash peer) booleanisEstablished(Hash peer) booleanThis returns true if the force-firewalled setting is configured, false otherwise.booleanThis returns true if the force-firewalled setting is configured, false otherwise.protected booleanisPubliclyRoutable(byte[] addr) Allows IPv6 only if the transport is configured for it.booleanisUnreachable(Hash peer) voidmarkReachable(Hash peer, boolean isInbound) called when we establish a peer connection (outbound or inbound)voidmarkUnreachable(Hash peer) called when we can't reach a peervoidmayDisconnect(Hash peer) Tell the transport that we may disconnect from this peer.voidmessageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived) Message received from the I2NPMessageReader - send it to the listenerprotected StringTranslateprotected abstract voidThis message is called whenever a new message is added to the send pool, and it should not block Only used by NTCP.voidDeprecated.unusedprotected voidremoveAddress(boolean ipv6) Remove all existing addresses with the specified IP length (4 or 16).protected voidremoveAddress(RouterAddress address) Remove only this address.voidrenderStatusHTML(Writer out) Make this stuff pretty (only used in the old console)voidrenderStatusHTML(Writer out, String urlBase, int sortFlags) protected voidreplaceAddress(RouterAddress address) Replace any existing addresses for the current transport with the same IP length (4 or 16) with the given one.protected voidsaveLocalAddress(InetAddress address) Save a local address we were notified about before we started.voidsend(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).voidIP of the peer from the last connection (in or out, any transport).voidsetListener(TransportEventListener listener) Who to notify on message availabilityAsk the transport to update its address based on current information and return it Transports should override.booleanwasUnreachable(Hash peer) Was the peer UNreachable (outbound only) the last time we tried it? This is NOT reset if the peer contacts us.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.i2p.router.transport.Transport
bid, forceDisconnect, getEstablished, getPeerCounts, getStyle, startListening, stopListening
-
Field Details
-
_currentAddresses
-
_context
-
CAP_IPV4
- Since:
- 0.9.50
- See Also:
-
CAP_IPV6
- Since:
- 0.9.50
- See Also:
-
CAP_IPV4_IPV6
- Since:
- 0.9.50
- See Also:
-
PROP_IPV6_FIREWALLED
- Since:
- 0.9.44
- See Also:
-
ADJUST_COST
protected static final boolean ADJUST_COSTDo we increase the advertised cost when approaching conn limits?- See Also:
-
CONGESTION_COST_ADJUSTMENT
protected static final int CONGESTION_COST_ADJUSTMENTTODO change to 2- See Also:
-
-
Constructor Details
-
TransportImpl
Initialize the new transport
-
-
Method Details
-
countPeers
public abstract int countPeers()How many peers are we connected to?- Specified by:
countPeersin interfaceTransport
-
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.- Specified by:
countActivePeersin interfaceTransport
-
countActiveSendPeers
public abstract int countActiveSendPeers()How many peers are we currently connected to, that we have sent a message to in the last minute. Unused for anything, to be removed.- Specified by:
countActiveSendPeersin interfaceTransport
-
getMaxConnections
public int getMaxConnections()Per-transport connection limit -
haveCapacity
public boolean haveCapacity()Can we initiate or accept a connection to another peer, saving some margin- Specified by:
haveCapacityin interfaceTransport
-
haveCapacity
public boolean haveCapacity(int pct) - Specified by:
haveCapacityin interfaceTransport- Parameters:
pct- are we under x% 0-100
-
getClockSkews
Return our peer clock skews on a transport. List composed of Long, each element representing a peer skew in seconds. Dummy version. Transports override it.- Specified by:
getClockSkewsin interfaceTransport
-
getMostRecentErrorMessages
- Specified by:
getMostRecentErrorMessagesin interfaceTransport
-
getNextMessage
Nonblocking call to pull the next outbound message off the queue. Only used by NTCP. SSU does not call.- Returns:
- the next message or null if none are available
-
afterSend
The transport is done sending this message- Parameters:
msg- message in questionsendSuccessful- true if the peer received it
-
afterSend
The transport is done sending this message- Parameters:
msg- message in questionsendSuccessful- true if the peer received itallowRequeue- true if we should try other transports if available
-
afterSend
The transport is done sending this message- Parameters:
msg- message in questionsendSuccessful- true if the peer received itmsToSend- how long it took to transfer the data to the peer
-
afterSend
protected void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend) The transport is done sending this message. This is the method that actually does all of the cleanup - firing off jobs, requeueing, updating stats, etc.- 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
-
send
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 Only used by NTCP. SSU overrides. Note that this adds to the queue and then takes it back off in the same thread, so it actually blocks, and we don't need a big queue. TODO: Override in NTCP also and get rid of queue? -
outboundMessageReady
protected abstract void outboundMessageReady()This 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. -
messageReceived
public void messageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived) Message received from the I2NPMessageReader - send it to the listener- Parameters:
inMsg- non-nullremoteIdent- may be nullremoteIdentHash- may be null, calculated from remoteIdent if null
-
getCurrentAddresses
What addresses are we currently listening to? Replaces getCurrentAddress()- Specified by:
getCurrentAddressesin interfaceTransport- Returns:
- all addresses, non-null
- Since:
- IPv6
-
getCurrentAddress
What address are we currently listening to? Replaces getCurrentAddress() Note: An address without a host is considered IPv4.- Specified by:
getCurrentAddressin interfaceTransport- Parameters:
ipv6- true for IPv6 only; false for IPv4 only- Returns:
- first matching address or null
- Since:
- IPv6
-
hasCurrentAddress
public boolean hasCurrentAddress()Do we have any current address?- Specified by:
hasCurrentAddressin interfaceTransport- Since:
- IPv6
-
updateAddress
Ask the transport to update its address based on current information and return it Transports should override.- Specified by:
updateAddressin interfaceTransport- Returns:
- all addresses, non-null
- Since:
- 0.7.12
-
replaceAddress
Replace any existing addresses for the current transport with the same IP length (4 or 16) with the given one. TODO: Allow multiple addresses of the same length. Calls listener.transportAddressChanged() To remove all IPv4 or IPv6 addresses, use removeAddress(boolean).- Parameters:
address- null to remove all
-
removeAddress
Remove only this address. Calls listener.transportAddressChanged(). To remove all IPv4 or IPv6 addresses, use removeAddress(boolean). To remove all IPv4 and IPv6 addresses, use replaceAddress(null).- Since:
- 0.9.20
-
removeAddress
protected void removeAddress(boolean ipv6) Remove all existing addresses with the specified IP length (4 or 16). Calls listener.transportAddressChanged(). To remove all IPv4 and IPv6 addresses, use replaceAddress(null).- Parameters:
ipv6- true to remove all IPv6 addresses, false to remove all IPv4 addresses- Since:
- 0.9.20
-
saveLocalAddress
Save a local address we were notified about before we started.- Since:
- IPv6
-
getSavedLocalAddresses
Return and then clear all saved local addresses.- Since:
- IPv6
-
getTargetAddresses
Get all available address we can use, shuffled and then sorted by cost/preference. Lowest cost (most preferred) first.- Returns:
- non-null, possibly empty
- Since:
- IPv6, public since 0.9.50, was protected
-
externalAddressReceived
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 before startListening() to set an initial address, or after the transport is running.- Specified by:
externalAddressReceivedin interfaceTransport- Parameters:
source- defined in Transport.javaip- typ. IPv4 or IPv6 non-local; may be null to indicate IPv4 failure or port info onlyport- 0 for unknown or unchanged
-
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) This implementation does nothing. Transports should override if they want notification.- Specified by:
externalAddressRemovedin interfaceTransport- Parameters:
source- defined in Transport.java- Since:
- 0.9.20
-
forwardPortStatus
public void forwardPortStatus(byte[] ip, int port, int externalPort, boolean success, String reason) Notify a transport of the results of trying to forward a port. This implementation does nothing. Transports should override if they want notification.- Specified by:
forwardPortStatusin interfaceTransport- 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()What 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- Returns:
- port or -1 for none or 0 for any
-
setListener
Who to notify on message availability- Specified by:
setListenerin interfaceTransport
-
renderStatusHTML
Make this stuff pretty (only used in the old console)- Throws:
IOException
-
renderStatusHTML
- Specified by:
renderStatusHTMLin interfaceTransport- Throws:
IOException
-
getReachabilityStatus
Previously returned short, now enum as of 0.9.20- Specified by:
getReachabilityStatusin interfaceTransport
-
recheckReachability
Deprecated.unused- Specified by:
recheckReachabilityin interfaceTransport
-
isIPv4Firewalled
public boolean isIPv4Firewalled()This returns true if the force-firewalled setting is configured, false otherwise.- Specified by:
isIPv4Firewalledin interfaceTransport- Since:
- 0.9.20, public since 0.9.30
-
isIPv6Firewalled
public boolean isIPv6Firewalled()This returns true if the force-firewalled setting is configured, false otherwise.- Specified by:
isIPv6Firewalledin interfaceTransport- Since:
- 0.9.27, public since 0.9.30
-
isBacklogged
- Specified by:
isBackloggedin interfaceTransport
-
isEstablished
- Specified by:
isEstablishedin interfaceTransport
-
mayDisconnect
Tell the transport that we may disconnect from this peer. This is advisory only.- Specified by:
mayDisconnectin interfaceTransport- Since:
- 0.9.24
-
isUnreachable
- Specified by:
isUnreachablein interfaceTransport
-
markUnreachable
called when we can't reach a peer -
markReachable
called when we establish a peer connection (outbound or inbound) -
wasUnreachable
Was the peer UNreachable (outbound only) the last time we tried it? This is NOT reset if the peer contacts us.- Specified by:
wasUnreachablein interfaceTransport
-
allowLocal
public boolean allowLocal()Are we allowed to connect to local addresses?- Since:
- 0.9.28 moved from UDPTransport
-
setIP
IP of the peer from the last connection (in or out, any transport).- Parameters:
ip- IPv4 or IPv6, non-null
-
getIP
IP of the peer from the last connection (in or out, any transport).- Returns:
- IPv4 or IPv6 or null
-
getAltStyle
An alternate supported style, or null.- Returns:
- null, override to add support
- Since:
- 0.9.35
-
clearCaches
static void clearCaches()- Since:
- 0.9.3
-
getIPv6Config
- Specified by:
getIPv6Configin interfaceTransport- Since:
- IPv6, public since 0.9.30
-
isPubliclyRoutable
protected boolean isPubliclyRoutable(byte[] addr) Allows IPv6 only if the transport is configured for it. Caller must check if we actually have a public IPv6 address.- Parameters:
addr- non-null
-
_t
Translate- Since:
- 0.9.8 moved from transports
-
_t
Translate- Since:
- 0.9.8 moved from transports
-
ngettext
Translate- Since:
- 0.9.8
-