Package io.netty.handler.codec.quic
Class QuicCodecDispatcher
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.quic.QuicCodecDispatcher
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
public abstract class QuicCodecDispatcher extends io.netty.channel.ChannelInboundHandlerAdapterSpecialChannelHandlerthat should be used to initChannels that will be used for QUIC while SO_REUSEPORT is used to bind to sameInetSocketAddressmultiple 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 differentChannelHandlerContexts into the destination connection id. This way once aQUICpacket is received its possible to forward it to the right codec. Subclasses might change how encoding / decoding of the index is done by overridingdecodeIndex(ByteBuf)andnewIdGenerator(int).It is important that the same
QuicCodecDispatcherinstance is shared between all theChannels that are bound to the sameInetSocketAddressand useSO_REUSEPORT.An alternative way to handle this would be to do the "routing" to the correct socket in an
epbfprogram by implementing your ownQuicConnectionIdGeneratorthat issue ids that can be understood and handled by theepbfprogram to route the packet to the correct socket.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedQuicCodecDispatcher()Create a new instance using the default connection id length.protectedQuicCodecDispatcher(int localConnectionIdLength)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)protected intdecodeIndex(io.netty.buffer.ByteBuf connectionId)Return the idx that was encoded into the connectionId via theQuicConnectionIdGeneratorbefore, or-1if decoding was not successful.voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)protected abstract voidinitChannel(io.netty.channel.Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator)Init theChanneland add all the neededChannelHandlerto the pipeline.booleanisSharable()protected QuicConnectionIdGeneratornewIdGenerator(int idx)Returns aQuicConnectionIdGeneratorthat will encode the given index into all the ids that it produces.
-
-
-
Constructor Detail
-
QuicCodecDispatcher
protected QuicCodecDispatcher()
Create a new instance using the default connection id length.
-
QuicCodecDispatcher
protected QuicCodecDispatcher(int localConnectionIdLength)
Create a new instance- Parameters:
localConnectionIdLength- the local connection id length. This must be between 10 and 20.
-
-
Method Detail
-
isSharable
public final boolean isSharable()
- Overrides:
isSharablein classio.netty.channel.ChannelHandlerAdapter
-
handlerAdded
public final void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
public final void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
channelRead
public final void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelReadComplete
public final void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter
-
initChannel
protected abstract void initChannel(io.netty.channel.Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator) throws ExceptionInit theChanneland add all the neededChannelHandlerto the pipeline. This also included building theQUICcodec viaQuicCodecBuildersub-type using the given local connection id length andQuicConnectionIdGenerator.- Parameters:
channel- theChannelto init.localConnectionIdLength- the local connection id length that must be used with theQuicCodecBuilder.idGenerator- theQuicConnectionIdGeneratorthat must be used with theQuicCodecBuilder.- Throws:
Exception- thrown on error.
-
decodeIndex
protected int decodeIndex(io.netty.buffer.ByteBuf connectionId)
Return the idx that was encoded into the connectionId via theQuicConnectionIdGeneratorbefore, or-1if 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.- Parameters:
connectionId- the destination connection id of theQUICconnection.- Returns:
- the index or -1.
-
newIdGenerator
protected QuicConnectionIdGenerator newIdGenerator(int idx)
Returns aQuicConnectionIdGeneratorthat 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.- Parameters:
idx- the index to encode into each id.- Returns:
- the
QuicConnectionIdGenerator.
-
-