Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large p2p http bodies #51

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<dependency>
<groupId>com.github.peergos</groupId>
<artifactId>jvm-libp2p</artifactId>
<version>0.13.0</version>
<version>0.14.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/peergos/protocol/http/HttpProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.netty.channel.nio.*;
import io.netty.channel.socket.nio.*;
import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.logging.*;
import org.jetbrains.annotations.*;

Expand All @@ -17,6 +16,7 @@
import java.util.function.*;

public class HttpProtocol extends ProtocolHandler<HttpProtocol.HttpController> {
private static final int MAX_BODY_SIZE = 2 * 1024 * 1024; // TODO remove this and make it fully streaming

public static class Binding extends StrictProtocolBinding<HttpController> {
public Binding(SocketAddress proxyTarget) {
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void proxyRequest(FullHttpRequest msg,
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new HttpRequestEncoder());
ch.pipeline().addLast(new HttpResponseDecoder());
ch.pipeline().addLast(new HttpObjectAggregator(2*1024*1024));
ch.pipeline().addLast(new HttpObjectAggregator(MAX_BODY_SIZE));
ch.pipeline().addLast(new ResponseWriter(replyHandler));
}
});
Expand Down Expand Up @@ -142,7 +142,7 @@ protected CompletableFuture<HttpController> onStartInitiator(@NotNull Stream str
Sender replyPropagator = new Sender(stream);
stream.pushHandler(new HttpRequestEncoder());
stream.pushHandler(new HttpResponseDecoder());
stream.pushHandler(new HttpObjectAggregator(1024*1024));
stream.pushHandler(new HttpObjectAggregator(MAX_BODY_SIZE));
stream.pushHandler(replyPropagator);
stream.pushHandler(new LoggingHandler(LogLevel.TRACE));
return CompletableFuture.completedFuture(replyPropagator);
Expand All @@ -153,7 +153,7 @@ protected CompletableFuture<HttpController> onStartInitiator(@NotNull Stream str
protected CompletableFuture<HttpController> onStartResponder(@NotNull Stream stream) {
Receiver proxier = new Receiver(handler);
stream.pushHandler(new HttpRequestDecoder());
stream.pushHandler(new HttpObjectAggregator(2*1024*1024));
stream.pushHandler(new HttpObjectAggregator(MAX_BODY_SIZE));
stream.pushHandler(proxier);
stream.pushHandler(new HttpResponseEncoder());
return CompletableFuture.completedFuture(proxier);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/peergos/HttpProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void p2pProxyRequest() throws IOException {
node2.start().join();

// start local server with fixed HTTP response
byte[] httpReply = new byte[577*1024];
byte[] httpReply = new byte[1024*1024];
new Random(42).nextBytes(httpReply);
HttpServer localhostServer = HttpServer.create(proxyTarget, 20);
localhostServer.createContext("/", ex -> {
Expand Down
Loading