2
0

cc_dummy.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2022-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. #include "internal/quic_cc.h"
  10. #include "internal/quic_types.h"
  11. typedef struct ossl_cc_dummy_st {
  12. size_t max_dgram_len;
  13. size_t *p_diag_max_dgram_len;
  14. } OSSL_CC_DUMMY;
  15. static void dummy_update_diag(OSSL_CC_DUMMY *d);
  16. static OSSL_CC_DATA *dummy_new(OSSL_TIME (*now_cb)(void *arg),
  17. void *now_cb_arg)
  18. {
  19. OSSL_CC_DUMMY *d = OPENSSL_zalloc(sizeof(*d));
  20. if (d == NULL)
  21. return NULL;
  22. d->max_dgram_len = QUIC_MIN_INITIAL_DGRAM_LEN;
  23. return (OSSL_CC_DATA *)d;
  24. }
  25. static void dummy_free(OSSL_CC_DATA *cc)
  26. {
  27. OPENSSL_free(cc);
  28. }
  29. static void dummy_reset(OSSL_CC_DATA *cc)
  30. {
  31. }
  32. static int dummy_set_input_params(OSSL_CC_DATA *cc, const OSSL_PARAM *params)
  33. {
  34. OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
  35. const OSSL_PARAM *p;
  36. size_t value;
  37. p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN);
  38. if (p != NULL) {
  39. if (!OSSL_PARAM_get_size_t(p, &value))
  40. return 0;
  41. if (value < QUIC_MIN_INITIAL_DGRAM_LEN)
  42. return 0;
  43. d->max_dgram_len = value;
  44. dummy_update_diag(d);
  45. }
  46. return 1;
  47. }
  48. static int dummy_bind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params)
  49. {
  50. OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
  51. const OSSL_PARAM *p;
  52. p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN);
  53. if (p != NULL) {
  54. if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER
  55. || p->data_size != sizeof(size_t))
  56. return 0;
  57. d->p_diag_max_dgram_len = p->data;
  58. }
  59. dummy_update_diag(d);
  60. return 1;
  61. }
  62. static int dummy_unbind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params)
  63. {
  64. OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
  65. if (OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN)
  66. != NULL)
  67. d->p_diag_max_dgram_len = NULL;
  68. return 1;
  69. }
  70. static void dummy_update_diag(OSSL_CC_DUMMY *d)
  71. {
  72. if (d->p_diag_max_dgram_len != NULL)
  73. *d->p_diag_max_dgram_len = d->max_dgram_len;
  74. }
  75. static uint64_t dummy_get_tx_allowance(OSSL_CC_DATA *cc)
  76. {
  77. return SIZE_MAX;
  78. }
  79. static OSSL_TIME dummy_get_wakeup_deadline(OSSL_CC_DATA *cc)
  80. {
  81. return ossl_time_infinite();
  82. }
  83. static int dummy_on_data_sent(OSSL_CC_DATA *cc,
  84. uint64_t num_bytes)
  85. {
  86. return 1;
  87. }
  88. static int dummy_on_data_acked(OSSL_CC_DATA *cc,
  89. const OSSL_CC_ACK_INFO *info)
  90. {
  91. return 1;
  92. }
  93. static int dummy_on_data_lost(OSSL_CC_DATA *cc,
  94. const OSSL_CC_LOSS_INFO *info)
  95. {
  96. return 1;
  97. }
  98. static int dummy_on_data_lost_finished(OSSL_CC_DATA *cc,
  99. uint32_t flags)
  100. {
  101. return 1;
  102. }
  103. static int dummy_on_data_invalidated(OSSL_CC_DATA *cc,
  104. uint64_t num_bytes)
  105. {
  106. return 1;
  107. }
  108. const OSSL_CC_METHOD ossl_cc_dummy_method = {
  109. dummy_new,
  110. dummy_free,
  111. dummy_reset,
  112. dummy_set_input_params,
  113. dummy_bind_diagnostic,
  114. dummy_unbind_diagnostic,
  115. dummy_get_tx_allowance,
  116. dummy_get_wakeup_deadline,
  117. dummy_on_data_sent,
  118. dummy_on_data_acked,
  119. dummy_on_data_lost,
  120. dummy_on_data_lost_finished,
  121. dummy_on_data_invalidated,
  122. };