Class QuicCodecDispatcher
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.quic.QuicCodecDispatcher
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
Special
ChannelHandler that should be used to init Channels 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 ChannelHandlerContexts 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 Channels 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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new instance using the default connection id length.protectedQuicCodecDispatcher(int localConnectionIdLength) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionfinal voidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.final voidCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected intdecodeIndex(ByteBuf connectionId) Return the idx that was encoded into the connectionId via theQuicConnectionIdGeneratorbefore, or-1if decoding was not successful.final voidDo nothing by default, sub-classes may override this method.final voidDo nothing by default, sub-classes may override this method.protected abstract voidinitChannel(Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator) Init theChanneland add all the neededChannelHandlerto the pipeline.final booleanReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.protected QuicConnectionIdGeneratornewIdGenerator(int idx) Returns aQuicConnectionIdGeneratorthat will encode the given index into all the ids that it produces.Methods inherited from class ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable
-
Constructor Details
-
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 Details
-
isSharable
public final boolean isSharable()Description copied from class:ChannelHandlerAdapterReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.- Overrides:
isSharablein classChannelHandlerAdapter
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
Exception
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadCompletein interfaceChannelInboundHandler- Overrides:
channelReadCompletein classChannelInboundHandlerAdapter
-
initChannel
protected abstract void initChannel(Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator) throws Exception Init 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
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
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.
-