forked from I2P_Developers/i2p.i2p
I2NP: Implement DatabaseLookupMessage search type field,
to replace all-zeros hash, and ease implementation for separate LS and RI databases, as documented in i2np spec.
This commit is contained in:
@@ -40,6 +40,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
private List<Hash> _dontIncludePeers;
|
||||
private SessionKey _replyKey;
|
||||
private SessionTag _replyTag;
|
||||
private Type _type;
|
||||
|
||||
//private static volatile long _currentLookupPeriod = 0;
|
||||
//private static volatile int _currentLookupCount = 0;
|
||||
@@ -52,7 +53,26 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
private static final int MAX_NUM_PEERS = 512;
|
||||
|
||||
private static final byte FLAG_TUNNEL = 0x01;
|
||||
// any flags below here will confuse routers 0.9.5 or lower
|
||||
private static final byte FLAG_ENCRYPT = 0x02;
|
||||
private static final byte FLAG_TYPE_MASK = 0x0c;
|
||||
private static final byte FLAG_TYPE_ANY = 0;
|
||||
private static final byte FLAG_TYPE_LS = 0x04;
|
||||
private static final byte FLAG_TYPE_RI = 0x08;
|
||||
private static final byte FLAG_TYPE_EXPL = 0x0c;
|
||||
|
||||
/** @since 0.9.16 */
|
||||
public enum Type {
|
||||
/** default - LS or RI */
|
||||
ANY,
|
||||
/** lease set only */
|
||||
LS,
|
||||
/** router info only */
|
||||
RI,
|
||||
/** exploratory - return closest non-floodfill router infos */
|
||||
EXPL
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* It's not supported until 0.9.7, but as of
|
||||
@@ -86,6 +106,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
// + " messages so far)", new Exception("Flood cause"));
|
||||
// }
|
||||
//}
|
||||
_type = Type.ANY;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,6 +151,30 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
_key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the type of data being searched for.
|
||||
* Default ANY.
|
||||
*
|
||||
* @return non-null
|
||||
* @since 0.9.16
|
||||
*/
|
||||
public Type getSearchType() { return _type; }
|
||||
|
||||
/**
|
||||
* Defines the type of data being searched for.
|
||||
* Default ANY.
|
||||
* Must be ANY for queried routers 0.9.5 or lower, but there are few if
|
||||
* any floodfills that old left, so not even worth checking.
|
||||
*
|
||||
* @param type non-null
|
||||
* @since 0.9.16
|
||||
*/
|
||||
public void setSearchType(Type type) {
|
||||
if (type == null)
|
||||
throw new IllegalArgumentException();
|
||||
_type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the router who requested this lookup
|
||||
*
|
||||
@@ -285,6 +330,21 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
// TODO store the whole flag byte
|
||||
boolean tunnelSpecified = (data[curIndex] & FLAG_TUNNEL) != 0;
|
||||
boolean replyKeySpecified = (data[curIndex] & FLAG_ENCRYPT) != 0;
|
||||
switch (data[curIndex] & FLAG_TYPE_MASK) {
|
||||
case FLAG_TYPE_LS:
|
||||
_type = Type.LS;
|
||||
break;
|
||||
case FLAG_TYPE_RI:
|
||||
_type = Type.RI;
|
||||
break;
|
||||
case FLAG_TYPE_EXPL:
|
||||
_type = Type.EXPL;
|
||||
break;
|
||||
case FLAG_TYPE_ANY:
|
||||
default:
|
||||
_type = Type.ANY;
|
||||
break;
|
||||
}
|
||||
curIndex++;
|
||||
|
||||
if (tunnelSpecified) {
|
||||
@@ -348,6 +408,21 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
byte flag = FLAG_TUNNEL;
|
||||
if (_replyKey != null)
|
||||
flag |= FLAG_ENCRYPT;
|
||||
switch (_type) {
|
||||
case LS:
|
||||
flag |= FLAG_TYPE_LS;
|
||||
break;
|
||||
case RI:
|
||||
flag |= FLAG_TYPE_RI;
|
||||
break;
|
||||
case EXPL:
|
||||
flag |= FLAG_TYPE_EXPL;
|
||||
break;
|
||||
case ANY:
|
||||
default:
|
||||
// flag is 0
|
||||
break;
|
||||
}
|
||||
out[curIndex++] = flag;
|
||||
byte id[] = DataHelper.toLong(4, _replyTunnel.getTunnelId());
|
||||
System.arraycopy(id, 0, out, curIndex, 4);
|
||||
@@ -410,6 +485,7 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder(256);
|
||||
buf.append("[DatabaseLookupMessage: ");
|
||||
buf.append("\n\tSearch Type: ").append(_type);
|
||||
buf.append("\n\tSearch Key: ").append(_key);
|
||||
if (_replyKey != null)
|
||||
buf.append("\n\tReply GW: ");
|
||||
|
||||
Reference in New Issue
Block a user