Home / Class/ ConnectionIdChannelMap Class — netty Architecture

ConnectionIdChannelMap Class — netty Architecture

Architecture documentation for the ConnectionIdChannelMap class in ConnectionIdChannelMap.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  ad87a7c4_a683_c89a_4173_3af4794a9127["ConnectionIdChannelMap"]
  0988f996_25ca_884f_5efb_81b622804353["ConnectionIdChannelMap.java"]
  ad87a7c4_a683_c89a_4173_3af4794a9127 -->|defined in| 0988f996_25ca_884f_5efb_81b622804353
  e8046396_bf0d_1c17_c817_511db98a5205["ConnectionIdChannelMap()"]
  ad87a7c4_a683_c89a_4173_3af4794a9127 -->|method| e8046396_bf0d_1c17_c817_511db98a5205
  5b047e6e_8abe_3167_01c9_c86e9c63f265["ConnectionIdKey()"]
  ad87a7c4_a683_c89a_4173_3af4794a9127 -->|method| 5b047e6e_8abe_3167_01c9_c86e9c63f265
  796805f2_4c1e_a999_7d5d_860da316458e["QuicheQuicChannel()"]
  ad87a7c4_a683_c89a_4173_3af4794a9127 -->|method| 796805f2_4c1e_a999_7d5d_860da316458e
  1d70813a_bb46_5f8e_6786_a5cc4b12b743["clear()"]
  ad87a7c4_a683_c89a_4173_3af4794a9127 -->|method| 1d70813a_bb46_5f8e_6786_a5cc4b12b743

Relationship Graph

Source Code

codec-classes-quic/src/main/java/io/netty/handler/codec/quic/ConnectionIdChannelMap.java lines 31–100

final class ConnectionIdChannelMap {
    private static final SecureRandom random = new SecureRandom();

    private final Map<ConnectionIdKey, QuicheQuicChannel> channelMap = new HashMap<>();
    private final SipHash sipHash;

    ConnectionIdChannelMap() {
        byte[] seed = new byte[SipHash.SEED_LENGTH];
        random.nextBytes(seed);
        // Use SipHash 1-3 for now which is also what rust is using by default.
        sipHash = new SipHash(1, 3, seed);
    }

    private ConnectionIdKey key(ByteBuffer cid) {
        long hash = sipHash.macHash(cid);
        return new ConnectionIdKey(hash, cid);
    }

    @Nullable
    QuicheQuicChannel put(ByteBuffer cid, QuicheQuicChannel channel) {
        return channelMap.put(key(cid), channel);
    }

    @Nullable
    QuicheQuicChannel remove(ByteBuffer cid) {
        return channelMap.remove(key(cid));
    }

    @Nullable
    QuicheQuicChannel get(ByteBuffer cid) {
        return channelMap.get(key(cid));
    }

    void clear() {
        channelMap.clear();
    }

    private static final class ConnectionIdKey implements Comparable<ConnectionIdKey> {
        private final long hash;
        private final ByteBuffer key;

        ConnectionIdKey(long hash, ByteBuffer key) {
            this.hash = hash;
            this.key = key;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            ConnectionIdKey that = (ConnectionIdKey) o;
            return hash == that.hash && Objects.equals(key, that.key);
        }

        @Override
        public int hashCode() {
            return (int) hash;
        }

        @Override
        public int compareTo(@NotNull ConnectionIdChannelMap.ConnectionIdKey o) {
            int result = Long.compare(hash, o.hash);
            return result != 0 ? result : key.compareTo(o.key);
        }
    }
}

Frequently Asked Questions

What is the ConnectionIdChannelMap class?
ConnectionIdChannelMap is a class in the netty codebase, defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/ConnectionIdChannelMap.java.
Where is ConnectionIdChannelMap defined?
ConnectionIdChannelMap is defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/ConnectionIdChannelMap.java at line 31.

Analyze Your Own Codebase

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

Try Supermodel Free