java.lang.Object
net.i2p.router.tunnel.HopConfig

public class HopConfigextends Object
Defines the general configuration for a hop in a tunnel.

This is used for both participating tunnels and tunnels we create. Data only stored for tunnels we create should be in TunnelCreatorConfig to save space.

  • Field Details

    • _receiveTunnel

      private TunnelId _receiveTunnel
      The tunnel id we receive on.
    • _receiveFrom

      private Hash _receiveFrom
      The router we receive from.
    • _sendTunnel

      private TunnelId _sendTunnel
      The tunnel id we send on.
    • _sendTo

      private Hash _sendTo
      The router we send to.
    • _layerKey

      private SessionKey _layerKey
      The layer key for the decryption.
    • _ivKey

      private SessionKey _ivKey
      The initialization vector key.
    • _creation

      private long _creation
      When the tunnel was created.
    • _expiration

      private long _expiration
      When the tunnel expires.
    • _messagesProcessed

      private final AtomicInteger _messagesProcessed
      Messages processed so far. An int rather than a long to save space, two billion messages of 1KB per 10 minutes is 3 GBps in one tunnel, and the lock-free access keeps the pumped-message counters off the monitor contended by every participating tunnel.
    • _oldMessagesProcessed

      private volatile int _oldMessagesProcessed
      Old messages processed so far.
    • _allocatedBW

      private volatile int _allocatedBW
      Allocated bandwidth, in KBps.
  • Constructor Details

    • HopConfig

      public HopConfig()
      Creates a new HopConfig with default values.
  • Method Details

    • getReceiveTunnelId

      public long getReceiveTunnelId()
      What tunnel ID are we receiving on? (0 if uninitialized).
      Returns:
      the receive tunnel ID or 0
    • getReceiveTunnel

      public TunnelId getReceiveTunnel()
      What tunnel ID are we receiving on? (null if uninitialized).
      Returns:
      the receive tunnel or null
    • setReceiveTunnelId

      public void setReceiveTunnelId(TunnelId id)
      The tunnel ID to receive messages on.
      Parameters:
      id - the tunnel ID
    • setReceiveTunnelId

      public void setReceiveTunnelId(long id)
      The receive tunnel ID, from 1 to 0xffffffff.
      Parameters:
      id - 1 to 0xffffffff
      Throws:
      IllegalArgumentException - if less than or equal to zero or greater than max value
    • getReceiveFrom

      public Hash getReceiveFrom()
      What is the previous peer in the tunnel (null if gateway)?
      Returns:
      the hash of the peer we receive from, or null at the gateway
    • setReceiveFrom

      public void setReceiveFrom(Hash from)
      Do not set for gateway.
      Parameters:
      from - the previous peer hash
    • getSendTunnelId

      public long getSendTunnelId()
      What is the next tunnel ID we are sending to? (0 if endpoint).
      Returns:
      the send tunnel ID or 0
    • getSendTunnel

      public TunnelId getSendTunnel()
      What is the next tunnel ID we are sending to? (null if endpoint).
      Returns:
      the send tunnel or null
    • setSendTunnelId

      public void setSendTunnelId(TunnelId id)
      The tunnel ID to send messages through. Do not set for endpoint.
      Parameters:
      id - the tunnel ID
    • setSendTunnelId

      public void setSendTunnelId(long id)
      The send tunnel ID, from 1 to 0xffffffff. Do not set for endpoint.
      Parameters:
      id - 1 to 0xffffffff
      Throws:
      IllegalArgumentException - if less than or equal to zero or greater than max value
    • getSendTo

      public Hash getSendTo()
      What is the next peer in the tunnel (null if endpoint)?
      Returns:
      the hash of the peer we send to, or null at the endpoint
    • setSendTo

      public void setSendTo(Hash to)
      Do not set for endpoint.
      Parameters:
      to - the next peer hash
    • getLayerKey

      public SessionKey getLayerKey()
      What key encrypts the layer before passing it on?
      Returns:
      the layer session key, or null if this hop does not relay layers
    • setLayerKey

      public void setLayerKey(SessionKey key)
      The key to encrypt the layer with before passing it on.
      Parameters:
      key - the layer session key applied to relayed layer messages
    • getIVKey

      public SessionKey getIVKey()
      What key encrypts the preIV before passing it on?
      Returns:
      the IV session key, or null if this hop does not relay IVs
    • setIVKey

      public void setIVKey(SessionKey key)
      The key to encrypt the IV with before passing it on.
      Parameters:
      key - the IV session key applied to relayed pre-IV messages
    • getExpiration

      public long getExpiration()
      When does this tunnel expire (in ms since the epoch)?
      Returns:
      the expiration time in milliseconds since the epoch
    • setExpiration

      public void setExpiration(long when)
      The tunnel expiration time, in ms since the epoch.
      Parameters:
      when - the expiration time in milliseconds since the epoch
    • getCreation

      public long getCreation()
      When was this tunnel created (in ms since the epoch)?
      Returns:
      the creation time in milliseconds since the epoch
    • setCreation

      public void setCreation(long when)
      The tunnel creation time, in ms since the epoch.
      Parameters:
      when - the creation time in milliseconds since the epoch
    • getAllocatedBW

      public int getAllocatedBW()
      The bandwidth allocated for this hop.
      Returns:
      the bandwidth in Bps
    • setAllocatedBW

      public void setAllocatedBW(int bw)
      The bandwidth allocated for this hop.
      Parameters:
      bw - the bandwidth in Bps
    • incrementProcessedMessages

      public void incrementProcessedMessages()
      Take note of a message being pumped through this tunnel. "processed" is for incoming and "sent" is for outgoing (could be dropped in between).
    • getProcessedMessagesCount

      public int getProcessedMessagesCount()
      The messages processed so far.
      Returns:
      the count of processed messages
    • getRecentMessagesCount

      public int getRecentMessagesCount()
      This returns the number of processed messages since the last time getAndResetRecentMessagesCount() was called. As of 0.9.23, does NOT reset the count, see getAndResetRecentMessagesCount().
      Returns:
      the recent messages count
    • getAndResetRecentMessagesCount

      int getAndResetRecentMessagesCount()
      This returns the number of processed messages since the last time this was called, and resets the count. It should only be called by code that updates the router stats. See TunnelDispatcher.updateParticipatingStats(int).

      The counter is sampled once so the returned delta and the stored baseline refer to the same read; a concurrent increment lands in the next window.

      Returns:
      the number of messages processed since the previous call
    • toShortString

      public String toShortString()
      Compact one-line hop identifier for log output: the next peer to send to. No message counts or expiration, no newlines.
      Returns:
      the next-hop identifier, or "local hop" for the final hop
    • toString

      public String toString()
      Overrides:
      toString in class Object