mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-11-02 18:46:45 +00:00
only update processed parts count with unique parts
This commit is contained in:
parent
1fe0489ceb
commit
6ee94c42ac
3 changed files with 63 additions and 2 deletions
|
@ -16,6 +16,7 @@ import static com.sparrowwallet.hummingbird.fountain.FountainUtils.chooseFragmen
|
|||
public class FountainDecoder {
|
||||
private final Set<Integer> recievedPartIndexes = new TreeSet<>();
|
||||
private Set<Integer> lastPartIndexes;
|
||||
private final Set<Integer> processedPartHashes = new HashSet<>();
|
||||
private int processedPartsCount = 0;
|
||||
private Result result;
|
||||
private long checksum;
|
||||
|
@ -114,8 +115,10 @@ public class FountainDecoder {
|
|||
processQueueItem();
|
||||
}
|
||||
|
||||
// Keep track of how many parts we've processed
|
||||
processedPartsCount += 1;
|
||||
// Keep track of how many unique parts we've processed
|
||||
if(processedPartHashes.add(encoderPart.hashCode())) {
|
||||
processedPartsCount++;
|
||||
}
|
||||
//printPartEnd();
|
||||
|
||||
return true;
|
||||
|
|
|
@ -181,5 +181,41 @@ public class FountainEncoder {
|
|||
|
||||
return new Part(seqNum.getValue().longValue(), seqLen.getValue().intValue(), messageLen.getValue().intValue(), checksum.getValue().longValue(), data.getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) {
|
||||
return true;
|
||||
}
|
||||
if(o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Part part = (Part) o;
|
||||
|
||||
if(seqNum != part.seqNum) {
|
||||
return false;
|
||||
}
|
||||
if(seqLen != part.seqLen) {
|
||||
return false;
|
||||
}
|
||||
if(messageLen != part.messageLen) {
|
||||
return false;
|
||||
}
|
||||
if(checksum != part.checksum) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(data, part.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (seqNum ^ (seqNum >>> 32));
|
||||
result = 31 * result + seqLen;
|
||||
result = 31 * result + messageLen;
|
||||
result = 31 * result + (int) (checksum ^ (checksum >>> 32));
|
||||
result = 31 * result + Arrays.hashCode(data);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,4 +216,26 @@ public class URTest {
|
|||
Assert.assertEquals(TestUtils.bytesToHex(ur.toBytes()), "70736274ff0100520200000001adb4134883273f90371c364743e1816de7099df3895dbc95ebcd19beb83200ec0000000000ffffffff01e80300000000000016001457766b7686ca60e5221119966bdfe1d1f4b62181000000000001011f581b0000000000001600145da1bc9a730b7e9d209f15aff9c096f6bbd89d26220603ccd4532b1350e04cbaff91056bdb08bd3877b4fcb8cd70aaeda5239ce112547b180000000054000080000000800000008000000000060000000000");
|
||||
Arrays.stream(fragments).forEach(part -> Assert.assertTrue(LegacyURDecoder.isLegacyURFragment(part)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateDecode() {
|
||||
String[] parts = new String[] {
|
||||
"ur:bytes/1-9/lpadascfadaxcywenbpljkhdcahkadaemejtswhhylkepmykhhtsytsnoyoyaxaedsuttydmmhhpktpmsrjtdkgslpgh",
|
||||
"ur:bytes/2-9/lpaoascfadaxcywenbpljkhdcagwdpfnsboxgwlbaawzuefywkdplrsrjynbvygabwjldapfcsgmghhkhstlrdcxaefz",
|
||||
"ur:bytes/3-9/lpaxascfadaxcywenbpljkhdcahelbknlkuejnbadmssfhfrdpsbiegecpasvssovlgeykssjykklronvsjksopdzmol"
|
||||
};
|
||||
|
||||
URDecoder urDecoder = new URDecoder();
|
||||
Assert.assertEquals(0, urDecoder.getProcessedPartsCount());
|
||||
urDecoder.receivePart(parts[0]);
|
||||
Assert.assertEquals(1, urDecoder.getProcessedPartsCount());
|
||||
urDecoder.receivePart(parts[0]);
|
||||
Assert.assertEquals(1, urDecoder.getProcessedPartsCount());
|
||||
urDecoder.receivePart(parts[1]);
|
||||
Assert.assertEquals(2, urDecoder.getProcessedPartsCount());
|
||||
urDecoder.receivePart(parts[0]);
|
||||
Assert.assertEquals(2, urDecoder.getProcessedPartsCount());
|
||||
urDecoder.receivePart(parts[2]);
|
||||
Assert.assertEquals(3, urDecoder.getProcessedPartsCount());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue