java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.i2np.DeliveryInstructions
- All Implemented Interfaces:
Serializable, DataStructure
- Direct Known Subclasses:
DeliveryInstructions.LocalInstructions
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:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAn immutable local delivery instructions with no options for efficiency.Field Summary
Modifier and TypeFieldDescriptionprivate booleanWhether a delivery delay was requested.private longDelay duration in seconds (obsolete, not implemented).private int0-3, set by delivery mode constants.private HashHash of the destination for DESTINATION mode.private HashHash of the router for ROUTER or TUNNEL mode.private TunnelIdTunnel ID for TUNNEL mode.static final intDelivery mode sending the message to a destination's client.static final intDelivery mode keeping the message on this router.static final intDelivery mode sending the message to a router's transport.static final intDelivery mode sending the message into a named tunnel.private static final intBitmask for the delay-requested flag.private static final intBitmask isolating the mode field in the flag byte.private static final intFlag bit pattern for destination delivery mode.private static final intFlag bit pattern for local delivery mode.private static final intFlag bit pattern for router delivery mode.private static final intFlag bit pattern for tunnel delivery mode.static final DeliveryInstructionsImmutable local instructions, no options.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic DeliveryInstructionscreate(byte[] data, int offset) Returns immutable local instructions, or new.booleanCompare the delivery instructions for equality, including mode, delay, and target fields.private static booleanflagDelay(int flags) Whether the delay flag is set in the flags byte.private static intflagMode(int flags) Extract the delivery mode from the flags byte.private intgetAdditionalInfo(byte[] rv, int offset) Serializes additional delivery info (hash, tunnel ID, delay) into buffer.private intSize of the serialized additional delivery info in bytes.booleanDefaults to false.longDefaults to 0.intDefault -1.Default null.For cloves only (not tunnels), default null Unused — always returns null, feature not implemented.private intgetFlags()Encodes the current delivery mode and delay into flag byte.Default null.intgetSize()Size of the serialized delivery instructions in bytes.Default null.inthashCode()Hash code combining the delay, mode, and target fields.intreadBytes(byte[] data, int offset) Populate the delivery instructions from the byte array, starting at the given offset.voidreadBytes(InputStream in) Not supported, use readBytes(byte[], int).voidsetDelayRequested(boolean req) Defaults to false.voidsetDelaySeconds(long seconds) Defaults to 0.voidsetDeliveryMode(int mode) Delivery mode of the message.voidsetDestination(Hash dest) Required for DESTINATION.voidRequired for ROUTER or TUNNEL.voidsetTunnelId(TunnelId id) Required for TUNNEL.toString()String form for debugging, showing the mode and any delay or target fields.intwriteBytes(byte[] target, int offset) Serialize the delivery instructions into the byte array, starting at the given offset.voidwriteBytes(OutputStream out) Not supported, use writeBytes(byte[], int).Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.
Field Details
_deliveryMode
private int _deliveryMode0-3, set by delivery mode constants.DELIVERY_MODE_LOCAL
public static final int DELIVERY_MODE_LOCALDelivery mode keeping the message on this router.- See Also:
DELIVERY_MODE_DESTINATION
public static final int DELIVERY_MODE_DESTINATIONDelivery mode sending the message to a destination's client.- See Also:
DELIVERY_MODE_ROUTER
public static final int DELIVERY_MODE_ROUTERDelivery mode sending the message to a router's transport.- See Also:
DELIVERY_MODE_TUNNEL
public static final int DELIVERY_MODE_TUNNELDelivery mode sending the message into a named tunnel.- See Also:
_destinationHash
Hash of the destination for DESTINATION mode._routerHash
Hash of the router for ROUTER or TUNNEL mode._tunnelId
Tunnel ID for TUNNEL mode._delayRequested
private boolean _delayRequestedWhether a delivery delay was requested._delaySeconds
private long _delaySecondsDelay duration in seconds (obsolete, not implemented).FLAG_MODE_LOCAL
private static final int FLAG_MODE_LOCALFlag bit pattern for local delivery mode.- See Also:
FLAG_MODE_DESTINATION
private static final int FLAG_MODE_DESTINATIONFlag bit pattern for destination delivery mode.- See Also:
FLAG_MODE_ROUTER
private static final int FLAG_MODE_ROUTERFlag bit pattern for router delivery mode.- See Also:
FLAG_MODE_TUNNEL
private static final int FLAG_MODE_TUNNELFlag bit pattern for tunnel delivery mode.- See Also:
FLAG_MODE
private static final int FLAG_MODEBitmask isolating the mode field in the flag byte.- See Also:
FLAG_DELAY
private static final int FLAG_DELAYBitmask for the delay-requested flag.- See Also:
LOCAL
Immutable local instructions, no options.
Constructor Details
DeliveryInstructions
public DeliveryInstructions()Creates instructions with an unset delivery mode of -1.
Method Details
create
Returns immutable local instructions, or new.- Parameters:
data- the buffer holding the encoded delivery instructionsoffset- 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
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
Default null.- Returns:
- the destination hash, or null unless the mode is DESTINATION
setDestination
Required for DESTINATION.- Parameters:
dest- the destination to deliver to
getRouter
Default null.- Returns:
- the router hash, or null unless the mode is ROUTER or TUNNEL
setRouter
Required for ROUTER or TUNNEL.- Parameters:
router- the router to deliver to
getTunnelId
Default null.- Returns:
- the tunnel to deliver to, or null unless the mode is TUNNEL
setTunnelId
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
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 instructionsoffset- 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 modeoffset- where in the buffer to start writing- Returns:
- the number of bytes written
writeBytes
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 intooffset- 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
hashCode
toString