Class QuicClient

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

public abstract class QuicClient extends Transport<T,CONF>
A QuicClient allows building in a safe immutable way a QUIC client that is materialized and connecting when connect() is ultimately called.

Example:

 
     QuicClient.create()
               .port(7777)
               .bindAddress(() -> new InetSocketAddress(0))
               .wiretap(true)
               .secure(clientCtx)
               .idleTimeout(Duration.ofSeconds(5))
               .initialSettings(spec ->
                   spec.maxData(10000000)
                       .maxStreamDataBidirectionalLocal(1000000))
               .connectNow();
 
 
Author:
Violeta Georgieva
  • Constructor Details

    • QuicClient

      public QuicClient()
  • Method Details

    • create

      public static QuicClient create()
      Prepare a QuicClient.
      Returns:
      a QuicClient
    • connect

      public abstract Mono<? extends QuicConnection> connect()
      Connect the QuicClient and return a Mono of QuicConnection. If Mono is cancelled, the underlying connection will be aborted. Once the QuicConnection has been emitted and is not necessary anymore, disposing must be done by the user via DisposableChannel.dispose().
      Returns:
      a Mono of QuicConnection
    • connectNow

      public final QuicConnection connectNow()
      Block the QuicClient and return a QuicConnection. Disposing must be done by the user via DisposableChannel.dispose(). The max connection timeout is 45 seconds.
      Returns:
      a QuicConnection
    • connectNow

      public final QuicConnection connectNow(Duration timeout)
      Block the QuicClient and return a QuicConnection. Disposing must be done by the user via DisposableChannel.dispose().
      Parameters:
      timeout - connect timeout (resolution: ns)
      Returns:
      a QuicConnection
    • doOnConnect

      public final QuicClient doOnConnect(Consumer<? super QuicClientConfig> doOnConnect)
      Set or add a callback called when QuicClient is about to connect to the remote endpoint.
      Parameters:
      doOnConnect - a consumer observing connect events
      Returns:
      a QuicClient reference
    • doOnConnected

      public final QuicClient doOnConnected(Consumer<? super QuicConnection> doOnConnected)
      Set or add a callback called after QuicConnection has been connected.
      Parameters:
      doOnConnected - a consumer observing connected events
      Returns:
      a QuicClient reference
    • doOnDisconnected

      public final QuicClient doOnDisconnected(Consumer<? super QuicConnection> doOnDisconnected)
      Set or add a callback called after QuicConnection has been disconnected.
      Parameters:
      doOnDisconnected - a consumer observing disconnected events
      Returns:
      a QuicClient reference
    • host

      public final QuicClient host(String host)
      The host to which this client should connect.
      Parameters:
      host - the host to connect to
      Returns:
      a QuicClient reference
    • port

      public final QuicClient port(int port)
      The port to which this client should connect. If a port is not specified, the default port 12012 is used.

      Note: The port can be specified also with QUIC_PORT environment variable.

      Parameters:
      port - the port to connect to
      Returns:
      a QuicClient reference
    • remoteAddress

      public final QuicClient remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
      The address to which this client should connect on each subscribe.
      Parameters:
      remoteAddressSupplier - A supplier of the address to connect to.
      Returns:
      a QuicClient
    • ackDelayExponent

      public final QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient doOnBind(Consumer<? super QuicClientConfig> 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient initialSettings(Consumer<QuicInitialSettingsSpec.Builder> initialSettings)
      Configure QUIC initial settings.
      Parameters:
      initialSettings - configures QUIC initial settings
      Returns:
      a QuicTransport reference
    • localConnectionIdLength

      public final QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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 QuicClient 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> QuicClient 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 QuicClient 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> QuicClient 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