forked from I2P_Developers/i2p.i2p
unused and javadoc
This commit is contained in:
@ -22,7 +22,12 @@ import net.i2p.util.Log;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the delivery instructions
|
* 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.
|
||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
@ -46,6 +51,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
private final static int FLAG_MODE_ROUTER = 2;
|
private final static int FLAG_MODE_ROUTER = 2;
|
||||||
private final static int FLAG_MODE_TUNNEL = 3;
|
private final static int FLAG_MODE_TUNNEL = 3;
|
||||||
|
|
||||||
|
/** @deprecated unused */
|
||||||
private final static long FLAG_ENCRYPTED = 128;
|
private final static long FLAG_ENCRYPTED = 128;
|
||||||
private final static long FLAG_MODE = 96;
|
private final static long FLAG_MODE = 96;
|
||||||
private final static long FLAG_DELAY = 16;
|
private final static long FLAG_DELAY = 16;
|
||||||
@ -54,21 +60,76 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
setDeliveryMode(-1);
|
setDeliveryMode(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For cloves only (not tunnels), default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public boolean getEncrypted() { return _encrypted; }
|
public boolean getEncrypted() { return _encrypted; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For cloves only (not tunnels), default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public void setEncrypted(boolean encrypted) { _encrypted = encrypted; }
|
public void setEncrypted(boolean encrypted) { _encrypted = encrypted; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For cloves only (not tunnels), default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public SessionKey getEncryptionKey() { return _encryptionKey; }
|
public SessionKey getEncryptionKey() { return _encryptionKey; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For cloves only (not tunnels), default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public void setEncryptionKey(SessionKey key) { _encryptionKey = key; }
|
public void setEncryptionKey(SessionKey key) { _encryptionKey = key; }
|
||||||
|
|
||||||
|
/** default -1 */
|
||||||
public int getDeliveryMode() { return _deliveryMode; }
|
public int getDeliveryMode() { return _deliveryMode; }
|
||||||
|
|
||||||
|
/** @param mode 0-3 */
|
||||||
public void setDeliveryMode(int mode) { _deliveryMode = mode; }
|
public void setDeliveryMode(int mode) { _deliveryMode = mode; }
|
||||||
|
|
||||||
|
/** default null */
|
||||||
public Hash getDestination() { return _destinationHash; }
|
public Hash getDestination() { return _destinationHash; }
|
||||||
|
|
||||||
|
/** required for DESTINATION */
|
||||||
public void setDestination(Hash dest) { _destinationHash = dest; }
|
public void setDestination(Hash dest) { _destinationHash = dest; }
|
||||||
|
|
||||||
|
/** default null */
|
||||||
public Hash getRouter() { return _routerHash; }
|
public Hash getRouter() { return _routerHash; }
|
||||||
|
|
||||||
|
/** required for ROUTER or TUNNEL */
|
||||||
public void setRouter(Hash router) { _routerHash = router; }
|
public void setRouter(Hash router) { _routerHash = router; }
|
||||||
|
|
||||||
|
/** default null */
|
||||||
public TunnelId getTunnelId() { return _tunnelId; }
|
public TunnelId getTunnelId() { return _tunnelId; }
|
||||||
|
|
||||||
|
/** required for TUNNEL */
|
||||||
public void setTunnelId(TunnelId id) { _tunnelId = id; }
|
public void setTunnelId(TunnelId id) { _tunnelId = id; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public boolean getDelayRequested() { return _delayRequested; }
|
public boolean getDelayRequested() { return _delayRequested; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public void setDelayRequested(boolean req) { _delayRequested = req; }
|
public void setDelayRequested(boolean req) { _delayRequested = req; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default 0, unusedx
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public long getDelaySeconds() { return _delaySeconds; }
|
public long getDelaySeconds() { return _delaySeconds; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default 0, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
public void setDelaySeconds(long seconds) { _delaySeconds = seconds; }
|
public void setDelaySeconds(long seconds) { _delaySeconds = seconds; }
|
||||||
|
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
@ -76,6 +137,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Read flags: " + flags + " mode: " + flagMode(flags));
|
_log.debug("Read flags: " + flags + " mode: " + flagMode(flags));
|
||||||
|
|
||||||
|
/****
|
||||||
if (flagEncrypted(flags)) {
|
if (flagEncrypted(flags)) {
|
||||||
SessionKey k = new SessionKey();
|
SessionKey k = new SessionKey();
|
||||||
k.readBytes(in);
|
k.readBytes(in);
|
||||||
@ -84,6 +146,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
} else {
|
} else {
|
||||||
setEncrypted(false);
|
setEncrypted(false);
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
setDeliveryMode(flagMode(flags));
|
setDeliveryMode(flagMode(flags));
|
||||||
switch (flagMode(flags)) {
|
switch (flagMode(flags)) {
|
||||||
@ -128,6 +191,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Read flags: " + flags + " mode: " + flagMode(flags));
|
_log.debug("Read flags: " + flags + " mode: " + flagMode(flags));
|
||||||
|
|
||||||
|
/****
|
||||||
if (flagEncrypted(flags)) {
|
if (flagEncrypted(flags)) {
|
||||||
byte kd[] = new byte[SessionKey.KEYSIZE_BYTES];
|
byte kd[] = new byte[SessionKey.KEYSIZE_BYTES];
|
||||||
System.arraycopy(data, cur, kd, 0, SessionKey.KEYSIZE_BYTES);
|
System.arraycopy(data, cur, kd, 0, SessionKey.KEYSIZE_BYTES);
|
||||||
@ -137,6 +201,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
} else {
|
} else {
|
||||||
setEncrypted(false);
|
setEncrypted(false);
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
setDeliveryMode(flagMode(flags));
|
setDeliveryMode(flagMode(flags));
|
||||||
switch (flagMode(flags)) {
|
switch (flagMode(flags)) {
|
||||||
@ -179,24 +244,34 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For cloves only (not tunnels), default false, unused
|
||||||
|
* @deprecated unused
|
||||||
|
*/
|
||||||
|
/****
|
||||||
private boolean flagEncrypted(long flags) {
|
private boolean flagEncrypted(long flags) {
|
||||||
return (0 != (flags & FLAG_ENCRYPTED));
|
return (0 != (flags & FLAG_ENCRYPTED));
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
|
/** high bits */
|
||||||
private int flagMode(long flags) {
|
private int flagMode(long flags) {
|
||||||
long v = flags & FLAG_MODE;
|
long v = flags & FLAG_MODE;
|
||||||
v >>>= 5;
|
v >>>= 5;
|
||||||
return (int)v;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** unused */
|
||||||
private boolean flagDelay(long flags) {
|
private boolean flagDelay(long flags) {
|
||||||
return (0 != (flags & FLAG_DELAY));
|
return (0 != (flags & FLAG_DELAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getFlags() {
|
private long getFlags() {
|
||||||
long val = 0L;
|
long val = 0L;
|
||||||
|
/****
|
||||||
if (getEncrypted())
|
if (getEncrypted())
|
||||||
val = val | FLAG_ENCRYPTED;
|
val = val | FLAG_ENCRYPTED;
|
||||||
|
****/
|
||||||
long fmode = 0;
|
long fmode = 0;
|
||||||
switch (getDeliveryMode()) {
|
switch (getDeliveryMode()) {
|
||||||
case FLAG_MODE_LOCAL:
|
case FLAG_MODE_LOCAL:
|
||||||
@ -221,10 +296,12 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
|
|
||||||
private int getAdditionalInfoSize() {
|
private int getAdditionalInfoSize() {
|
||||||
int additionalSize = 0;
|
int additionalSize = 0;
|
||||||
|
/****
|
||||||
if (getEncrypted()) {
|
if (getEncrypted()) {
|
||||||
if (_encryptionKey == null) throw new IllegalStateException("Encryption key is not set");
|
if (_encryptionKey == null) throw new IllegalStateException("Encryption key is not set");
|
||||||
additionalSize += SessionKey.KEYSIZE_BYTES;
|
additionalSize += SessionKey.KEYSIZE_BYTES;
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
switch (getDeliveryMode()) {
|
switch (getDeliveryMode()) {
|
||||||
case FLAG_MODE_LOCAL:
|
case FLAG_MODE_LOCAL:
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
@ -260,8 +337,11 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
_log.log(Log.CRIT, "wtf, additionalSize = " + additionalSize + ", offset = " + offset);
|
_log.log(Log.CRIT, "wtf, additionalSize = " + additionalSize + ", offset = " + offset);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAdditionalInfo(byte rv[], int offset) {
|
private int getAdditionalInfo(byte rv[], int offset) {
|
||||||
int origOffset = offset;
|
int origOffset = offset;
|
||||||
|
|
||||||
|
/****
|
||||||
if (getEncrypted()) {
|
if (getEncrypted()) {
|
||||||
if (_encryptionKey == null) throw new IllegalStateException("Encryption key is not set");
|
if (_encryptionKey == null) throw new IllegalStateException("Encryption key is not set");
|
||||||
System.arraycopy(_encryptionKey.getData(), 0, rv, offset, SessionKey.KEYSIZE_BYTES);
|
System.arraycopy(_encryptionKey.getData(), 0, rv, offset, SessionKey.KEYSIZE_BYTES);
|
||||||
@ -272,6 +352,8 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Is NOT Encrypted");
|
_log.debug("Is NOT Encrypted");
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
switch (getDeliveryMode()) {
|
switch (getDeliveryMode()) {
|
||||||
case FLAG_MODE_LOCAL:
|
case FLAG_MODE_LOCAL:
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
@ -329,7 +411,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the number of bytes written to the target
|
* @return the number of bytes written to the target
|
||||||
*/
|
*/
|
||||||
public int writeBytes(byte target[], int offset) {
|
public int writeBytes(byte target[], int offset) {
|
||||||
if ( (_deliveryMode < 0) || (_deliveryMode > FLAG_MODE_TUNNEL) ) throw new IllegalStateException("Invalid data: mode = " + _deliveryMode);
|
if ( (_deliveryMode < 0) || (_deliveryMode > FLAG_MODE_TUNNEL) ) throw new IllegalStateException("Invalid data: mode = " + _deliveryMode);
|
||||||
@ -357,7 +439,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
return (getDelayRequested() == instr.getDelayRequested()) &&
|
return (getDelayRequested() == instr.getDelayRequested()) &&
|
||||||
(getDelaySeconds() == instr.getDelaySeconds()) &&
|
(getDelaySeconds() == instr.getDelaySeconds()) &&
|
||||||
(getDeliveryMode() == instr.getDeliveryMode()) &&
|
(getDeliveryMode() == instr.getDeliveryMode()) &&
|
||||||
(getEncrypted() == instr.getEncrypted()) &&
|
//(getEncrypted() == instr.getEncrypted()) &&
|
||||||
DataHelper.eq(getDestination(), instr.getDestination()) &&
|
DataHelper.eq(getDestination(), instr.getDestination()) &&
|
||||||
DataHelper.eq(getEncryptionKey(), instr.getEncryptionKey()) &&
|
DataHelper.eq(getEncryptionKey(), instr.getEncryptionKey()) &&
|
||||||
DataHelper.eq(getRouter(), instr.getRouter()) &&
|
DataHelper.eq(getRouter(), instr.getRouter()) &&
|
||||||
@ -396,7 +478,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
buf.append("\n\tDelay requested: ").append(getDelayRequested());
|
buf.append("\n\tDelay requested: ").append(getDelayRequested());
|
||||||
buf.append("\n\tDelay seconds: ").append(getDelaySeconds());
|
buf.append("\n\tDelay seconds: ").append(getDelaySeconds());
|
||||||
buf.append("\n\tDestination: ").append(getDestination());
|
buf.append("\n\tDestination: ").append(getDestination());
|
||||||
buf.append("\n\tEncrypted: ").append(getEncrypted());
|
//buf.append("\n\tEncrypted: ").append(getEncrypted());
|
||||||
buf.append("\n\tEncryption key: ").append(getEncryptionKey());
|
buf.append("\n\tEncryption key: ").append(getEncryptionKey());
|
||||||
buf.append("\n\tRouter: ").append(getRouter());
|
buf.append("\n\tRouter: ").append(getRouter());
|
||||||
buf.append("\n\tTunnelId: ").append(getTunnelId());
|
buf.append("\n\tTunnelId: ").append(getTunnelId());
|
||||||
|
Reference in New Issue
Block a user