quic_engine.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_QUIC_ENGINE_H
  10. # define OSSL_QUIC_ENGINE_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_predef.h"
  13. # include "internal/quic_port.h"
  14. # include "internal/thread_arch.h"
  15. # ifndef OPENSSL_NO_QUIC
  16. /*
  17. * QUIC Engine
  18. * ===========
  19. *
  20. * A QUIC Engine (QUIC_ENGINE) represents an event processing domain for the
  21. * purposes of QUIC and contains zero or more subsidiary QUIC_PORT instances
  22. * (each of which currently represents a UDP socket), each of which in turn
  23. * contains zero or more subsidiary QUIC_CHANNEL instances, each of which
  24. * represents a single QUIC connection. All QUIC_PORT instances must belong
  25. * to a QUIC_ENGINE.
  26. *
  27. * TODO(QUIC SERVER): Currently a QUIC_PORT belongs to a single QUIC_CHANNEL.
  28. * This will cease to be the case once connection migration and/or multipath is
  29. * implemented, so in future a channel might be associated with multiple ports.
  30. *
  31. * A QUIC engine is the root object in a QUIC event domain, and is responsible
  32. * for managing event processing for all QUIC ports and channels (e.g. timeouts,
  33. * clock management, the QUIC_REACTOR instance, etc.).
  34. */
  35. typedef struct quic_engine_args_st {
  36. OSSL_LIB_CTX *libctx;
  37. const char *propq;
  38. /*
  39. * This must be a mutex the lifetime of which will exceed that of the engine
  40. * and all ports and channels. The instantiator of the engine is responsible
  41. * for providing a mutex as this makes it easier to handle instantiation and
  42. * teardown of channels in situations potentially requiring locking.
  43. *
  44. * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for
  45. * compatibility with an OS's condition variable wait API, whereas RWLOCK
  46. * may, depending on the build configuration, be implemented using an OS's
  47. * mutex primitive or using its RW mutex primitive.
  48. */
  49. CRYPTO_MUTEX *mutex;
  50. OSSL_TIME (*now_cb)(void *arg);
  51. void *now_cb_arg;
  52. } QUIC_ENGINE_ARGS;
  53. QUIC_ENGINE *ossl_quic_engine_new(const QUIC_ENGINE_ARGS *args);
  54. void ossl_quic_engine_free(QUIC_ENGINE *qeng);
  55. /*
  56. * Create a port which is a child of the engine. args->engine shall be NULL.
  57. */
  58. QUIC_PORT *ossl_quic_engine_create_port(QUIC_ENGINE *qeng,
  59. const QUIC_PORT_ARGS *args);
  60. /* Gets the mutex used by the engine. */
  61. CRYPTO_MUTEX *ossl_quic_engine_get0_mutex(QUIC_ENGINE *qeng);
  62. /* Gets the current time. */
  63. OSSL_TIME ossl_quic_engine_get_time(QUIC_ENGINE *qeng);
  64. /* For testing use. While enabled, ticking is not performed. */
  65. void ossl_quic_engine_set_inhibit_tick(QUIC_ENGINE *qeng, int inhibit);
  66. /* Gets the reactor which can be used to tick/poll on the port. */
  67. QUIC_REACTOR *ossl_quic_engine_get0_reactor(QUIC_ENGINE *qeng);
  68. # endif
  69. #endif