Class: QuietQUIC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/quietquic/server.rb

Overview

A running cloaked QUIC server.

Build one with Server.bind (from a listen address + a {client_id => psk} map) or Server.bind_toml (from a secrets file). Both parse and validate the config synchronously (raising ConfigError on a bad address or PSK), then await the native bind on the shared runtime.

#accept yields the next authenticated Connection; it blocks (parking the fiber under an Async reactor) until a peer completes the cloaked handshake.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ Server

Returns a new instance of Server.

Parameters:

  • native (Native::Server)

    the wrapped crate server.



38
39
40
# File 'lib/quietquic/server.rb', line 38

def initialize(native)
  @native = native
end

Class Method Details

.bind(listen:, clients:) ⇒ Server

Bind a server from a listen address and an authorized-clients map.

Parameters:

  • listen (String)

    the "ip:port" to bind (use port 0 for an ephemeral port, then read #local_address).

  • clients (Hash{String=>String})

    client_id => psk_hex (64 hex chars).

Returns:

Raises:

  • (QuietQUIC::ConfigError)

    on a bad address or PSK.

  • (QuietQUIC::ConnectError)

    if the socket cannot be bound.



21
22
23
24
# File 'lib/quietquic/server.rb', line 21

def self.bind(listen:, clients:)
  handle = Native.server_config_from_hash(listen, clients)
  new(QuietQUIC.await(Native::Server.bind(handle)))
end

.bind_toml(path) ⇒ Server

Bind a server from a TOML secrets file.

Parameters:

  • path (String)

    path to the server secrets TOML.

Returns:

Raises:

  • (QuietQUIC::ConfigError)

    if the file is missing or invalid.

  • (QuietQUIC::ConnectError)

    if the socket cannot be bound.



32
33
34
35
# File 'lib/quietquic/server.rb', line 32

def self.bind_toml(path)
  handle = Native.server_config_from_toml(path)
  new(QuietQUIC.await(Native::Server.bind(handle)))
end

Instance Method Details

#acceptConnection

Await and return the next authenticated Connection.

Blocks until a peer completes the cloaked handshake. Under an Async reactor it parks the fiber; otherwise it blocks with the GVL released.

Returns:

Raises:

  • (QuietQUIC::ConnectionLost)

    if the server has been closed or its driver has shut down.



50
51
52
# File 'lib/quietquic/server.rb', line 50

def accept
  Connection.new(QuietQUIC.await(@native.accept_op))
end

#closevoid

This method returns an undefined value.

Stop the server: drop the crate server, halting its driver and releasing the socket. Idempotent.



66
67
68
# File 'lib/quietquic/server.rb', line 66

def close
  @native.close
end

#local_addressString

The address the server is actually listening on (e.g. "127.0.0.1:54321"). After binding to port 0 this reports the kernel-chosen port.

Returns:

  • (String)


58
59
60
# File 'lib/quietquic/server.rb', line 58

def local_address
  @native.local_address
end