From 5918e0fae362412fcfa5303c7cd7987ebe4ddc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9Cur=D0=B0d=20H=D0=B0mz=D0=B0?= Date: Wed, 28 Aug 2024 12:12:53 +0300 Subject: [PATCH] chore: remove stream object --- .../network/StrictProtocolBinding.java | 36 ------------------- .../network/protocol/warp/WarpSync.java | 11 +----- .../com/limechain/network/wrapper/Stream.java | 29 --------------- 3 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 src/main/java/com/limechain/network/wrapper/Stream.java diff --git a/src/main/java/com/limechain/network/StrictProtocolBinding.java b/src/main/java/com/limechain/network/StrictProtocolBinding.java index 9e7675b84..426ff72ab 100644 --- a/src/main/java/com/limechain/network/StrictProtocolBinding.java +++ b/src/main/java/com/limechain/network/StrictProtocolBinding.java @@ -1,11 +1,5 @@ package com.limechain.network; -import com.limechain.network.wrapper.Stream; -import org.teavm.jso.JSBody; -import org.teavm.jso.core.JSPromise; - -import java.util.concurrent.atomic.AtomicReference; - public abstract class StrictProtocolBinding { String protocolId; @@ -13,34 +7,4 @@ protected StrictProtocolBinding(String protocolId/*, T protocol*/) { this.protocolId = protocolId; } - public Stream dialPeer(/*PeerId peer*/) { - Object peer1 = getPeer(); - JSPromise dial = dial(peer1, protocolId); - final var lock = new Object(); - AtomicReference stream = new AtomicReference<>(); - - dial.then((result) -> { - stream.set((Stream) result); - synchronized (lock) { - lock.notify(); - } - return null; - }); - - synchronized (lock) { - try { - lock.wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - return stream.get(); - } - - @JSBody(params = {"peerId", "protocolId"}, script = "return (async () => ItPbStream.pbStream(await libp.dialProtocol(peerId, protocolId)))()") - private static native JSPromise dial(Object peerId, String protocolId); - - @JSBody(script = "return libp.getConnections()[0].remotePeer;") - private static native Object getPeer(); } diff --git a/src/main/java/com/limechain/network/protocol/warp/WarpSync.java b/src/main/java/com/limechain/network/protocol/warp/WarpSync.java index 71940361a..b33b363ad 100644 --- a/src/main/java/com/limechain/network/protocol/warp/WarpSync.java +++ b/src/main/java/com/limechain/network/protocol/warp/WarpSync.java @@ -1,24 +1,15 @@ package com.limechain.network.protocol.warp; -import com.limechain.exception.global.ExecutionFailedException; -import com.limechain.exception.global.ThreadInterruptedException; import com.limechain.network.StrictProtocolBinding; -import com.limechain.network.kad.dto.Host; -import com.limechain.network.kad.dto.PeerId; -import com.limechain.network.protocol.warp.dto.WarpSyncRequest; import com.limechain.network.protocol.warp.dto.WarpSyncResponse; -import com.limechain.network.wrapper.Stream; import lombok.extern.java.Log; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import java.util.logging.Level; @Log public class WarpSync extends StrictProtocolBinding { - private String protocolId; + private final String protocolId; public WarpSync(String protocolId) { super(protocolId); diff --git a/src/main/java/com/limechain/network/wrapper/Stream.java b/src/main/java/com/limechain/network/wrapper/Stream.java deleted file mode 100644 index 590049edd..000000000 --- a/src/main/java/com/limechain/network/wrapper/Stream.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.limechain.network.wrapper; - -import org.teavm.jso.JSObject; - -public class Stream implements JSObject { - public void write() { - - } - - public void writeLP(byte[] data) { - - } - - public void writePB() { - - } - - public void read() { - - } - - public Object readLP() { - return null; - } - - public void readPB() { - - } -}