Skip to content

Commit

Permalink
Don't identify incoming connections for peers already in
Browse files Browse the repository at this point in the history
address book
  • Loading branch information
ianopolous committed Dec 5, 2023
1 parent b70d043 commit 8b6dd6f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/java/org/peergos/HostBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,19 @@ public static Host build(PrivKey privKey,
addrs.addAddrs(remotePeer, 0, remote);
if (connection.isInitiator())
return;
StreamPromise<IdentifyController> stream = connection.muxerSession()
.createStream(new IdentifyBinding(new IdentifyProtocol()));
stream.getController()
.thenCompose(IdentifyController::id)
.thenAccept(remoteId -> {
Multiaddr[] remoteAddrs = remoteId.getListenAddrsList()
.stream()
.map(bytes -> Multiaddr.deserialize(bytes.toByteArray()))
.toArray(Multiaddr[]::new);
addrs.getAddrs(remotePeer).thenAccept(existing -> {
addrs.getAddrs(remotePeer).thenAccept(existing -> {
if (existing.isEmpty())
return;
StreamPromise<IdentifyController> stream = connection.muxerSession()
.createStream(new IdentifyBinding(new IdentifyProtocol()));
stream.getController()
.thenCompose(IdentifyController::id)
.thenAccept(remoteId -> {
Multiaddr[] remoteAddrs = remoteId.getListenAddrsList()
.stream()
.map(bytes -> Multiaddr.deserialize(bytes.toByteArray()))
.toArray(Multiaddr[]::new);

addrs.addAddrs(remotePeer, 0, remoteAddrs);
List<String> protocolIds = remoteId.getProtocolsList().stream().collect(Collectors.toList());
if (protocolIds.contains(Kademlia.WAN_DHT_ID) && wan.isPresent()) {
Expand All @@ -204,7 +207,7 @@ public static Host build(PrivKey privKey,
connection.muxerSession().createStream(wan.get());
}
});
});
});
});

for (String listenAddr : listenAddrs) {
Expand Down

0 comments on commit 8b6dd6f

Please sign in to comment.