diff --git a/src/main/java/com/limechain/network/protocol/blockannounce/BlockAnnounceEngine.java b/src/main/java/com/limechain/network/protocol/blockannounce/BlockAnnounceEngine.java index 49ce13c62..c37c90fb6 100644 --- a/src/main/java/com/limechain/network/protocol/blockannounce/BlockAnnounceEngine.java +++ b/src/main/java/com/limechain/network/protocol/blockannounce/BlockAnnounceEngine.java @@ -56,17 +56,21 @@ public static String getHandshake() { @JSBody(params = {"announceExport", "protocolId"}, script = "window.fruzhin.libp.handle(protocolId, async ({connection, stream}) => {" + - " ItPipe.pipe(stream, async function (source) {" + - " for await (const msg of source) {" + - " let subarr = msg.subarray();" + - " if(subarr.length === 69) {" + - " let handshake = announceExport.getHandshake();" + - " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" + - " } else if (subarr.length > 1) {" + - " announceExport.blockAnnounce(Ed25519.b2h(subarr.slice(2)), connection.remotePeer.toString());" + - " }" + - " }" + - " });" + - " });") + " ItPipe.pipe(stream, async function (source) {" + + " for await (const msg of source) {" + + " let subarr = msg.subarray();" + + " if(subarr.length === 69) {" + + " let handshake = announceExport.getHandshake();" + + " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" + + " } else if (subarr.length > 1) {" + + " announceExport.blockAnnounce(Ed25519.b2h(subarr.slice(2)), connection.remotePeer.toString());" + + " }" + + " }" + + " });" + + "});" + + "fruzhin.libp.addEventListener('peer:connect', async (evt) => {" + + " let handshake = announceExport.getHandshake();" + + " (await ItPbStream.pbStream(await window.fruzhin.libp.dialProtocol(evt.detail, protocolId))).writeLP(Ed25519.h2b(handshake));" + + "});") public static native void registerHandler(JSObject announceExport, String protocolId); } diff --git a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaController.java b/src/main/java/com/limechain/network/protocol/grandpa/GrandpaController.java deleted file mode 100644 index 153c67040..000000000 --- a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.limechain.network.protocol.grandpa; - -/** - * A controller for sending message on a GRANDPA stream. - */ -public class GrandpaController { - protected GrandpaEngine engine = new GrandpaEngine(); -// protected final Stream stream; - -// public GrandpaController(Stream stream) { -// this.stream = stream; -// } - - /** - * Sends a handshake message over the controller stream. - */ -// public void sendHandshake() { -// engine.writeHandshakeToStream(stream, stream.remotePeerId()); -// } - - /** - * Sends a neighbour message over the controller stream. - */ -// public void sendNeighbourMessage() { -// engine.writeNeighbourMessage(stream, stream.remotePeerId()); -// } -} diff --git a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaEngine.java b/src/main/java/com/limechain/network/protocol/grandpa/GrandpaEngine.java index 916dadf65..94a3d3c9c 100644 --- a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaEngine.java +++ b/src/main/java/com/limechain/network/protocol/grandpa/GrandpaEngine.java @@ -112,18 +112,26 @@ public static String getNeighbourMessage() { @JSBody(params = {"grandpaExport", "protocolId"}, script = "window.fruzhin.libp.handle(protocolId, async ({connection, stream}) => {" + - " ItPipe.pipe(stream, async function (source) {" + - " for await (const msg of source) {" + " let subarr = msg.subarray();" + - " if(subarr.length === 1) {" + - " let handshake = grandpaExport.getHandshake();" + - " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" + - " } else if (subarr.length > 1) {" + - " if(subarr.slice(1)[0] === 2) {" + - " let niehgbourMessage = grandpaExport.getNeighbourMessage();" + - " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(niehgbourMessage));" + - " }" + - " grandpaExport.handleMessage(Ed25519.b2h(subarr.slice(1)), connection.remotePeer.toString());" + - " }" + " }" + " });" + " });") + " ItPipe.pipe(stream, async function (source) {" + + " for await (const msg of source) {" + + " let subarr = msg.subarray();" + + " if(subarr.length === 1) {" + + " let handshake = grandpaExport.getHandshake();" + + " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" + + " } else if (subarr.length > 1) {" + + " if(subarr.slice(1)[0] === 2) {" + + " let niehgbourMessage = grandpaExport.getNeighbourMessage();" + + " (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(niehgbourMessage));" + + " }" + + " grandpaExport.handleMessage(Ed25519.b2h(subarr.slice(1)), connection.remotePeer.toString());" + + " }" + + " }" + + " });" + + "});" + + "fruzhin.libp.addEventListener('peer:connect', async (evt) => {" + + " let handshake = grandpaExport.getHandshake();" + + " (await ItPbStream.pbStream(await window.fruzhin.libp.dialProtocol(evt.detail, protocolId))).writeLP(Ed25519.h2b(handshake));" + + "});") public static native void registerHandler(JSObject grandpaExport, String protocolId); } diff --git a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaService.java b/src/main/java/com/limechain/network/protocol/grandpa/GrandpaService.java index 72b76d9ee..cdb94b12a 100644 --- a/src/main/java/com/limechain/network/protocol/grandpa/GrandpaService.java +++ b/src/main/java/com/limechain/network/protocol/grandpa/GrandpaService.java @@ -14,27 +14,6 @@ public GrandpaService(String protocolId) { this.protocolId = protocolId; } -// /** -// * Sends a neighbour message to a peer. If there is no initiator stream opened with the peer, -// * sends a handshake instead. -// * -// * @param us our host object -// * @param peerId message receiver -// */ -// public void sendNeighbourMessage(Host us, PeerId peerId) { -// Optional.ofNullable(connectionManager.getPeerInfo(peerId)) -// .map(p -> p.getGrandpaStreams().getInitiator()) -// .ifPresentOrElse( -// this::sendNeighbourMessage, -// () -> sendHandshake(us, peerId) -// ); -// } -// -// private void sendNeighbourMessage(Stream stream) { -// GrandpaController controller = new GrandpaController(stream); -// controller.sendNeighbourMessage(); -// } - private boolean isRegistered = false; public void sendHandshake() { diff --git a/src/main/webapp/js/fruzhin-lib.js b/src/main/webapp/js/fruzhin-lib.js index 96e31de6c..f84915d2d 100644 --- a/src/main/webapp/js/fruzhin-lib.js +++ b/src/main/webapp/js/fruzhin-lib.js @@ -1,16 +1,16 @@ -import 'https://unpkg.com/@chainsafe/libp2p-yamux/dist/index.min.js'; -import 'https://unpkg.com/@chainsafe/libp2p-noise/dist/index.min.js'; -import 'https://unpkg.com/@libp2p/websockets/dist/index.min.js'; -import 'https://unpkg.com/@libp2p/kad-dht/dist/index.min.js'; -import 'https://unpkg.com/@libp2p/identify/dist/index.min.js'; -import 'https://unpkg.com/@libp2p/bootstrap/dist/index.min.js'; -import 'https://unpkg.com/@libp2p/ping/dist/index.min.js'; -import 'https://unpkg.com/@chainsafe/libp2p-gossipsub/dist/index.min.js'; -import 'https://unpkg.com/libp2p/dist/index.min.js'; -import 'https://unpkg.com/it-pipe/dist/index.min.js'; -import 'https://unpkg.com/it-pb-stream/dist/index.min.js'; -import 'https://unpkg.com/@muradsenteca/ed25519/dist/index.min.js' -import 'https://unpkg.com/@muradsenteca/blake2b/dist/index.min.js' +import 'https://unpkg.com/@chainsafe/libp2p-yamux@6.0.2/dist/index.min.js'; +import 'https://unpkg.com/@chainsafe/libp2p-noise@15.1.2/dist/index.min.js'; +import 'https://unpkg.com/@libp2p/websockets@8.2.0/dist/index.min.js'; +import 'https://unpkg.com/@libp2p/kad-dht@12.1.5/dist/index.min.js'; +import 'https://unpkg.com/@libp2p/identify@2.1.5/dist/index.min.js'; +import 'https://unpkg.com/@libp2p/bootstrap@10.1.5/dist/index.min.js'; +import 'https://unpkg.com/@libp2p/ping@1.1.6/dist/index.min.js'; +import 'https://unpkg.com/@chainsafe/libp2p-gossipsub@13.2.0/dist/index.min.js'; +import 'https://unpkg.com/libp2p@1.9.4/dist/index.min.js'; +import 'https://unpkg.com/it-pipe@3.0.1/dist/index.min.js'; +import 'https://unpkg.com/it-pb-stream@4.0.2/dist/index.min.js'; +import 'https://unpkg.com/@muradsenteca/ed25519@1.0.0/dist/index.min.js' +import 'https://unpkg.com/@muradsenteca/blake2b@1.0.1/dist/index.min.js' import * as HTTP from './http.js'; import * as Fruzhin from './fruzhin.js'