Skip to content

Commit

Permalink
Relay Stop protocol working correctly!
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Sep 19, 2023
1 parent 6d04428 commit 665f944
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public void onMessage(@NotNull Stream stream, Circuit.HopMessage msg) {
.orTimeout(15, TimeUnit.SECONDS).join();
Circuit.StopMessage reply = stop.connect(initiator, resv.durationSeconds, resv.maxBytes).join();
if (reply.getStatus().equals(Circuit.Status.OK)) {
stream.writeAndFlush(Circuit.StopMessage.newBuilder()
.setType(Circuit.StopMessage.Type.STATUS)
stream.writeAndFlush(Circuit.HopMessage.newBuilder()
.setType(Circuit.HopMessage.Type.STATUS)
.setStatus(Circuit.Status.OK));
Stream toTarget = stop.getStream();
Stream fromRequestor = stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public CompletableFuture<Circuit.StopMessage> rpc(Circuit.StopMessage msg) {
private static final int TRAFFIC_LIMIT = 2*1024;

public CircuitStopProtocol() {
super(Circuit.HopMessage.getDefaultInstance(), TRAFFIC_LIMIT, TRAFFIC_LIMIT);
super(Circuit.StopMessage.getDefaultInstance(), TRAFFIC_LIMIT, TRAFFIC_LIMIT);
}

@NotNull
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/org/peergos/RelayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,36 @@ public void remoteRelay() {
public void localRelay() {
HostBuilder builder1 = HostBuilder.create(10000 + new Random().nextInt(50000),
new RamProviderStore(), new RamRecordStore(), new RamBlockstore(), (c, b, p, a) -> CompletableFuture.completedFuture(true));
Host node1 = builder1.build();
node1.start().join();
IdentifyBuilder.addIdentifyProtocol(node1);
Host sender = builder1.build();
sender.start().join();
IdentifyBuilder.addIdentifyProtocol(sender);

HostBuilder builder2 = HostBuilder.create(10000 + new Random().nextInt(50000),
new RamProviderStore(), new RamRecordStore(), new RamBlockstore(), (c, b, p, a) -> CompletableFuture.completedFuture(true));
Host node2 = builder2.build();
node2.start().join();
IdentifyBuilder.addIdentifyProtocol(node2);
Host receiver = builder2.build();
receiver.start().join();
IdentifyBuilder.addIdentifyProtocol(receiver);

HostBuilder builder3 = HostBuilder.create(10000 + new Random().nextInt(50000),
HostBuilder relayBuilder = HostBuilder.create(10000 + new Random().nextInt(50000),
new RamProviderStore(), new RamRecordStore(), new RamBlockstore(), (c, b, p, a) -> CompletableFuture.completedFuture(true));
Host relay = builder3.build();
Host relay = relayBuilder.build();
relay.start().join();
IdentifyBuilder.addIdentifyProtocol(relay);

try {
// set up node 2 to listen via a relay
Multiaddr relayAddr = relay.listenAddresses().get(0).withP2P(relay.getPeerId());
CircuitHopProtocol.HopController hop = builder2.getRelayHop().get().dial(node2, relayAddr).getController().join();
CircuitHopProtocol.HopController hop = builder2.getRelayHop().get().dial(receiver, relayAddr).getController().join();
CircuitHopProtocol.Reservation reservation = hop.reserve().join();

// connect to node2 from node1 via a relay
System.out.println("Using relay " + relay.getPeerId());
CircuitHopProtocol.HopController node1Hop = builder1.getRelayHop().get().dial(node1, relayAddr).getController().join();
Stream stream = node1Hop.connect(Multihash.deserialize(node2.getPeerId().getBytes())).join();
CircuitHopProtocol.HopController node1Hop = builder1.getRelayHop().get().dial(sender, relayAddr).getController().join();
Stream stream = node1Hop.connect(Multihash.deserialize(receiver.getPeerId().getBytes())).join();
System.out.println();
} finally {
node1.stop();
node2.stop();
sender.stop();
receiver.stop();
relay.stop();
}
}
Expand Down

0 comments on commit 665f944

Please sign in to comment.