Home / File/ QuicCodecDispatcher.java — netty Source File

QuicCodecDispatcher.java — netty Source File

Architecture documentation for QuicCodecDispatcher.java, a java file in the netty codebase.

Entity Profile

Relationship Graph

Source Code

/*
 * Copyright 2024 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.handler.codec.quic;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.internal.ObjectUtil;
import org.jetbrains.annotations.Nullable;

import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;


/**
 * Special {@link io.netty.channel.ChannelHandler} that should be used to init {@link Channel}s that will be used
 * for QUIC while <a href="https://man7.org/linux/man-pages/man7/socket.7.html">SO_REUSEPORT</a> is used to
 * bind to same {@link java.net.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 {@link ChannelHandlerContext}s into the destination connection id. This way once a
 * {@code 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 {@link #decodeIndex(ByteBuf)}
 * and {@link #newIdGenerator(int)}.
 * <p>
 * It is important that the same {@link QuicCodecDispatcher} instance is shared between all the {@link Channel}s that
 * are bound to the same {@link java.net.InetSocketAddress} and use {@code SO_REUSEPORT}.
 * <p>
 * An alternative way to handle this would be to do the "routing" to the correct socket in an {@code epbf} program
 * by implementing your own {@link QuicConnectionIdGenerator} that issue ids that can be understood and handled by the
 * {@code epbf} program to route the packet to the correct socket.
 *
 */
public abstract class QuicCodecDispatcher extends ChannelInboundHandlerAdapter {
    // 20 is the max as per RFC.
    // See https://datatracker.ietf.org/doc/html/rfc9000#section-17.2
    private static final int MAX_LOCAL_CONNECTION_ID_LENGTH = 20;

    // Use a CopyOnWriteArrayList as modifications to the List should only happen during bootstrapping and teardown
    // of the channels.
    private final List<ChannelHandlerContextDispatcher> contextList = new CopyOnWriteArrayList<>();
    private final int localConnectionIdLength;

// ... (266 more lines)

Domain

Subdomains

Frequently Asked Questions

What does QuicCodecDispatcher.java do?
QuicCodecDispatcher.java is a source file in the netty codebase, written in java. It belongs to the Buffer domain, Allocators subdomain.
Where is QuicCodecDispatcher.java in the architecture?
QuicCodecDispatcher.java is located at codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java (domain: Buffer, subdomain: Allocators, directory: codec-classes-quic/src/main/java/io/netty/handler/codec/quic).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free