Class QuicServer

java.lang.Object
reactor.netty.transport.Transport<T,CONF>
reactor.netty.quic.QuicServer

public abstract class QuicServer extends Transport<T,CONF>
A QuicServer allows building in a safe immutable way a QUIC server that is materialized and bound when bind() is ultimately called.

Example:

 
     QuicServer.create()
               .tokenHandler(InsecureQuicTokenHandler.INSTANCE)
               .port(7777)
               .wiretap(true)
               .secure(serverCtx)
               .idleTimeout(Duration.ofSeconds(5))
               .initialSettings(spec ->
                   spec.maxData(10000000)
                       .maxStreamDataBidirectionalLocal(1000000)
                       .maxStreamDataBidirectionalRemote(1000000)
                       .maxStreamsBidirectional(100)
                       .maxStreamsUnidirectional(100))
               .bindNow();
 
 
Author:
Violeta Georgieva
  • Constructor Details

    • QuicServer

      public QuicServer()
  • Method Details

    • create

      public static QuicServer create()
      Prepare a QuicServer.
      Returns:
      a QuicServer
    • bind

      public abstract Mono<? extends Connection> bind()
      Binds the QuicServer and returns a Mono of Connection. If Mono is cancelled, the underlying binding will be aborted. Once the Connection has been emitted and is not necessary anymore, disposing the main server loop must be done by the user via DisposableChannel.dispose().
      Returns:
      a Mono of Connection
    • bindNow

      public final Connection bindNow()
      Starts the server in a blocking fashion, and waits for it to finish initializing or the startup timeout expires (the startup timeout is 45 seconds). The returned Connection offers simple server API, including to DisposableChannel.disposeNow() shut it down in a blocking fashion.
      Returns:
      a Connection
    • bindNow

      public final Connection bindNow(Duration timeout)
      Start the server in a blocking fashion, and wait for it to finish initializing or the provided startup timeout expires. The returned Connection offers simple server API, including to DisposableChannel.disposeNow() shut it down in a blocking fashion.
      Parameters:
      timeout - max startup timeout (resolution: ns)
      Returns:
      a Connection
    • connectionIdAddressGenerator

      public final QuicServer connectionIdAddressGenerator(QuicConnectionIdGenerator connectionIdAddressGenerator)
      Parameters:
      connectionIdAddressGenerator - the QuicConnectionIdGenerator to use.
      Returns:
      a QuicServer reference
    • doOnConnection

      public final QuicServer doOnConnection(Consumer<? super QuicConnection> doOnConnection)
      Set or add a callback called on new remote QuicConnection.
      Parameters:
      doOnConnection - a consumer observing remote QUIC connections
      Returns:
      a QuicServer reference
    • host

      public final QuicServer host(String host)
      The host to which this server should bind.
      Parameters:
      host - the host to bind to.
      Returns:
      a QuicServer reference
    • port

      public final QuicServer port(int port)
      The port to which this server should bind. If a port is not specified, the system picks up an ephemeral port.
      Parameters:
      port - The port to bind to.
      Returns:
      a QuicServer reference
    • tokenHandler

      public final QuicServer tokenHandler(QuicTokenHandler tokenHandler)
      Configure the QuicTokenHandler that is used to generate and validate tokens.
      Parameters:
      tokenHandler - the QuicTokenHandler to use
      Returns:
      a QuicServer
    • ackDelayExponent

      public final QuicServer ackDelayExponent(long ackDelayExponent)
      Set the delay exponent used for ACKs. See set_ack_delay_exponent. Default to 3.
      Parameters:
      ackDelayExponent - the delay exponent used for ACKs.
      Returns:
      a QuicTransport reference
    • activeMigration

      public final QuicServer activeMigration(boolean enable)
      Enable/disable active migration. See set_disable_active_migration. Default to true.
      Parameters:
      enable - true if migration should be enabled, false otherwise
      Returns:
      a QuicTransport reference
    • congestionControlAlgorithm

      public final QuicServer congestionControlAlgorithm(QuicCongestionControlAlgorithm congestionControlAlgorithm)
      Set the congestion control algorithm to use. Default to QuicCongestionControlAlgorithm.CUBIC.
      Parameters:
      congestionControlAlgorithm - the QuicCongestionControlAlgorithm to use.
      Returns:
      a QuicTransport reference
    • datagram

      public final QuicServer datagram(int recvQueueLen, int sendQueueLen)
      If configured this will enable Datagram support.
      Parameters:
      recvQueueLen - the RECV queue length.
      sendQueueLen - the SEND queue length.
      Returns:
      a QuicTransport reference
    • doOnBind

      public final QuicServer doOnBind(Consumer<? super QuicServerConfig> doOnBind)
      Set or add a callback called when QuicTransport is about to start listening for incoming traffic.
      Parameters:
      doOnBind - a consumer observing connected events
      Returns:
      a QuicTransport reference
    • doOnBound

      public final QuicServer doOnBound(Consumer<? super Connection> doOnBound)
      Set or add a callback called after QuicTransport has been started.
      Parameters:
      doOnBound - a consumer observing connected events
      Returns:
      a QuicTransport reference
    • doOnUnbound

      public final QuicServer doOnUnbound(Consumer<? super Connection> doOnUnbound)
      Set or add a callback called after QuicTransport has been shutdown.
      Parameters:
      doOnUnbound - a consumer observing unbound events
      Returns:
      a QuicTransport reference
    • grease

      public final QuicServer grease(boolean enable)
      Set if greasing should be enabled or not. Default to true.
      Parameters:
      enable - true if enabled, false otherwise.
      Returns:
      a QuicTransport reference
    • handleStream

      public final QuicServer handleStream(BiFunction<? super QuicInbound,? super QuicOutbound,? extends Publisher<Void>> streamHandler)
      Attach an IO handler to react on incoming stream.

      Note: If an IO handler is not specified the incoming streams will be closed automatically.

      Parameters:
      streamHandler - an IO handler that can dispose underlying connection when Publisher terminates.
      Returns:
      a QuicTransport reference
    • hystart

      public final QuicServer hystart(boolean enable)
      Enable/disable Hystart. See enable_hystart. Default to true.
      Parameters:
      enable - true if Hystart should be enabled
      Returns:
      a QuicTransport reference
    • idleTimeout

      public final QuicServer idleTimeout(Duration idleTimeout)
      Set the maximum idle timeout (resolution: ms) See set_max_idle_timeout.

      By default idleTimeout is not specified.

      Parameters:
      idleTimeout - the maximum idle timeout (resolution: ms)
      Returns:
      a QuicTransport reference
    • initialSettings

      public final QuicServer initialSettings(Consumer<QuicInitialSettingsSpec.Builder> initialSettings)
      Configure QUIC initial settings.
      Parameters:
      initialSettings - configures QUIC initial settings
      Returns:
      a QuicTransport reference
    • localConnectionIdLength

      public final QuicServer localConnectionIdLength(int localConnectionIdLength)
      Sets the local connection id length that is used. Default 20, which is also the maximum that is supported.
      Parameters:
      localConnectionIdLength - the length of local generated connections ids
      Returns:
      a QuicTransport reference
    • maxAckDelay

      public final QuicServer maxAckDelay(Duration maxAckDelay)
      Set max ACK delay (resolution: ms). See set_max_ack_delay. Default to 25 ms.
      Parameters:
      maxAckDelay - the max ACK delay (resolution: ms)
      Returns:
      a QuicTransport reference
    • maxRecvUdpPayloadSize

      public final QuicServer maxRecvUdpPayloadSize(long maxRecvUdpPayloadSize)
      See set_max_recv_udp_payload_size. The default value is 65527.
      Parameters:
      maxRecvUdpPayloadSize - the maximum payload size that is advertised to the remote peer.
      Returns:
      a QuicTransport reference
    • maxSendUdpPayloadSize

      public final QuicServer maxSendUdpPayloadSize(long maxSendUdpPayloadSize)
      See set_max_send_udp_payload_size. The default and minimum value is 1200.
      Parameters:
      maxSendUdpPayloadSize - the maximum payload size that is advertised to the remote peer.
      Returns:
      a QuicTransport reference
    • secure

      public final QuicServer secure(QuicSslContext sslContext)
      The QuicSslContext that will be used to create QuicSslEngines for QuicChannels.
      Parameters:
      sslContext - the QuicSslContext
      Returns:
      a QuicTransport reference
    • secure

      public final QuicServer secure(Function<QuicChannel,? extends QuicSslEngine> sslEngineProvider)
      The Function that will return the QuicSslEngine that should be used for the QuicChannel.
      Parameters:
      sslEngineProvider - the Function that will return the QuicSslEngine that should be used for the QuicChannel
      Returns:
      a QuicTransport reference
    • streamAttr

      public final <A> QuicServer streamAttr(AttributeKey<A> key, @Nullable A value)
      Injects default attribute to the future QuicStreamChannel. It will be available via AttributeMap.attr(AttributeKey). If the value is null, the attribute of the specified key is removed.
      Type Parameters:
      A - the attribute type
      Parameters:
      key - the attribute key
      value - the attribute value - null to remove a key
      Returns:
      a QuicTransport reference
      See Also:
    • streamObserve

      public QuicServer streamObserve(ConnectionObserver observer)
      Set or add the given ConnectionObserver for each stream.
      Parameters:
      observer - the ConnectionObserver addition
      Returns:
      a QuicTransport reference
    • streamOption

      public final <A> QuicServer streamOption(ChannelOption<A> key, @Nullable A value)
      Injects default options to the future QuicStreamChannel. It will be available via QuicStreamChannel.config(). If the value is null, the attribute of the specified key is removed.
      Type Parameters:
      A - the option type
      Parameters:
      key - the option key
      value - the option value - null to remove a key
      Returns:
      a QuicTransport reference
      See Also:
    • warmup

      public final Mono<Void> warmup()
      Based on the actual configuration, returns a Mono that triggers:
      • an initialization of the event loop group
      • loads the necessary native libraries for the transport
      By default, when method is not used, the bind operation absorbs the extra time needed to load resources.
      Returns:
      a Mono representing the completion of the warmup