Class QuicCodecDispatcher

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

    public abstract class QuicCodecDispatcher
    extends io.netty.channel.ChannelInboundHandlerAdapter
    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.

    • 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:
        isSharable in class io.netty.channel.ChannelHandlerAdapter
      • handlerAdded

        public final void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)
                                throws Exception
        Specified by:
        handlerAdded in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerAdded in class io.netty.channel.ChannelHandlerAdapter
        Throws:
        Exception
      • handlerRemoved

        public final void handlerRemoved​(io.netty.channel.ChannelHandlerContext ctx)
                                  throws Exception
        Specified by:
        handlerRemoved in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
        Throws:
        Exception
      • channelRead

        public final void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                      Object msg)
                               throws Exception
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • channelReadComplete

        public final void channelReadComplete​(io.netty.channel.ChannelHandlerContext ctx)
        Specified by:
        channelReadComplete in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapter
      • decodeIndex

        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.

        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 the QUIC connection.
        Returns:
        the index or -1.