I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit b19b529a authored by zzz's avatar zzz
Browse files

Ratchet: Expire tags too far behind current one

parent 0c4cf5d3
No related branches found
No related tags found
No related merge requests found
...@@ -368,6 +368,23 @@ class RatchetTagSet implements TagSetHandle { ...@@ -368,6 +368,23 @@ class RatchetTagSet implements TagSetHandle {
} }
} }
// trim any too far behind
{
int tooOld = usedTagNumber - _maxSize;
int toTrim = 0;
int tagnum;
while ((tagnum = _sessionTags.keyAt(toTrim)) < tooOld) {
int kidx = _sessionKeys.indexOfKey(tagnum);
if (kidx >= 0)
_sessionKeys.removeAt(kidx);
if (_lsnr != null)
_lsnr.expireTag(_sessionTags.valueAt(toTrim), this);
toTrim++;
}
if (toTrim > 0)
_sessionTags.removeAtRange(0, toTrim);
}
// trim if too big // trim if too big
int toTrim = _sessionTags.size() - _maxSize; int toTrim = _sessionTags.size() - _maxSize;
if (toTrim > 0) { if (toTrim > 0) {
...@@ -394,7 +411,7 @@ class RatchetTagSet implements TagSetHandle { ...@@ -394,7 +411,7 @@ class RatchetTagSet implements TagSetHandle {
} }
/** /**
* For outbound only. * Public for outbound only. Used internally for inbound.
* Call before consumeNextKey(); * Call before consumeNextKey();
* *
* @return a tag or null if we ran out * @return a tag or null if we ran out
...@@ -504,7 +521,7 @@ class RatchetTagSet implements TagSetHandle { ...@@ -504,7 +521,7 @@ class RatchetTagSet implements TagSetHandle {
System.out.println("Size now: " + rts.size()); System.out.println("Size now: " + rts.size());
System.out.println(""); System.out.println("");
System.out.println("Receive test in-order"); System.out.println("Receive test in-order");
rts = new RatchetTagSet(hkdf, null, k1, k2, 0, 0, 10, 50); rts = new RatchetTagSet(hkdf, null, (PublicKey) null, k1, k2, 0, 0, 10, 50);
System.out.println("Size now: " + rts.size()); System.out.println("Size now: " + rts.size());
List<RatchetSessionTag> tags = rts.getTags(); List<RatchetSessionTag> tags = rts.getTags();
int j = 0; int j = 0;
...@@ -527,7 +544,7 @@ class RatchetTagSet implements TagSetHandle { ...@@ -527,7 +544,7 @@ class RatchetTagSet implements TagSetHandle {
System.out.println("Size now: " + rts.size()); System.out.println("Size now: " + rts.size());
System.out.println(""); System.out.println("");
System.out.println("Receive test out of order"); System.out.println("Receive test out of order");
rts = new RatchetTagSet(hkdf, null, k1, k2, 0, 0, 10, 50); rts = new RatchetTagSet(hkdf, null, (PublicKey) null, k1, k2, 0, 0, 10, 50);
System.out.println("Size now: " + rts.size()); System.out.println("Size now: " + rts.size());
tags = rts.getTags(); tags = rts.getTags();
List<RatchetSessionTag> origtags = new ArrayList<RatchetSessionTag>(tags); List<RatchetSessionTag> origtags = new ArrayList<RatchetSessionTag>(tags);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment