Skip to content

Commit

Permalink
Fix peer lookup reliability in Kademlia
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Apr 3, 2024
1 parent b4b3c96 commit 96d35a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public void start() {
IdentifyBuilder.addIdentifyProtocol(node);
LOG.info("Node started and listening on " + node.listenAddresses());
LOG.info("Bootstrapping IPFS routing table");
if (bootstrap.isEmpty())
LOG.warning("Starting with empty bootstrap list - you will not join the global dht");
int connections = dht.bootstrapRoutingTable(node, bootstrap, addr -> !addr.contains("/wss/"));
LOG.info("Bootstrapping IPFS kademlia");
dht.bootstrap(node);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/peergos/protocol/dht/Kademlia.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public List<PeerAddresses> findClosestPeers(byte[] key, int maxCount, Host us) {
Id keyId = Id.create(Hash.sha256(key), 256);
SortedSet<RoutingEntry> closest = Collections.synchronizedSortedSet(new TreeSet<>((a, b) -> compareKeys(a, b, keyId)));
SortedSet<RoutingEntry> toQuery = Collections.synchronizedSortedSet(new TreeSet<>((a, b) -> compareKeys(a, b, keyId)));
List<PeerAddresses> localClosest = engine.getKClosestPeers(key, maxCount);
List<PeerAddresses> localClosest = engine.getKClosestPeers(key, Math.max(6, maxCount));
if (maxCount == 1) {
Optional<PeerAddresses> match = localClosest.stream().filter(p -> Arrays.equals(p.peerId.toBytes(), key)).findFirst();
if (match.isPresent())
Expand Down

0 comments on commit 96d35a9

Please sign in to comment.