Interface Transport

All Known Implementing Classes:
NTCPTransport, TransportImpl, UDPTransport

public interface Transport
Defines a way to send a message to another peer and start listening for messages. To implement a new or pluggable I2P transport, implement this interface, and add it to TransportManager.startListening(). API is subject to change. Please contact us if you're writing a new transport or transport plugin.
  • Method Details

    • bid

      TransportBid bid(RouterInfo toAddress, int dataSize)
      Parameters:
      dataSize - assumes full 16-byte header, transports should adjust as necessary
      Returns:
      a bid or null if unwilling to send
    • send

      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). If the send fails, queue up any msg.getOnFailedSendJob
    • startListening

      void startListening()
    • stopListening

      void stopListening()
    • getCurrentAddresses

      List<RouterAddress> getCurrentAddresses()
      What addresses are we currently listening to? Replaces getCurrentAddress()
      Returns:
      all addresses, non-null
      Since:
      IPv6
    • getCurrentAddress

      RouterAddress getCurrentAddress(boolean ipv6)
      What address are we currently listening to? Replaces getCurrentAddress() Note: An address without a host is considered IPv4.
      Parameters:
      ipv6 - true for IPv6 only; false for IPv4 only
      Returns:
      first matching address or null
      Since:
      0.9.50 lifted from TransportImpl
    • hasCurrentAddress

      boolean hasCurrentAddress()
      Do we have any current address?
      Since:
      IPv6
    • updateAddress

      List<RouterAddress> updateAddress()
      Ask the transport to update its addresses based on current information and return them
      Returns:
      all addresses, non-null
    • externalAddressReceived

      void externalAddressReceived(Transport.AddressSource source, byte[] ip, int port)
      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.
      Parameters:
      source - defined in Transport.java
      ip - typ. IPv4 or IPv6 non-local; may be null to indicate IPv4 failure or port info only
      port - 0 for unknown or unchanged
    • externalAddressRemoved

      void externalAddressRemoved(Transport.AddressSource source, boolean ipv6)
      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)
      Parameters:
      source - defined in Transport.java
      Since:
      0.9.20
    • forwardPortStatus

      void forwardPortStatus(byte[] ip, int port, int externalPort, boolean success, String reason)
      Notify a transport of the results of trying to forward a port.
      Parameters:
      ip - may be null
      port - the internal port
      externalPort - the external port, which for now should always be the same as the internal port if the forwarding was successful.
    • getRequestedPort

      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.
      Returns:
      port or -1 for none or 0 for any
    • setListener

      void setListener(TransportEventListener listener)
      Who to notify on message availability
    • getStyle

      String getStyle()
      The unique identity of this Transport
    • getEstablished

      Set<Hash> getEstablished()
      Returns:
      may or may not be modifiable; check implementation
      Since:
      0.9.34
    • countPeers

      int countPeers()
    • countActivePeers

      int countActivePeers()
    • countActiveSendPeers

      int countActiveSendPeers()
    • getPeerCounts

      int[] getPeerCounts()
      Returns:
      8 bytes: version 1 ipv4 in/out, ipv6 in/out version 2 ipv4 in/out, ipv6 in/out
      Since:
      0.9.57
    • haveCapacity

      boolean haveCapacity()
    • haveCapacity

      boolean haveCapacity(int pct)
    • getClockSkews

      List<Long> getClockSkews()
      Previously returned Vector, now List as of 0.9.46.
    • getMostRecentErrorMessages

      List<String> getMostRecentErrorMessages()
    • renderStatusHTML

      void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException
      Throws:
      IOException
    • getReachabilityStatus

      CommSystemFacade.Status getReachabilityStatus()
      Previously returned short, now enum as of 0.9.20
    • recheckReachability

      @Deprecated void recheckReachability()
      Deprecated.
      unused
    • getIPv6Config

      TransportUtil.IPv6Config getIPv6Config()
      Since:
      0.9.50 added to interface
    • isIPv4Firewalled

      boolean isIPv4Firewalled()
      This returns true if the force-firewalled setting is configured, false otherwise.
      Since:
      0.9.50 added to interface
    • isIPv6Firewalled

      boolean isIPv6Firewalled()
      This returns true if the force-firewalled setting is configured, false otherwise.
      Since:
      0.9.50 added to interface
    • isBacklogged

      boolean isBacklogged(Hash peer)
    • wasUnreachable

      boolean wasUnreachable(Hash peer)
      Was the peer UNreachable (outbound only) the last time we tried it? This is NOT reset if the peer contacts us and it is never expired.
    • isUnreachable

      boolean isUnreachable(Hash peer)
    • isEstablished

      boolean isEstablished(Hash peer)
    • mayDisconnect

      void mayDisconnect(Hash peer)
      Tell the transport that we may disconnect from this peer. This is advisory only.
      Since:
      0.9.24
    • forceDisconnect

      void forceDisconnect(Hash peer)
      Tell the transport to disconnect from this peer.
      Since:
      0.9.38