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