java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.i2np.DeliveryInstructions
All Implemented Interfaces:
Serializable, DataStructure
Direct Known Subclasses:
DeliveryInstructions.LocalInstructions

public class DeliveryInstructionsextends DataStructureImpl
Contains the delivery instructions for garlic cloves. Generic "delivery instructions" are used both in tunnel messages and in garlic cloves, with slight differences. However, the tunnel message generator TrivialPreprocessor and reader FragmentHandler do not use this class, the reading and writing is handled inline there.
See Also:
  • Field Details

    • _deliveryMode

      private int _deliveryMode
      0-3, set by delivery mode constants.
    • DELIVERY_MODE_LOCAL

      public static final int DELIVERY_MODE_LOCAL
      Delivery mode keeping the message on this router.
      See Also:
    • DELIVERY_MODE_DESTINATION

      public static final int DELIVERY_MODE_DESTINATION
      Delivery mode sending the message to a destination's client.
      See Also:
    • DELIVERY_MODE_ROUTER

      public static final int DELIVERY_MODE_ROUTER
      Delivery mode sending the message to a router's transport.
      See Also:
    • DELIVERY_MODE_TUNNEL

      public static final int DELIVERY_MODE_TUNNEL
      Delivery mode sending the message into a named tunnel.
      See Also:
    • _destinationHash

      private Hash _destinationHash
      Hash of the destination for DESTINATION mode.
    • _routerHash

      private Hash _routerHash
      Hash of the router for ROUTER or TUNNEL mode.
    • _tunnelId

      private TunnelId _tunnelId
      Tunnel ID for TUNNEL mode.
    • _delayRequested

      private boolean _delayRequested
      Whether a delivery delay was requested.
    • _delaySeconds

      private long _delaySeconds
      Delay duration in seconds (obsolete, not implemented).
    • FLAG_MODE_LOCAL

      private static final int FLAG_MODE_LOCAL
      Flag bit pattern for local delivery mode.
      See Also:
    • FLAG_MODE_DESTINATION

      private static final int FLAG_MODE_DESTINATION
      Flag bit pattern for destination delivery mode.
      See Also:
    • FLAG_MODE_ROUTER

      private static final int FLAG_MODE_ROUTER
      Flag bit pattern for router delivery mode.
      See Also:
    • FLAG_MODE_TUNNEL

      private static final int FLAG_MODE_TUNNEL
      Flag bit pattern for tunnel delivery mode.
      See Also:
    • FLAG_MODE

      private static final int FLAG_MODE
      Bitmask isolating the mode field in the flag byte.
      See Also:
    • FLAG_DELAY

      private static final int FLAG_DELAY
      Bitmask for the delay-requested flag.
      See Also:
    • LOCAL

      public static final DeliveryInstructions LOCAL
      Immutable local instructions, no options.
  • Constructor Details

    • DeliveryInstructions

      public DeliveryInstructions()
      Creates instructions with an unset delivery mode of -1.
  • Method Details

    • create

      public static DeliveryInstructions create(byte[] data, int offset)
      Returns immutable local instructions, or new.
      Parameters:
      data - the buffer holding the encoded delivery instructions
      offset - the index within data of the flags byte starting the instructions
      Returns:
      the shared LOCAL instance when the flags byte is zero, otherwise a newly parsed instance
    • getEncryptionKey

      public SessionKey getEncryptionKey()
      For cloves only (not tunnels), default null Unused — always returns null, feature not implemented.
      Returns:
      the encryption key
    • getDeliveryMode

      public int getDeliveryMode()
      Default -1.
      Returns:
      the delivery mode, 0 through 3, or -1 when no mode has been set
    • setDeliveryMode

      public void setDeliveryMode(int mode)
      Delivery mode of the message.
      Parameters:
      mode - 0-3
    • getDestination

      public Hash getDestination()
      Default null.
      Returns:
      the destination hash, or null unless the mode is DESTINATION
    • setDestination

      public void setDestination(Hash dest)
      Required for DESTINATION.
      Parameters:
      dest - the destination to deliver to
    • getRouter

      public Hash getRouter()
      Default null.
      Returns:
      the router hash, or null unless the mode is ROUTER or TUNNEL
    • setRouter

      public void setRouter(Hash router)
      Required for ROUTER or TUNNEL.
      Parameters:
      router - the router to deliver to
    • getTunnelId

      public TunnelId getTunnelId()
      Default null.
      Returns:
      the tunnel to deliver to, or null unless the mode is TUNNEL
    • setTunnelId

      public void setTunnelId(TunnelId id)
      Required for TUNNEL.
      Parameters:
      id - the tunnel to deliver to
    • getDelayRequested

      public boolean getDelayRequested()
      Defaults to false. Obsolete — delay not implemented in this release.
      Returns:
      the delay requested
    • setDelayRequested

      public void setDelayRequested(boolean req)
      Defaults to false. Obsolete — delay not implemented in this release.
      Parameters:
      req - true to request delayed delivery; the request is stored but never acted on
    • getDelaySeconds

      public long getDelaySeconds()
      Defaults to 0. Obsolete — delay not implemented in this release.
      Returns:
      the delay seconds
    • setDelaySeconds

      public void setDelaySeconds(long seconds)
      Defaults to 0. Obsolete — delay not implemented in this release.
      Parameters:
      seconds - the delay to request, in seconds; stored but never acted on
    • readBytes

      public void readBytes(InputStream in)
      Not supported, use readBytes(byte[], int).
      Parameters:
      in - stream to read from
      Throws:
      UnsupportedOperationException - always; the stream form is not implemented
    • readBytes

      public int readBytes(byte[] data, int offset)
      Populate the delivery instructions from the byte array, starting at the given offset.
      Parameters:
      data - the buffer holding the encoded delivery instructions
      offset - the index within data of the flags byte starting the instructions
      Returns:
      the number of bytes read
    • flagMode

      private static int flagMode(int flags)
      Extract the delivery mode from the flags byte.
      Parameters:
      flags - the raw flags byte from the wire
      Returns:
      the delivery mode, 0-3, held in the two high bits
    • flagDelay

      private static boolean flagDelay(int flags)
      Whether the delay flag is set in the flags byte.
      Parameters:
      flags - the raw flags byte from the wire
      Returns:
      true if the delay bit is set
    • getFlags

      private int getFlags()
      Encodes the current delivery mode and delay into flag byte.
      Returns:
      the flags byte: the delivery mode in the two high bits, plus the delay bit set if a delay was requested
    • getAdditionalInfoSize

      private int getAdditionalInfoSize()
      Size of the serialized additional delivery info in bytes.
      Returns:
      the total size of the destination or router hash, tunnel ID and delay fields required by the current delivery mode
    • getAdditionalInfo

      private int getAdditionalInfo(byte[] rv, int offset)
      Serializes additional delivery info (hash, tunnel ID, delay) into buffer.
      Parameters:
      rv - the buffer to write into, large enough for the current mode
      offset - where in the buffer to start writing
      Returns:
      the number of bytes written
    • writeBytes

      public void writeBytes(OutputStream out)
      Not supported, use writeBytes(byte[], int).
      Parameters:
      out - stream to write to
      Throws:
      UnsupportedOperationException - always; the stream form is not implemented
    • writeBytes

      public int writeBytes(byte[] target, int offset)
      Serialize the delivery instructions into the byte array, starting at the given offset.
      Parameters:
      target - the buffer to serialize into
      offset - the index within target of the first byte written
      Returns:
      the number of bytes written to the target
    • getSize

      public int getSize()
      Size of the serialized delivery instructions in bytes.
      Returns:
      the flags byte plus any mode-specific fields
    • equals

      public boolean equals(Object obj)
      Compare the delivery instructions for equality, including mode, delay, and target fields.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code combining the delay, mode, and target fields.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • toString

      public String toString()
      String form for debugging, showing the mode and any delay or target fields.
      Overrides:
      toString in class Object