public abstract class QuicCodecDispatcher
extends io.netty.channel.ChannelInboundHandlerAdapter
ChannelHandler
that should be used to init Channel
s that will be used
for QUIC while SO_REUSEPORT is used to
bind to same InetSocketAddress
multiple times. This is necessary to ensure QUIC packets are always
dispatched to the correct codec that keeps the mapping for the connection id.
This implementation use a very simple mapping strategy by encoding the index of the internal datastructure that
keeps track of the different ChannelHandlerContext
s into the destination connection id. This way once a
QUIC
packet is received its possible to forward it to the right codec.
Subclasses might change how encoding / decoding of the index is done by overriding decodeIndex(ByteBuf)
and newIdGenerator(int)
.
It is important that the same QuicCodecDispatcher
instance is shared between all the Channel
s that
are bound to the same InetSocketAddress
and use SO_REUSEPORT
.
An alternative way to handle this would be to do the "routing" to the correct socket in an epbf
program
by implementing your own QuicConnectionIdGenerator
that issue ids that can be understood and handled by the
epbf
program to route the packet to the correct socket.
Modifier | Constructor and Description |
---|---|
protected |
QuicCodecDispatcher()
Create a new instance using the default connection id length.
|
protected |
QuicCodecDispatcher(int localConnectionIdLength)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
java.lang.Object msg) |
void |
channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) |
protected int |
decodeIndex(io.netty.buffer.ByteBuf connectionId)
Return the idx that was encoded into the connectionId via the
QuicConnectionIdGenerator before,
or -1 if decoding was not successful. |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract void |
initChannel(io.netty.channel.Channel channel,
int localConnectionIdLength,
QuicConnectionIdGenerator idGenerator)
Init the
Channel and add all the needed ChannelHandler to the pipeline. |
boolean |
isSharable() |
protected QuicConnectionIdGenerator |
newIdGenerator(int idx)
Returns a
QuicConnectionIdGenerator that will encode the given index into all the
ids that it produces. |
protected QuicCodecDispatcher()
protected QuicCodecDispatcher(int localConnectionIdLength)
localConnectionIdLength
- the local connection id length. This must be between 10 and 20.public final boolean isSharable()
isSharable
in class io.netty.channel.ChannelHandlerAdapter
public final void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
java.lang.Exception
public final void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
java.lang.Exception
public final void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
java.lang.Exception
public final void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
channelReadComplete
in interface io.netty.channel.ChannelInboundHandler
channelReadComplete
in class io.netty.channel.ChannelInboundHandlerAdapter
protected abstract void initChannel(io.netty.channel.Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator) throws java.lang.Exception
Channel
and add all the needed ChannelHandler
to the pipeline.
This also included building the QUIC
codec via QuicCodecBuilder
sub-type using the given local
connection id length and QuicConnectionIdGenerator
.channel
- the Channel
to init.localConnectionIdLength
- the local connection id length that must be used with the
QuicCodecBuilder
.idGenerator
- the QuicConnectionIdGenerator
that must be used with the
QuicCodecBuilder
.java.lang.Exception
- thrown on error.protected int decodeIndex(io.netty.buffer.ByteBuf connectionId)
QuicConnectionIdGenerator
before,
or -1
if decoding was not successful.
Subclasses may override this. In this case newIdGenerator(int)
should be overridden as well
to implement the encoding scheme for the encoding side.
connectionId
- the destination connection id of the QUIC
connection.protected QuicConnectionIdGenerator newIdGenerator(int idx)
QuicConnectionIdGenerator
that will encode the given index into all the
ids that it produces.
Subclasses may override this. In this case decodeIndex(ByteBuf)
should be overridden as well
to implement the encoding scheme for the decoding side.
idx
- the index to encode into each id.QuicConnectionIdGenerator
.Copyright © 2020-2024 The Netty Project. All Rights Reserved.