Skip to content

Commit

Permalink
Improve routing table bootstrap parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Dec 13, 2023
1 parent 6117454 commit e1ccbfd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/peergos/protocol/dht/Kademlia.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ public int bootstrapRoutingTable(Host host, List<MultiAddress> addrs, Predicate<
})
.filter(filter)
.collect(Collectors.toList());
List<? extends CompletableFuture<? extends KademliaController>> futures = resolved.stream()
.parallel()
List<? extends Future<? extends KademliaController>> futures = resolved.stream()
.map(addr -> {
Multiaddr addrWithPeer = Multiaddr.fromString(addr);
addressBook.setAddrs(addrWithPeer.getPeerId(), 0, addrWithPeer);
return dial(host, addrWithPeer).getController();
return ioExec.submit(() -> dial(host, addrWithPeer).getController().join());
})
.collect(Collectors.toList());
int successes = 0;
for (CompletableFuture<? extends KademliaController> future : futures) {
for (Future<? extends KademliaController> future : futures) {
try {
future.orTimeout(5, TimeUnit.SECONDS).join();
future.get(5, TimeUnit.SECONDS);
successes++;
} catch (Exception e) {}
}
Expand Down

0 comments on commit e1ccbfd

Please sign in to comment.