|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
| 4 | +#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC |
| 5 | + |
| 6 | +#include<env.h> |
| 7 | +#include<memory_tracker.h> |
| 8 | +#include<nghttp3/nghttp3.h> |
| 9 | +#include<ngtcp2/ngtcp2.h> |
| 10 | +#include<node_internals.h> |
| 11 | +#include<node_sockaddr.h> |
| 12 | +#include<v8.h> |
| 13 | + |
| 14 | +namespacenode { |
| 15 | +namespacequic { |
| 16 | + |
| 17 | +structPathfinal : public ngtcp2_path { |
| 18 | +Path(const SocketAddress& local, const SocketAddress& remote); |
| 19 | +}; |
| 20 | + |
| 21 | +structPathStoragefinal : public ngtcp2_path_storage { |
| 22 | +PathStorage(); |
| 23 | +operatorngtcp2_path(); |
| 24 | +}; |
| 25 | + |
| 26 | +classStorefinal : public MemoryRetainer { |
| 27 | +public: |
| 28 | +Store() = default; |
| 29 | + |
| 30 | +Store(std::shared_ptr<v8::BackingStore> store, |
| 31 | +size_t length, |
| 32 | +size_t offset = 0); |
| 33 | +Store(std::unique_ptr<v8::BackingStore> store, |
| 34 | +size_t length, |
| 35 | +size_t offset = 0); |
| 36 | + |
| 37 | +enumclassOption { |
| 38 | +NONE, |
| 39 | +DETACH, |
| 40 | + }; |
| 41 | + |
| 42 | +Store(v8::Local<v8::ArrayBuffer> buffer, Option option = Option::NONE); |
| 43 | +Store(v8::Local<v8::ArrayBufferView> view, Option option = Option::NONE); |
| 44 | + |
| 45 | + v8::Local<v8::Uint8Array> ToUint8Array(Environment* env) const; |
| 46 | + |
| 47 | +operatoruv_buf_t() const; |
| 48 | +operatorngtcp2_vec() const; |
| 49 | +operatornghttp3_vec() const; |
| 50 | +operatorbool() const; |
| 51 | +size_tlength() const; |
| 52 | + |
| 53 | +voidMemoryInfo(MemoryTracker* tracker) constoverride; |
| 54 | +SET_MEMORY_INFO_NAME(Store) |
| 55 | +SET_SELF_SIZE(Store) |
| 56 | + |
| 57 | +private: |
| 58 | +template <typename T, typename t> |
| 59 | + T convert() const; |
| 60 | + std::shared_ptr<v8::BackingStore> store_; |
| 61 | +size_t length_ = 0; |
| 62 | +size_t offset_ = 0; |
| 63 | +}; |
| 64 | + |
| 65 | +classQuicErrorfinal : public MemoryRetainer { |
| 66 | +public: |
| 67 | +using error_code = uint64_t; |
| 68 | + |
| 69 | +staticconstexpr error_code QUIC_NO_ERROR = NGTCP2_NO_ERROR; |
| 70 | +staticconstexpr error_code QUIC_APP_NO_ERROR = 65280; |
| 71 | + |
| 72 | +enumclassType { |
| 73 | +TRANSPORT = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT, |
| 74 | +APPLICATION = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION, |
| 75 | +VERSION_NEGOTIATION = |
| 76 | +NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION, |
| 77 | +IDLE_CLOSE = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE, |
| 78 | + }; |
| 79 | + |
| 80 | +staticconstexpr error_code QUIC_ERROR_TYPE_TRANSPORT = |
| 81 | +NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT; |
| 82 | +staticconstexpr error_code QUIC_ERROR_TYPE_APPLICATION = |
| 83 | +NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION; |
| 84 | + |
| 85 | +explicitQuicError(const std::string_view reason = ""); |
| 86 | +explicitQuicError(const ngtcp2_connection_close_error* ptr); |
| 87 | +explicitQuicError(const ngtcp2_connection_close_error& error); |
| 88 | + |
| 89 | + Type type() const; |
| 90 | + error_code code() const; |
| 91 | +const std::string_view reason() const; |
| 92 | +uint64_tframe_type() const; |
| 93 | + |
| 94 | +operatorconst ngtcp2_connection_close_error&() const; |
| 95 | +operatorconst ngtcp2_connection_close_error*() const; |
| 96 | + |
| 97 | +// Returns false if the QuicError uses a no_error code with type |
| 98 | +// transport or application. |
| 99 | +operatorbool() const; |
| 100 | + |
| 101 | +booloperator==(const QuicError& other) const; |
| 102 | +booloperator!=(const QuicError& other) const; |
| 103 | + |
| 104 | +voidMemoryInfo(MemoryTracker* tracker) constoverride; |
| 105 | +SET_MEMORY_INFO_NAME(QuicError) |
| 106 | +SET_SELF_SIZE(QuicError) |
| 107 | + |
| 108 | + std::string ToString() const; |
| 109 | + v8::MaybeLocal<v8::Value> ToV8Value(Environment* env) const; |
| 110 | + |
| 111 | +static QuicError ForTransport(error_code code, |
| 112 | +const std::string_view reason = ""); |
| 113 | +static QuicError ForApplication(error_code code, |
| 114 | +const std::string_view reason = ""); |
| 115 | +static QuicError ForVersionNegotiation(const std::string_view reason = ""); |
| 116 | +static QuicError ForIdleClose(const std::string_view reason = ""); |
| 117 | +static QuicError ForNgtcp2Error(int code, const std::string_view reason = ""); |
| 118 | +static QuicError ForTlsAlert(int code, const std::string_view reason = ""); |
| 119 | + |
| 120 | +static QuicError FromConnectionClose(ngtcp2_conn* session); |
| 121 | + |
| 122 | +static QuicError TRANSPORT_NO_ERROR; |
| 123 | +static QuicError APPLICATION_NO_ERROR; |
| 124 | +static QuicError VERSION_NEGOTIATION; |
| 125 | +static QuicError IDLE_CLOSE; |
| 126 | +static QuicError INTERNAL_ERROR; |
| 127 | + |
| 128 | +private: |
| 129 | +constuint8_t* reason_c_str() const; |
| 130 | + |
| 131 | + std::string reason_; |
| 132 | + ngtcp2_connection_close_error error_ = ngtcp2_connection_close_error(); |
| 133 | +const ngtcp2_connection_close_error* ptr_ = nullptr; |
| 134 | +}; |
| 135 | + |
| 136 | +} // namespace quic |
| 137 | +} // namespace node |
| 138 | + |
| 139 | +#endif// HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC |
| 140 | +#endif// defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
0 commit comments