Router: Implement expiration for BlindData entries

This commit is contained in:
zzz
2019-09-17 11:17:14 +00:00
parent 0c2a8e9244
commit 94c96b09e9
8 changed files with 99 additions and 24 deletions
+30 -2
View File
@@ -28,6 +28,7 @@ public class BlindData {
private boolean _secretRequired;
private boolean _authRequired;
private long _date;
private long _expiration;
private String _b32;
/**
@@ -257,6 +258,7 @@ public class BlindData {
}
/**
* Creation date. Absolute timestamp.
* @since 0.9.41
*/
public void setDate(long date) {
@@ -264,6 +266,9 @@ public class BlindData {
}
/**
* Creation date. Absolute timestamp.
* Returns zero if not specified.
*
* @return creation date or as overridden by setDate()
* @since 0.9.41
*/
@@ -271,14 +276,33 @@ public class BlindData {
return _date;
}
/**
* Expiration date. Absolute timestamp.
* @since 0.9.43
*/
public void setExpiration(long date) {
_expiration = date;
}
/**
* Expiration date. Absolute timestamp.
* Returns zero if not specified.
*
* @return expiration date or as overridden by setExpiration()
* @since 0.9.43
*/
public long getExpiration() {
return _expiration;
}
@Override
public synchronized String toString() {
calculate();
StringBuilder buf = new StringBuilder(1024);
buf.append("[BlindData: ");
buf.append("\n\tSigningPublicKey: ").append(_clearSPK);
buf.append("\n\tAlpha : ").append(_alpha);
buf.append("\n\tAlpha valid for : ").append((new Date(_date)).toString());
buf.append("\n\tAlpha : ").append(getAlpha());
buf.append("\n\tAlpha valid for : ").append((new Date(_routingKeyGenMod)).toString());
buf.append("\n\tBlindedPublicKey: ").append(_blindSPK);
buf.append("\n\tBlinded Hash : ").append(_blindHash);
if (_secret != null)
@@ -305,6 +329,10 @@ public class BlindData {
buf.append("\n\t + secret : ").append(Blinding.encode(_clearSPK, true, _authRequired));
if (!(_authRequired || _secretRequired))
buf.append("\n\t + auth,secret : ").append(Blinding.encode(_clearSPK, true, true));
if (_date > 0)
buf.append("\n\tCreated : ").append((new Date(_date)).toString());
if (_expiration > 0)
buf.append("\n\tExpires : ").append((new Date(_expiration)).toString());
buf.append(']');
return buf.toString();
}
@@ -60,9 +60,8 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
*
* @param expiration ms from now or 0 for forever
*/
public BlindingInfoMessage(BlindData bd,
SessionId id, int expiration) {
this(id, expiration, bd.getAuthType(), bd.getBlindedSigType(), bd.getAuthPrivKey(), bd.getSecret());
public BlindingInfoMessage(BlindData bd, SessionId id) {
this(id, bd.getExpiration(), bd.getAuthType(), bd.getBlindedSigType(), bd.getAuthPrivKey(), bd.getSecret());
Destination dest = bd.getDestination();
if (dest != null) {
_dest = dest;
@@ -157,13 +156,13 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
_endpointType = TYPE_KEY;
}
private BlindingInfoMessage(SessionId id, int expiration, int authType, SigType blindType,
private BlindingInfoMessage(SessionId id, long expiration, int authType, SigType blindType,
PrivateKey privKey, String secret) {
if (id == null || blindType == null)
throw new IllegalArgumentException();
if (authType != BlindData.AUTH_NONE && authType != BlindData.AUTH_DH &&
authType != BlindData.AUTH_PSK)
throw new IllegalArgumentException();
throw new IllegalArgumentException("Bad auth type");
if (authType == BlindData.AUTH_NONE && privKey != null)
throw new IllegalArgumentException("no key required");
if (authType != BlindData.AUTH_NONE && privKey == null)
@@ -171,8 +170,9 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
_sessionId = id;
_authType = authType;
_blindType = blindType;
if (expiration > 0)
_expiration = expiration + I2PAppContext.getGlobalContext().clock().now();
_expiration = expiration;
if (expiration > 0 && expiration < Integer.MAX_VALUE)
_expiration += I2PAppContext.getGlobalContext().clock().now();
_privkey = privKey;
_secret = secret;
}
@@ -262,6 +262,10 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
_blindData = new BlindData(I2PAppContext.getGlobalContext(), _dest, _blindType, _secret, _authType, _privkey);
else if (_endpointType == TYPE_KEY)
_blindData = new BlindData(I2PAppContext.getGlobalContext(), _pubkey, _blindType, _secret, _authType, _privkey);
if (_blindData != null) {
_blindData.setDate(I2PAppContext.getGlobalContext().clock().now());
_blindData.setExpiration(_expiration);
}
// HASH and HOST not supported by router yet
return _blindData;
}
@@ -278,7 +282,7 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
_blindType = SigType.getByCode(bt);
if (_blindType == null)
throw new I2CPMessageException("unsupported sig type " + bt);
_expiration = DataHelper.readLong(in, 4);
_expiration = DataHelper.readLong(in, 4) * 1000;
if (_endpointType == TYPE_HASH) {
_hash = Hash.create(in);
} else if (_endpointType == TYPE_HOST) {
@@ -338,7 +342,7 @@ public class BlindingInfoMessage extends I2CPMessageImpl {
os.write(flags);
os.write((byte) _endpointType);
DataHelper.writeLong(os, 2, _blindType.getCode());
DataHelper.writeLong(os, 4, _expiration);
DataHelper.writeLong(os, 4, _expiration / 1000);
if (_endpointType == TYPE_HASH) {
_hash.writeBytes(os);
} else if (_endpointType == TYPE_HOST) {