Skip to content

Commit

Permalink
Don't close p2p http stream for writes after sending request
Browse files Browse the repository at this point in the history
This fixes talking to go ipfs instances
  • Loading branch information
ianopolous committed Aug 12, 2023
1 parent 5e2fd65 commit df0f007
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/peergos/protocol/http/HttpProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public CompletableFuture<FullHttpResponse> send(FullHttpRequest req) {
queue.add(res);
FullHttpRequest withTargetHost = setHost(req, stream.remotePeerId());
stream.writeAndFlush(withTargetHost);
stream.closeWrite();
return res;
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/peergos/HttpProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public void p2pProxyRequest() throws IOException {
}

@Test
@Ignore
public void p2pProxyClientTest() throws IOException {
public void p2pProxyClientTest() throws Exception {
InetSocketAddress unusedProxyTarget = new InetSocketAddress("127.0.0.1", 7000);
HostBuilder builder1 = HostBuilder.create(TestPorts.getPort(),
new RamProviderStore(), new RamRecordStore(), new RamBlockstore(), (c, b, p, a) -> CompletableFuture.completedFuture(true))
Expand All @@ -118,7 +117,7 @@ public void p2pProxyClientTest() throws IOException {
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
"/peergos/v0/core/getUsernamesGzip/");
long totalTime = 0;
int count = 200;
int count = 20;
for (int i = 0; i < count; i++) {
HttpProtocol.HttpController proxier = new HttpProtocol.Binding(unusedProxyTarget)
.dial(node1, PeerId.fromBase58(peerId), addrs)
Expand All @@ -135,8 +134,10 @@ public void p2pProxyClientTest() throws IOException {
resp.content().readBytes(bout, resp.headers().getInt("content-length"));
resp.release();

Object reply = JSONParser.parse(new String(bout.toByteArray()));
System.out.println();
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(bout.toByteArray()));

List<String> reply = (List)JSONParser.parse(new String(readFully(gzip)));
Assert.assertTrue(reply.contains("peergos"));
}
System.out.println("Average: " + totalTime / count);
} finally {
Expand Down

0 comments on commit df0f007

Please sign in to comment.