Skip to content

Commit

Permalink
feat: add session throttling to netty implementation by restricting t…
Browse files Browse the repository at this point in the history
…he recieve buffer to the max buffer size
  • Loading branch information
AlexGidman committed Jun 30, 2023
1 parent 878fbc9 commit 6b99cfc
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ public void initChannel(SocketChannel ch) throws Exception {
// which is NioSocketChannel in this case.
.childOption(ChannelOption.SO_KEEPALIVE, true);

// Throttle sessions to prevent clients from sending data too fast
if ( configuration.getMaxBufferSize() > 0 ) {
// SO_RCVBUF = Socket Option - Receive Buffer Size in Bytes
serverBootstrap.childOption(ChannelOption.SO_RCVBUF, configuration.getMaxBufferSize());
Log.debug( "Throttling read buffer for connections to max={} bytes", configuration.getMaxBufferSize() );
}
// Bind to the port and start the server to accept incoming connections.
// You can now call the bind() method as many times as you want (with different bind addresses.)
this.mainChannel = serverBootstrap.bind(
Expand Down Expand Up @@ -216,7 +222,6 @@ public synchronized boolean isIdle() {
@Override
public synchronized void reconfigure(ConnectionConfiguration configuration) {
this.configuration = configuration;

// TODO reconfigure the netty connection
}

Expand Down

0 comments on commit 6b99cfc

Please sign in to comment.