SSU2: Catch errors on bad ack blocks

so rest of payload can be processed
Improve debug output on errors
This commit is contained in:
zzz
2022-06-10 07:50:43 -04:00
parent cdf778514c
commit 9de618d644
2 changed files with 14 additions and 7 deletions

View File

@@ -567,12 +567,19 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
_log.debug("Got dup ACK block: " + SSU2Bitfield.toString(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0)));
return;
}
SSU2Bitfield ackbf;
ackbf = SSU2Bitfield.fromACKBlock(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0));
if (_log.shouldDebug())
_log.debug("Got new ACK block: " + SSU2Bitfield.toString(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0)));
// calls bitSet() below
ackbf.forEachAndNot(_ackedMessages, this);
try {
SSU2Bitfield ackbf = SSU2Bitfield.fromACKBlock(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0));
if (_log.shouldDebug())
_log.debug("Got new ACK block: " + SSU2Bitfield.toString(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0)));
// calls bitSet() below
ackbf.forEachAndNot(_ackedMessages, this);
} catch (Exception e) {
// IllegalArgumentException, buggy ack block, let the other blocks get processed
if (_log.shouldWarn())
_log.warn("Bad ACK block\n" + SSU2Bitfield.toString(ackThru, acks, ranges, (ranges != null ? ranges.length / 2 : 0)) +
"\nAck through " + ackThru + " acks " + acks + (ranges != null ? "\n" + HexDump.dump(ranges) : "") +
"\nfrom " + this, e);
}
}
public void gotTermination(int reason, long count) {

View File

@@ -36,7 +36,7 @@ class SSU2Bitfield {
*/
public SSU2Bitfield(int size, long offset) {
if (size <= 0 || offset < 0)
throw new IllegalArgumentException();
throw new IllegalArgumentException("size " + size + " offset " + offset);
// force mult. of 256
size = (size + 255) & 0x7FFFFF00;
this.size = size;