Skip to content

Commit

Permalink
chore: remove stream object
Browse files Browse the repository at this point in the history
  • Loading branch information
ablax committed Aug 28, 2024
1 parent 9203a78 commit 5918e0f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 75 deletions.
36 changes: 0 additions & 36 deletions src/main/java/com/limechain/network/StrictProtocolBinding.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
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;

protected StrictProtocolBinding(String protocolId/*, T protocol*/) {
this.protocolId = protocolId;
}

public Stream dialPeer(/*PeerId peer*/) {
Object peer1 = getPeer();
JSPromise<Object> dial = dial(peer1, protocolId);
final var lock = new Object();
AtomicReference<Stream> 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<Object> dial(Object peerId, String protocolId);

@JSBody(script = "return libp.getConnections()[0].remotePeer;")
private static native Object getPeer();
}
11 changes: 1 addition & 10 deletions src/main/java/com/limechain/network/protocol/warp/WarpSync.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/com/limechain/network/wrapper/Stream.java

This file was deleted.

0 comments on commit 5918e0f

Please sign in to comment.