Skip to content

Commit

Permalink
Improve publish quality
Browse files Browse the repository at this point in the history
This slows down publishing to 11s

(a large fraction of closest nodes may be quic only, so we need to try next closest)
  • Loading branch information
ianopolous committed Dec 13, 2023
1 parent c8bef93 commit 8b86b55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/main/java/org/peergos/protocol/dht/Kademlia.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,30 @@ public CompletableFuture<Void> publishValue(PrivKey priv,
// exit early if we have enough results
if (publishes.size() >= minPublishes)
break;
if (toQuery.size() == remaining)
if (toQuery.size() == remaining) {
// publish to closest remaining nodes
while (publishes.size() < minPublishes) {
List<RoutingEntry> closest = toQuery.stream()
.limit(minPublishes - publishes.size() + 5)
.collect(Collectors.toList());
List<? extends Future<?>> lastFutures = closest.stream()
.map(r -> {
toQuery.remove(r);
queried.add(r.addresses.peerId);
return ioExec.submit(() -> {
if (putValue(priv, publisher, publishValue, sequence, expiry, ttlNanos, r.addresses, us))
publishes.add(r.addresses.peerId);
});
})
.collect(Collectors.toList());
lastFutures.forEach(f -> {
try {
f.get();
} catch (Exception e) {}
});
}
break;
}
}
return CompletableFuture.completedFuture(null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/peergos/KademliaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void ipnsBenchmark() throws Exception {

List<PrivKey> signers = new ArrayList<>();
long publishTotal = 0, resolveTotal = 0;
int iterations = 5;
int iterations = 25;
for (int i = 0; i < iterations; i++) {
// publish mapping from node 1
PrivKey signer = Ed25519Kt.generateEd25519KeyPair().getFirst();
Expand Down

0 comments on commit 8b86b55

Please sign in to comment.