Skip to content

Commit

Permalink
fix/feat!: reintroduce protocolId parameter
Browse files Browse the repository at this point in the history
turned out later on that this refactor from the upstream is breaking for us since we need to use Nabu with custom protocol IDs which significantly diverge from the upstream's vision. Has been noted in a comment, too.
  • Loading branch information
David-Petrov committed Apr 15, 2024
1 parent 3825866 commit 0f92552
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static EmbeddedIpfs build(RecordStore records,
}
Multihash ourPeerId = Multihash.deserialize(builder.getPeerId().getBytes());

Kademlia dht = new Kademlia(new KademliaEngine(ourPeerId, providers, records, blocks), 20, 3, localEnabled, false);
Kademlia dht = new Kademlia(new KademliaEngine(ourPeerId, providers, records, blocks), Kademlia.WAN_DHT_ID, 20, 3, localEnabled, false);
CircuitStopProtocol.Binding stop = new CircuitStopProtocol.Binding();
CircuitHopProtocol.RelayManager relayManager = CircuitHopProtocol.RelayManager.limitTo(builder.getPrivateKey(), ourPeerId, 5);
Bitswap bitswap = new Bitswap(bitswapProtocolId.orElse(Bitswap.PROTOCOL_ID),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/peergos/HostBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static HostBuilder create(int listenPort,
.generateIdentity()
.listen(List.of(new MultiAddress("/ip4/0.0.0.0/tcp/" + listenPort)));
Multihash ourPeerId = Multihash.deserialize(builder.peerId.getBytes());
Kademlia dht = new Kademlia(new KademliaEngine(ourPeerId, providers, records, blocks), 20, 3, localEnabled, false);
Kademlia dht = new Kademlia(new KademliaEngine(ourPeerId, providers, records, blocks), Kademlia.WAN_DHT_ID, 20, 3, localEnabled, false);
CircuitStopProtocol.Binding stop = new CircuitStopProtocol.Binding();
CircuitHopProtocol.RelayManager relayManager = CircuitHopProtocol.RelayManager.limitTo(builder.privKey, ourPeerId, 5);
return builder.addProtocols(List.of(
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/peergos/protocol/dht/Kademlia.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public class Kademlia extends StrictProtocolBinding<KademliaController> implemen
private final Integer replication;
private final Integer alpha;

public Kademlia(KademliaEngine dht, Integer replication, Integer alpha, boolean localOnly, boolean clientMode) {
super(localOnly ? LAN_DHT_ID : WAN_DHT_ID, new KademliaProtocol(dht, clientMode));
// INTENTIONALITY: We want to preserve `protocolId` as a parameter since we're using Nabu for other protocol IDs,
// hence a significant, and intentional, divergence from the upstream.
public Kademlia(KademliaEngine dht, String protocolId, Integer replication, Integer alpha, boolean localOnly, boolean clientMode) {
super(protocolId, new KademliaProtocol(dht, clientMode));
this.engine = dht;
this.localDht = localOnly;
this.replication = replication;
Expand Down

0 comments on commit 0f92552

Please sign in to comment.