Home / Class/ SslHandler Class — netty Architecture

SslHandler Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1["SslHandler"]
  cdb86368_ae5f_5721_2e99_c3d0ec92017f["SslHandler.java"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|defined in| cdb86368_ae5f_5721_2e99_c3d0ec92017f
  0f16674e_fb65_d1b4_d514_edf65e741c7d["SslHandler()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 0f16674e_fb65_d1b4_d514_edf65e741c7d
  9629030e_34fb_0cbe_1325_d893039cd21b["getHandshakeTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 9629030e_34fb_0cbe_1325_d893039cd21b
  e528d34d_8093_1a11_6860_cd8154162e69["setHandshakeTimeout()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| e528d34d_8093_1a11_6860_cd8154162e69
  1424a095_14a4_697c_4106_19b1d16d97a9["setHandshakeTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 1424a095_14a4_697c_4106_19b1d16d97a9
  783b63cb_1b3c_d668_4e0f_f4c1f0878ddd["setWrapDataSize()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 783b63cb_1b3c_d668_4e0f_f4c1f0878ddd
  42628971_8172_841b_1df4_2986bb9bf163["getCloseNotifyTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 42628971_8172_841b_1df4_2986bb9bf163
  0d6f9aae_e1c6_7be7_06d0_b70b412938d5["setCloseNotifyTimeout()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 0d6f9aae_e1c6_7be7_06d0_b70b412938d5
  b547ec62_f614_04c6_fc70_3a7629141852["setCloseNotifyTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| b547ec62_f614_04c6_fc70_3a7629141852
  e8431ff5_af11_8e5f_3b58_bc6eca8dd3a5["getCloseNotifyFlushTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| e8431ff5_af11_8e5f_3b58_bc6eca8dd3a5
  dfa74868_7b0c_3d6b_56c1_b015716da362["setCloseNotifyFlushTimeout()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| dfa74868_7b0c_3d6b_56c1_b015716da362
  2578b5ce_0698_280f_4629_cdcc54eed719["setCloseNotifyFlushTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 2578b5ce_0698_280f_4629_cdcc54eed719
  c5c48a32_bd21_0c7f_9abc_a57d55790e44["getCloseNotifyReadTimeoutMillis()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| c5c48a32_bd21_0c7f_9abc_a57d55790e44
  71ddaa1a_27bc_1a58_a5fe_6244448a4f62["setCloseNotifyReadTimeout()"]
  d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 -->|method| 71ddaa1a_27bc_1a58_a5fe_6244448a4f62

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/SslHandler.java lines 168–2475

public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler {
    private static final InternalLogger logger =
            InternalLoggerFactory.getInstance(SslHandler.class);
    private static final Pattern IGNORABLE_ERROR_MESSAGE = Pattern.compile(
            "^.*(?:connection.*(?:reset|closed|abort|broken)|broken.*pipe).*$", Pattern.CASE_INSENSITIVE);
    private static final int STATE_SENT_FIRST_MESSAGE = 1;
    private static final int STATE_FLUSHED_BEFORE_HANDSHAKE = 1 << 1;
    private static final int STATE_READ_DURING_HANDSHAKE = 1 << 2;
    private static final int STATE_HANDSHAKE_STARTED = 1 << 3;
    /**
     * Set by wrap*() methods when something is produced.
     * {@link #channelReadComplete(ChannelHandlerContext)} will check this flag, clear it, and call ctx.flush().
     */
    private static final int STATE_NEEDS_FLUSH = 1 << 4;
    private static final int STATE_OUTBOUND_CLOSED = 1 << 5;
    private static final int STATE_CLOSE_NOTIFY = 1 << 6;
    private static final int STATE_PROCESS_TASK = 1 << 7;
    /**
     * This flag is used to determine if we need to call {@link ChannelHandlerContext#read()} to consume more data
     * when {@link ChannelConfig#isAutoRead()} is {@code false}.
     */
    private static final int STATE_FIRE_CHANNEL_READ = 1 << 8;
    private static final int STATE_UNWRAP_REENTRY = 1 << 9;

    /**
     * <a href="https://tools.ietf.org/html/rfc5246#section-6.2">2^14</a> which is the maximum sized plaintext chunk
     * allowed by the TLS RFC.
     */
    private static final int MAX_PLAINTEXT_LENGTH = 16 * 1024;

    private enum SslEngineType {
        TCNATIVE(true, COMPOSITE_CUMULATOR) {
            @Override
            SSLEngineResult unwrap(SslHandler handler, ByteBuf in, int len, ByteBuf out) throws SSLException {
                int nioBufferCount = in.nioBufferCount();
                int writerIndex = out.writerIndex();
                final SSLEngineResult result;
                if (nioBufferCount > 1) {
                    /*
                     * If {@link OpenSslEngine} is in use,
                     * we can use a special {@link OpenSslEngine#unwrap(ByteBuffer[], ByteBuffer[])} method
                     * that accepts multiple {@link ByteBuffer}s without additional memory copies.
                     */
                    ReferenceCountedOpenSslEngine opensslEngine = (ReferenceCountedOpenSslEngine) handler.engine;
                    try {
                        handler.singleBuffer[0] = toByteBuffer(out, writerIndex, out.writableBytes());
                        result = opensslEngine.unwrap(in.nioBuffers(in.readerIndex(), len), handler.singleBuffer);
                    } finally {
                        handler.singleBuffer[0] = null;
                    }
                } else {
                    result = handler.engine.unwrap(toByteBuffer(in, in.readerIndex(), len),
                        toByteBuffer(out, writerIndex, out.writableBytes()));
                }
                out.writerIndex(writerIndex + result.bytesProduced());
                return result;
            }

            @Override
            ByteBuf allocateWrapBuffer(SslHandler handler, ByteBufAllocator allocator,
                                       int pendingBytes, int numComponents) {
                return allocator.directBuffer(((ReferenceCountedOpenSslEngine) handler.engine)
                        .calculateOutNetBufSize(pendingBytes, numComponents));
            }

            @Override
            int calculateRequiredOutBufSpace(SslHandler handler, int pendingBytes, int numComponents) {
                return ((ReferenceCountedOpenSslEngine) handler.engine)
                        .calculateMaxLengthForWrap(pendingBytes, numComponents);
            }

            @Override
            int calculatePendingData(SslHandler handler, int guess) {
                int sslPending = ((ReferenceCountedOpenSslEngine) handler.engine).sslPending();
                return sslPending > 0 ? sslPending : guess;
            }

            @Override
            boolean jdkCompatibilityMode(SSLEngine engine) {
                return ((ReferenceCountedOpenSslEngine) engine).jdkCompatibilityMode;
            }

Frequently Asked Questions

What is the SslHandler class?
SslHandler is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java.
Where is SslHandler defined?
SslHandler is defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java at line 168.

Analyze Your Own Codebase

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

Try Supermodel Free