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:
ChannelHandler,ChannelInboundHandler
public abstract class QuicCodecDispatcher extends ChannelInboundHandlerAdapter
SpecialChannelHandlerthat 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
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(ChannelHandlerContext ctx, java.lang.Object msg)CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelReadComplete(ChannelHandlerContext ctx)CallsChannelHandlerContext.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.voidhandlerAdded(ChannelHandlerContext ctx)Do nothing by default, sub-classes may override this method.voidhandlerRemoved(ChannelHandlerContext ctx)Do 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.booleanisSharable()Returntrueif 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 io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable
-
-
-
-
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()
Description copied from class:ChannelHandlerAdapterReturntrueif the implementation isChannelHandler.Sharableand so can be added to differentChannelPipelines.- Overrides:
isSharablein classChannelHandlerAdapter
-
handlerAdded
public final void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
handlerRemoved
public final void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
java.lang.Exception
-
channelRead
public final void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
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:
java.lang.Exception
-
channelReadComplete
public final void channelReadComplete(ChannelHandlerContext ctx)
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 java.lang.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:
java.lang.Exception- thrown on error.
-
decodeIndex
protected int decodeIndex(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.
-
-