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
SpecialChannelHandler
that should be used to initChannel
s that will be used for QUIC while SO_REUSEPORT is used to bind to sameInetSocketAddress
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 differentChannelHandlerContext
s into the destination connection id. This way once aQUIC
packet 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
QuicCodecDispatcher
instance is shared between all theChannel
s that are bound to the sameInetSocketAddress
and useSO_REUSEPORT
.An alternative way to handle this would be to do the "routing" to the correct socket in an
epbf
program by implementing your ownQuicConnectionIdGenerator
that issue ids that can be understood and handled by theepbf
program 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 protected
QuicCodecDispatcher()
Create a new instance using the default connection id length.protected
QuicCodecDispatcher(int localConnectionIdLength)
Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
channelRead(ChannelHandlerContext ctx, java.lang.Object msg)
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
channelReadComplete(ChannelHandlerContext ctx)
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected int
decodeIndex(ByteBuf connectionId)
Return the idx that was encoded into the connectionId via theQuicConnectionIdGenerator
before, or-1
if decoding was not successful.void
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.void
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.protected abstract void
initChannel(Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator)
Init theChannel
and add all the neededChannelHandler
to the pipeline.boolean
isSharable()
Returntrue
if the implementation isChannelHandler.Sharable
and so can be added to differentChannelPipeline
s.protected QuicConnectionIdGenerator
newIdGenerator(int idx)
Returns aQuicConnectionIdGenerator
that 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:ChannelHandlerAdapter
Returntrue
if the implementation isChannelHandler.Sharable
and so can be added to differentChannelPipeline
s.- Overrides:
isSharable
in classChannelHandlerAdapter
-
handlerAdded
public final void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
handlerRemoved
public final void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
channelRead
public final void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelReadComplete
public final void channelReadComplete(ChannelHandlerContext ctx)
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
-
initChannel
protected abstract void initChannel(Channel channel, int localConnectionIdLength, QuicConnectionIdGenerator idGenerator) throws java.lang.Exception
Init theChannel
and add all the neededChannelHandler
to the pipeline. This also included building theQUIC
codec viaQuicCodecBuilder
sub-type using the given local connection id length andQuicConnectionIdGenerator
.- Parameters:
channel
- theChannel
to init.localConnectionIdLength
- the local connection id length that must be used with theQuicCodecBuilder
.idGenerator
- theQuicConnectionIdGenerator
that 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 theQuicConnectionIdGenerator
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 theQUIC
connection.- Returns:
- the index or -1.
-
newIdGenerator
protected QuicConnectionIdGenerator newIdGenerator(int idx)
Returns aQuicConnectionIdGenerator
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.- Parameters:
idx
- the index to encode into each id.- Returns:
- the
QuicConnectionIdGenerator
.
-
-