Class: Quicsilver::Transport::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/quicsilver/transport/configuration.rb

Constant Summary collapse

QUIC_SERVER_RESUME_AND_ZERORTT =
1
QUIC_SERVER_RESUME_ONLY =
2
QUIC_SERVER_RESUME_AND_REUSE =
3
QUIC_SERVER_RESUME_AND_REUSE_ZERORTT =
4
CONGESTION_CONTROL_CUBIC =

Congestion control algorithms

0
CONGESTION_CONTROL_BBR =
1
DEFAULT_CERT_FILE =
"certificates/server.crt"
DEFAULT_KEY_FILE =
"certificates/server.key"
DEFAULT_ALPN =
"h3"
DEFAULT_STREAM_RECEIVE_WINDOW =

Flow control defaults — cross-referenced with quiche, quic-go, lsquic, RFC 9000 See: github.com/microsoft/msquic/blob/main/docs/Settings.md

262_144
DEFAULT_STREAM_RECEIVE_BUFFER =

256KB (quiche/quic-go use 1MB, MsQuic default 64KB)

32_768
DEFAULT_CONNECTION_FLOW_CONTROL_WINDOW =

32KB (MsQuic default 4KB — too small for typical responses)

16_777_216
DEFAULT_PACING_ENABLED =

Throughput defaults

true
DEFAULT_SEND_BUFFERING_ENABLED =

RFC 9002: MUST pace or limit bursts

true
DEFAULT_INITIAL_RTT_MS =

MsQuic recommended — coalesces small writes

100
DEFAULT_INITIAL_WINDOW_PACKETS =

MsQuic default 333ms is satellite-grade; 100ms matches Chromium

10
DEFAULT_MAX_ACK_DELAY_MS =

Matches RFC 9002 recommendation

25
DEFAULT_KEEP_ALIVE_INTERVAL_MS =

Connection management defaults

0
DEFAULT_CONGESTION_CONTROL_ALGORITHM =

0 = disabled. Set to 20000 for NAT traversal

CONGESTION_CONTROL_CUBIC
DEFAULT_MIGRATION_ENABLED =

CUBIC (0) or BBR (1)

true
DEFAULT_DISCONNECT_TIMEOUT_MS =

Client IP migration. Disable behind load balancers

16_000
DEFAULT_HANDSHAKE_IDLE_TIMEOUT_MS =

How long to wait for ACK before path declared dead

10_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert_file = nil, key_file = nil, options = {}) ⇒ Configuration

Handshake timeout (separate from connection idle)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/quicsilver/transport/configuration.rb', line 48

def initialize(cert_file = nil, key_file = nil, options = {})
  @idle_timeout_ms = options.fetch(:idle_timeout_ms, 10000)
  @server_resumption_level = options.fetch(:server_resumption_level, QUIC_SERVER_RESUME_AND_ZERORTT)
  @max_concurrent_requests = options.fetch(:max_concurrent_requests, 100)
  @max_unidirectional_streams = options.fetch(:max_unidirectional_streams, 10)
  @alpn = options.fetch(:alpn, DEFAULT_ALPN)

  # Flow control
  @stream_receive_window = options.fetch(:stream_receive_window, DEFAULT_STREAM_RECEIVE_WINDOW)
  @stream_receive_buffer = options.fetch(:stream_receive_buffer, DEFAULT_STREAM_RECEIVE_BUFFER)
  @connection_flow_control_window = options.fetch(:connection_flow_control_window, DEFAULT_CONNECTION_FLOW_CONTROL_WINDOW)

  # Throughput
  @pacing_enabled = options.fetch(:pacing_enabled, DEFAULT_PACING_ENABLED)
  @send_buffering_enabled = options.fetch(:send_buffering_enabled, DEFAULT_SEND_BUFFERING_ENABLED)
  @initial_rtt_ms = options.fetch(:initial_rtt_ms, DEFAULT_INITIAL_RTT_MS)
  @initial_window_packets = options.fetch(:initial_window_packets, DEFAULT_INITIAL_WINDOW_PACKETS)
  @max_ack_delay_ms = options.fetch(:max_ack_delay_ms, DEFAULT_MAX_ACK_DELAY_MS)

  # Connection management
  @keep_alive_interval_ms = options.fetch(:keep_alive_interval_ms, DEFAULT_KEEP_ALIVE_INTERVAL_MS)
  @congestion_control_algorithm = options.fetch(:congestion_control_algorithm, DEFAULT_CONGESTION_CONTROL_ALGORITHM)
  @migration_enabled = options.fetch(:migration_enabled, DEFAULT_MIGRATION_ENABLED)
  @disconnect_timeout_ms = options.fetch(:disconnect_timeout_ms, DEFAULT_DISCONNECT_TIMEOUT_MS)
  @handshake_idle_timeout_ms = options.fetch(:handshake_idle_timeout_ms, DEFAULT_HANDSHAKE_IDLE_TIMEOUT_MS)

  # HTTP/3 parser limits (nil = unlimited)
  @max_body_size = options[:max_body_size]
  @max_header_size = options[:max_header_size]
  @max_header_count = options[:max_header_count]
  @max_frame_payload_size = options[:max_frame_payload_size]

  # 0-RTT early data policy (RFC 8470)
  # :reject (default) — send 425 Too Early for unsafe methods on 0-RTT
  # :allow — pass all 0-RTT requests to the Rack app with env["quicsilver.early_data"]
  @early_data_policy = options.fetch(:early_data_policy, :reject)
  unless %i[reject allow].include?(@early_data_policy)
    raise ServerConfigurationError, "Invalid early_data_policy: #{@early_data_policy.inspect} (must be :reject or :allow)"
  end

  # Application interface mode:
  # :rack (default) — app is a Rack app, auto-wrapped with Protocol::Rack::Adapter
  # :falcon — app is a native protocol-http app, used directly
  @mode = options.fetch(:mode, :rack)
  unless %i[rack falcon].include?(@mode)
    raise ServerConfigurationError, "Invalid mode: #{@mode.inspect} (must be :rack or :falcon)"
  end

  @cert_file = cert_file.nil? ? DEFAULT_CERT_FILE : cert_file
  @key_file = key_file.nil? ? DEFAULT_KEY_FILE : key_file

  unless File.exist?(@cert_file)
    raise ServerConfigurationError, "Certificate file not found: #{@cert_file}"
  end

  unless File.exist?(@key_file)
    raise ServerConfigurationError, "Key file not found: #{@key_file}"
  end
end

Instance Attribute Details

#cert_fileObject (readonly)

Returns the value of attribute cert_file.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def cert_file
  @cert_file
end

#congestion_control_algorithmObject (readonly)

Returns the value of attribute congestion_control_algorithm.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def congestion_control_algorithm
  @congestion_control_algorithm
end

#connection_flow_control_windowObject (readonly)

Returns the value of attribute connection_flow_control_window.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def connection_flow_control_window
  @connection_flow_control_window
end

#disconnect_timeout_msObject (readonly)

Returns the value of attribute disconnect_timeout_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def disconnect_timeout_ms
  @disconnect_timeout_ms
end

#early_data_policyObject (readonly)

Returns the value of attribute early_data_policy.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def early_data_policy
  @early_data_policy
end

#handshake_idle_timeout_msObject (readonly)

Returns the value of attribute handshake_idle_timeout_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def handshake_idle_timeout_ms
  @handshake_idle_timeout_ms
end

#idle_timeout_msObject (readonly)

Returns the value of attribute idle_timeout_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def idle_timeout_ms
  @idle_timeout_ms
end

#initial_rtt_msObject (readonly)

Returns the value of attribute initial_rtt_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def initial_rtt_ms
  @initial_rtt_ms
end

#initial_window_packetsObject (readonly)

Returns the value of attribute initial_window_packets.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def initial_window_packets
  @initial_window_packets
end

#keep_alive_interval_msObject (readonly)

Returns the value of attribute keep_alive_interval_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def keep_alive_interval_ms
  @keep_alive_interval_ms
end

#key_fileObject (readonly)

Returns the value of attribute key_file.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def key_file
  @key_file
end

#max_ack_delay_msObject (readonly)

Returns the value of attribute max_ack_delay_ms.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_ack_delay_ms
  @max_ack_delay_ms
end

#max_body_sizeObject (readonly)

Returns the value of attribute max_body_size.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_body_size
  @max_body_size
end

#max_concurrent_requestsObject (readonly)

Returns the value of attribute max_concurrent_requests.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_concurrent_requests
  @max_concurrent_requests
end

#max_frame_payload_sizeObject (readonly)

Returns the value of attribute max_frame_payload_size.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_frame_payload_size
  @max_frame_payload_size
end

#max_header_countObject (readonly)

Returns the value of attribute max_header_count.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_header_count
  @max_header_count
end

#max_header_sizeObject (readonly)

Returns the value of attribute max_header_size.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_header_size
  @max_header_size
end

#max_unidirectional_streamsObject (readonly)

Returns the value of attribute max_unidirectional_streams.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def max_unidirectional_streams
  @max_unidirectional_streams
end

#migration_enabledObject (readonly)

Returns the value of attribute migration_enabled.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def migration_enabled
  @migration_enabled
end

#modeObject (readonly)

Returns the value of attribute mode.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def mode
  @mode
end

#pacing_enabledObject (readonly)

Returns the value of attribute pacing_enabled.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def pacing_enabled
  @pacing_enabled
end

#send_buffering_enabledObject (readonly)

Returns the value of attribute send_buffering_enabled.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def send_buffering_enabled
  @send_buffering_enabled
end

#server_resumption_levelObject (readonly)

Returns the value of attribute server_resumption_level.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def server_resumption_level
  @server_resumption_level
end

#stream_receive_bufferObject (readonly)

Returns the value of attribute stream_receive_buffer.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def stream_receive_buffer
  @stream_receive_buffer
end

#stream_receive_windowObject (readonly)

Returns the value of attribute stream_receive_window.



6
7
8
# File 'lib/quicsilver/transport/configuration.rb', line 6

def stream_receive_window
  @stream_receive_window
end

Instance Method Details

#alpnObject

Common HTTP/3 ALPN Values: “h3” - HTTP/3 (most common) “h3-29” - HTTP/3 draft version 29



111
112
113
# File 'lib/quicsilver/transport/configuration.rb', line 111

def alpn
  @alpn
end

#to_hObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/quicsilver/transport/configuration.rb', line 115

def to_h
  {
    cert_file: @cert_file,
    key_file: @key_file,
    idle_timeout_ms: @idle_timeout_ms,
    server_resumption_level: @server_resumption_level,
    max_concurrent_requests: @max_concurrent_requests,
    max_unidirectional_streams: @max_unidirectional_streams,
    alpn: alpn,
    stream_receive_window: @stream_receive_window,
    stream_receive_buffer: @stream_receive_buffer,
    connection_flow_control_window: @connection_flow_control_window,
    pacing_enabled: @pacing_enabled ? 1 : 0,
    send_buffering_enabled: @send_buffering_enabled ? 1 : 0,
    initial_rtt_ms: @initial_rtt_ms,
    initial_window_packets: @initial_window_packets,
    max_ack_delay_ms: @max_ack_delay_ms,
    keep_alive_interval_ms: @keep_alive_interval_ms,
    congestion_control_algorithm: @congestion_control_algorithm,
    migration_enabled: @migration_enabled ? 1 : 0,
    disconnect_timeout_ms: @disconnect_timeout_ms,
    handshake_idle_timeout_ms: @handshake_idle_timeout_ms
  }
end