Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update libp2p versions and fix issues with breaking changes. #19

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions src/main/java/com/limechain/network/kad/KademliaService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.limechain.network.kad;

import com.limechain.network.kad.dto.Host;
import com.limechain.network.kad.dto.PeerId;
import com.limechain.network.protocol.NetworkService;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.java.Log;
import org.teavm.jso.JSBody;

Expand All @@ -18,8 +15,6 @@
public class KademliaService extends NetworkService {
public static final int REPLICATION = 20;

@Setter
private Host host;
private int successfulBootNodes;

/**
Expand All @@ -39,12 +34,6 @@ public int connectBootNodes(String[] bootNodes) {
}
peer = getPeerId();
}
String peerIdStr = peer.toString();
byte[] privateKey = getPeerPrivateKey();
byte[] publicKey = getPeerPublicKey();

PeerId peerId = new PeerId(privateKey, publicKey, peerIdStr);
this.host = new Host(peerId);

successfulBootNodes = getPeerStoreSize();

Expand All @@ -64,25 +53,19 @@ public void updateSuccessfulBootNodes() {
@JSBody(script = "return window.fruzhin.libp?.peerId")
public static native Object getPeerId();

@JSBody(script = "return window.fruzhin.libp.peerId.privateKey")
public static native byte[] getPeerPrivateKey();

@JSBody(script = "return window.fruzhin.libp.peerId.publicKey")
public static native byte[] getPeerPublicKey();

@JSBody(script = "return window.fruzhin.libp.getConnections().length")
public static native int getPeerStoreSize();

/**
* Populates Kademlia dht with peers closest in distance to a random id then makes connections with our node
*/
@JSBody(script = "window.fruzhin.libp.peerStore.forEach( async (p) => {" +
" for await (const foundPeer of dht.peerRouting.getClosestPeers(p.id.toBytes())){" +
" if(foundPeer.peer?.multiaddrs?.length > 0){" +
" try{window.fruzhin.libp.dial(foundPeer.peer)}finally{}" +
" }" +
" }" +
"});")
" for await (const foundPeer of dht.peerRouting.getClosestPeers(p.id.toBytes())){" +
" if(foundPeer.peer?.multiaddrs?.length > 0){" +
" try{window.fruzhin.libp.dial(foundPeer.peer)}finally{}" +
" }" +
" }" +
"});")
public static native void findNewPeers();

}
12 changes: 0 additions & 12 deletions src/main/java/com/limechain/network/kad/dto/Host.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/com/limechain/network/kad/dto/PeerId.java

This file was deleted.

24 changes: 12 additions & 12 deletions src/main/webapp/js/fruzhin-lib.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/[email protected]/dist/index.min.js';
import 'https://unpkg.com/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@chainsafe/[email protected]/dist/index.min.js';
import 'https://unpkg.com/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@libp2p/[email protected]/dist/index.min.js';
import 'https://unpkg.com/[email protected]/dist/index.min.js';
import 'https://unpkg.com/@muradsenteca/ed25519@1.0.0/dist/index.min.js'
import 'https://unpkg.com/it-pipe@3.0.1/dist/index.min.js';
import 'https://unpkg.com/@muradsenteca/[email protected]/dist/index.min.js'
import 'https://unpkg.com/@muradsenteca/[email protected]/dist/index.min.js'

import * as HTTP from './http.js';
import * as Fruzhin from './fruzhin.js'
Expand All @@ -25,7 +25,7 @@ var startLibp2p = async (bootnodes) => {
Libp2PWebsockets.webSockets()
],
streamMuxers: [ChainsafeLibp2PYamux.yamux()],
connectionEncryption: [ChainsafeLibp2PNoise.noise()],
connectionEncrypters: [ChainsafeLibp2PNoise.noise()],
peerDiscovery: [
Libp2PBootstrap.bootstrap({
list: bootnodes
Expand Down
Loading