@encharm/cws 4.5.1 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/binding.gyp +1 -1
  2. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  3. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  4. package/package.json +1 -1
  5. package/src/Addon.h +6 -1
  6. package/src/headers/24/acorn_version.h +6 -0
  7. package/src/headers/24/addon_permission.h +31 -0
  8. package/src/headers/24/agent.h +195 -0
  9. package/src/headers/24/aliased_buffer-inl.h +244 -0
  10. package/src/headers/24/aliased_buffer.h +206 -0
  11. package/src/headers/24/aliased_struct-inl.h +54 -0
  12. package/src/headers/24/aliased_struct.h +63 -0
  13. package/src/headers/24/amaro_version.h +6 -0
  14. package/src/headers/24/application.h +165 -0
  15. package/src/headers/24/async_context_frame.h +33 -0
  16. package/src/headers/24/async_wrap-inl.h +96 -0
  17. package/src/headers/24/async_wrap.h +244 -0
  18. package/src/headers/24/base_object-inl.h +330 -0
  19. package/src/headers/24/base_object.h +338 -0
  20. package/src/headers/24/base_object_types.h +74 -0
  21. package/src/headers/24/bindingdata.h +272 -0
  22. package/src/headers/24/blob_serializer_deserializer-inl.h +385 -0
  23. package/src/headers/24/blob_serializer_deserializer.h +132 -0
  24. package/src/headers/24/callback_queue-inl.h +97 -0
  25. package/src/headers/24/callback_queue.h +79 -0
  26. package/src/headers/24/cares_wrap.h +447 -0
  27. package/src/headers/24/child_process_permission.h +31 -0
  28. package/src/headers/24/cid.h +127 -0
  29. package/src/headers/24/cjs_module_lexer_version.h +6 -0
  30. package/src/headers/24/cleanup_queue-inl.h +36 -0
  31. package/src/headers/24/cleanup_queue.h +79 -0
  32. package/src/headers/24/compile_cache.h +113 -0
  33. package/src/headers/24/connect_wrap.h +26 -0
  34. package/src/headers/24/connection_wrap.h +30 -0
  35. package/src/headers/24/cppgc_helpers-inl.h +65 -0
  36. package/src/headers/24/cppgc_helpers.h +162 -0
  37. package/src/headers/24/crypto/crypto_aes.h +97 -0
  38. package/src/headers/24/crypto/crypto_argon2.h +86 -0
  39. package/src/headers/24/crypto/crypto_bio.h +193 -0
  40. package/src/headers/24/crypto/crypto_chacha20_poly1305.h +64 -0
  41. package/src/headers/24/crypto/crypto_cipher.h +281 -0
  42. package/src/headers/24/crypto/crypto_clienthello-inl.h +90 -0
  43. package/src/headers/24/crypto/crypto_clienthello.h +131 -0
  44. package/src/headers/24/crypto/crypto_common.h +48 -0
  45. package/src/headers/24/crypto/crypto_context.h +171 -0
  46. package/src/headers/24/crypto/crypto_dh.h +126 -0
  47. package/src/headers/24/crypto/crypto_dsa.h +50 -0
  48. package/src/headers/24/crypto/crypto_ec.h +163 -0
  49. package/src/headers/24/crypto/crypto_hash.h +89 -0
  50. package/src/headers/24/crypto/crypto_hkdf.h +61 -0
  51. package/src/headers/24/crypto/crypto_hmac.h +92 -0
  52. package/src/headers/24/crypto/crypto_kem.h +113 -0
  53. package/src/headers/24/crypto/crypto_keygen.h +290 -0
  54. package/src/headers/24/crypto/crypto_keys.h +392 -0
  55. package/src/headers/24/crypto/crypto_ml_dsa.h +21 -0
  56. package/src/headers/24/crypto/crypto_pbkdf2.h +74 -0
  57. package/src/headers/24/crypto/crypto_random.h +124 -0
  58. package/src/headers/24/crypto/crypto_rsa.h +136 -0
  59. package/src/headers/24/crypto/crypto_scrypt.h +85 -0
  60. package/src/headers/24/crypto/crypto_sig.h +156 -0
  61. package/src/headers/24/crypto/crypto_spkac.h +21 -0
  62. package/src/headers/24/crypto/crypto_timing.h +20 -0
  63. package/src/headers/24/crypto/crypto_tls.h +309 -0
  64. package/src/headers/24/crypto/crypto_util.h +598 -0
  65. package/src/headers/24/crypto/crypto_x509.h +140 -0
  66. package/src/headers/24/data.h +148 -0
  67. package/src/headers/24/debug_utils-inl.h +232 -0
  68. package/src/headers/24/debug_utils.h +193 -0
  69. package/src/headers/24/defs.h +254 -0
  70. package/src/headers/24/diagnosticfilename-inl.h +33 -0
  71. package/src/headers/24/embedded_data.h +17 -0
  72. package/src/headers/24/encoding_binding.h +60 -0
  73. package/src/headers/24/endpoint.h +421 -0
  74. package/src/headers/24/env-inl.h +935 -0
  75. package/src/headers/24/env.h +1257 -0
  76. package/src/headers/24/env_properties.h +561 -0
  77. package/src/headers/24/fs_permission.h +167 -0
  78. package/src/headers/24/handle_wrap.h +123 -0
  79. package/src/headers/24/histogram-inl.h +107 -0
  80. package/src/headers/24/histogram.h +279 -0
  81. package/src/headers/24/http3.h +44 -0
  82. package/src/headers/24/inspector_agent.h +165 -0
  83. package/src/headers/24/inspector_io.h +78 -0
  84. package/src/headers/24/inspector_permission.h +31 -0
  85. package/src/headers/24/inspector_profiler.h +149 -0
  86. package/src/headers/24/inspector_socket.h +60 -0
  87. package/src/headers/24/inspector_socket_server.h +110 -0
  88. package/src/headers/24/io_agent.h +30 -0
  89. package/src/headers/24/js_native_api.h +615 -0
  90. package/src/headers/24/js_native_api_types.h +211 -0
  91. package/src/headers/24/js_native_api_v8.h +485 -0
  92. package/src/headers/24/js_native_api_v8_internals.h +45 -0
  93. package/src/headers/24/js_stream.h +52 -0
  94. package/src/headers/24/json_parser.h +40 -0
  95. package/src/headers/24/json_utils.h +172 -0
  96. package/src/headers/24/logstream.h +81 -0
  97. package/src/headers/24/main_thread_interface.h +116 -0
  98. package/src/headers/24/memory_tracker-inl.h +454 -0
  99. package/src/headers/24/memory_tracker.h +333 -0
  100. package/src/headers/24/module_wrap.h +229 -0
  101. package/src/headers/24/ncrypto.h +1625 -0
  102. package/src/headers/24/network_agent.h +118 -0
  103. package/src/headers/24/network_inspector.h +45 -0
  104. package/src/headers/24/network_resource_manager.h +29 -0
  105. package/src/headers/24/node.h +1620 -0
  106. package/src/headers/24/node_api.h +269 -0
  107. package/src/headers/24/node_api_internals.h +46 -0
  108. package/src/headers/24/node_api_types.h +52 -0
  109. package/src/headers/24/node_binding.h +163 -0
  110. package/src/headers/24/node_blob.h +159 -0
  111. package/src/headers/24/node_bob-inl.h +36 -0
  112. package/src/headers/24/node_bob.h +107 -0
  113. package/src/headers/24/node_buffer.h +92 -0
  114. package/src/headers/24/node_builtins.h +223 -0
  115. package/src/headers/24/node_config_file.h +65 -0
  116. package/src/headers/24/node_constants.h +82 -0
  117. package/src/headers/24/node_context_data.h +168 -0
  118. package/src/headers/24/node_contextify.h +261 -0
  119. package/src/headers/24/node_crypto.h +62 -0
  120. package/src/headers/24/node_debug.h +25 -0
  121. package/src/headers/24/node_dir.h +52 -0
  122. package/src/headers/24/node_dotenv.h +45 -0
  123. package/src/headers/24/node_errors.h +391 -0
  124. package/src/headers/24/node_exit_code.h +54 -0
  125. package/src/headers/24/node_external_reference.h +167 -0
  126. package/src/headers/24/node_file-inl.h +412 -0
  127. package/src/headers/24/node_file.h +540 -0
  128. package/src/headers/24/node_http2.h +1175 -0
  129. package/src/headers/24/node_http2_state.h +159 -0
  130. package/src/headers/24/node_http_common-inl.h +198 -0
  131. package/src/headers/24/node_http_common.h +535 -0
  132. package/src/headers/24/node_i18n.h +132 -0
  133. package/src/headers/24/node_internals.h +476 -0
  134. package/src/headers/24/node_json.h +24 -0
  135. package/src/headers/24/node_large_page.h +34 -0
  136. package/src/headers/24/node_locks.h +180 -0
  137. package/src/headers/24/node_main_instance.h +67 -0
  138. package/src/headers/24/node_mem-inl.h +112 -0
  139. package/src/headers/24/node_mem.h +45 -0
  140. package/src/headers/24/node_messaging.h +389 -0
  141. package/src/headers/24/node_metadata.h +164 -0
  142. package/src/headers/24/node_modules.h +93 -0
  143. package/src/headers/24/node_mutex.h +323 -0
  144. package/src/headers/24/node_object_wrap.h +132 -0
  145. package/src/headers/24/node_options-inl.h +524 -0
  146. package/src/headers/24/node_options.h +682 -0
  147. package/src/headers/24/node_perf.h +166 -0
  148. package/src/headers/24/node_perf_common.h +102 -0
  149. package/src/headers/24/node_platform.h +286 -0
  150. package/src/headers/24/node_process-inl.h +26 -0
  151. package/src/headers/24/node_process.h +111 -0
  152. package/src/headers/24/node_realm-inl.h +153 -0
  153. package/src/headers/24/node_realm.h +236 -0
  154. package/src/headers/24/node_report.h +43 -0
  155. package/src/headers/24/node_revert.h +82 -0
  156. package/src/headers/24/node_root_certs.h +3546 -0
  157. package/src/headers/24/node_sea.h +74 -0
  158. package/src/headers/24/node_shadow_realm.h +46 -0
  159. package/src/headers/24/node_snapshot_builder.h +57 -0
  160. package/src/headers/24/node_snapshotable.h +174 -0
  161. package/src/headers/24/node_sockaddr-inl.h +257 -0
  162. package/src/headers/24/node_sockaddr.h +394 -0
  163. package/src/headers/24/node_sqlite.h +270 -0
  164. package/src/headers/24/node_stat_watcher.h +73 -0
  165. package/src/headers/24/node_string.h +101 -0
  166. package/src/headers/24/node_task_runner.h +92 -0
  167. package/src/headers/24/node_threadsafe_cow-inl.h +54 -0
  168. package/src/headers/24/node_threadsafe_cow.h +105 -0
  169. package/src/headers/24/node_trace_buffer.h +83 -0
  170. package/src/headers/24/node_trace_writer.h +75 -0
  171. package/src/headers/24/node_union_bytes.h +81 -0
  172. package/src/headers/24/node_url.h +101 -0
  173. package/src/headers/24/node_url_pattern.h +118 -0
  174. package/src/headers/24/node_v8.h +77 -0
  175. package/src/headers/24/node_v8_platform-inl.h +185 -0
  176. package/src/headers/24/node_version.h +110 -0
  177. package/src/headers/24/node_wasi.h +185 -0
  178. package/src/headers/24/node_wasm_web_api.h +55 -0
  179. package/src/headers/24/node_watchdog.h +154 -0
  180. package/src/headers/24/node_webstorage.h +60 -0
  181. package/src/headers/24/node_worker.h +159 -0
  182. package/src/headers/24/packet.h +155 -0
  183. package/src/headers/24/path.h +33 -0
  184. package/src/headers/24/permission/addon_permission.h +31 -0
  185. package/src/headers/24/permission/child_process_permission.h +31 -0
  186. package/src/headers/24/permission/fs_permission.h +167 -0
  187. package/src/headers/24/permission/inspector_permission.h +31 -0
  188. package/src/headers/24/permission/permission.h +100 -0
  189. package/src/headers/24/permission/permission_base.h +65 -0
  190. package/src/headers/24/permission/wasi_permission.h +31 -0
  191. package/src/headers/24/permission/worker_permission.h +31 -0
  192. package/src/headers/24/permission.h +100 -0
  193. package/src/headers/24/permission_base.h +65 -0
  194. package/src/headers/24/pipe_wrap.h +80 -0
  195. package/src/headers/24/preferredaddress.h +72 -0
  196. package/src/headers/24/protocol_helper.h +27 -0
  197. package/src/headers/24/queue.h +306 -0
  198. package/src/headers/24/req_wrap-inl.h +176 -0
  199. package/src/headers/24/req_wrap.h +79 -0
  200. package/src/headers/24/runtime_agent.h +41 -0
  201. package/src/headers/24/session.h +528 -0
  202. package/src/headers/24/sessionticket.h +108 -0
  203. package/src/headers/24/spawn_sync.h +243 -0
  204. package/src/headers/24/stream_base-inl.h +173 -0
  205. package/src/headers/24/stream_base.h +478 -0
  206. package/src/headers/24/stream_pipe.h +76 -0
  207. package/src/headers/24/stream_wrap.h +132 -0
  208. package/src/headers/24/streams.h +370 -0
  209. package/src/headers/24/string_bytes.h +109 -0
  210. package/src/headers/24/string_decoder-inl.h +31 -0
  211. package/src/headers/24/string_decoder.h +49 -0
  212. package/src/headers/24/target_agent.h +75 -0
  213. package/src/headers/24/tcp_wrap.h +105 -0
  214. package/src/headers/24/threadpoolwork-inl.h +70 -0
  215. package/src/headers/24/timer_wrap-inl.h +32 -0
  216. package/src/headers/24/timer_wrap.h +87 -0
  217. package/src/headers/24/timers.h +75 -0
  218. package/src/headers/24/tlscontext.h +228 -0
  219. package/src/headers/24/tokens.h +256 -0
  220. package/src/headers/24/trace_event.h +722 -0
  221. package/src/headers/24/trace_event_common.h +1109 -0
  222. package/src/headers/24/traced_value.h +129 -0
  223. package/src/headers/24/tracing_agent.h +43 -0
  224. package/src/headers/24/transportparams.h +166 -0
  225. package/src/headers/24/tty_wrap.h +65 -0
  226. package/src/headers/24/udp_wrap.h +230 -0
  227. package/src/headers/24/undici_version.h +6 -0
  228. package/src/headers/24/util-inl.h +711 -0
  229. package/src/headers/24/util.h +1016 -0
  230. package/src/headers/24/v8-external-memory-accounter.h +60 -0
  231. package/src/headers/24/v8-fast-api-calls.h +819 -0
  232. package/src/headers/24/v8-inspector.h +426 -0
  233. package/src/headers/24/wasi_permission.h +31 -0
  234. package/src/headers/24/worker_agent.h +40 -0
  235. package/src/headers/24/worker_inspector.h +124 -0
  236. package/src/headers/24/worker_permission.h +31 -0
  237. package/src/headers/24/zlib_version.h +6 -0
@@ -0,0 +1,100 @@
1
+ #ifndef SRC_PERMISSION_PERMISSION_H_
2
+ #define SRC_PERMISSION_PERMISSION_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include "debug_utils.h"
7
+ #include "node_options.h"
8
+ #include "permission/addon_permission.h"
9
+ #include "permission/child_process_permission.h"
10
+ #include "permission/fs_permission.h"
11
+ #include "permission/inspector_permission.h"
12
+ #include "permission/permission_base.h"
13
+ #include "permission/wasi_permission.h"
14
+ #include "permission/worker_permission.h"
15
+ #include "v8.h"
16
+
17
+ #include <string_view>
18
+ #include <unordered_map>
19
+
20
+ namespace node {
21
+
22
+ class Environment;
23
+
24
+ namespace fs {
25
+ class FSReqBase;
26
+ }
27
+
28
+ namespace permission {
29
+
30
+ #define THROW_IF_INSUFFICIENT_PERMISSIONS(env, perm_, resource_, ...) \
31
+ do { \
32
+ if (!env->permission()->is_granted(env, perm_, resource_)) [[unlikely]] { \
33
+ node::permission::Permission::ThrowAccessDenied( \
34
+ (env), perm_, resource_); \
35
+ return __VA_ARGS__; \
36
+ } \
37
+ } while (0)
38
+
39
+ #define ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS( \
40
+ env, wrap, perm_, resource_, ...) \
41
+ do { \
42
+ if (!env->permission()->is_granted(env, perm_, resource_)) [[unlikely]] { \
43
+ node::permission::Permission::AsyncThrowAccessDenied( \
44
+ (env), wrap, perm_, resource_); \
45
+ return __VA_ARGS__; \
46
+ } \
47
+ } while (0)
48
+
49
+ class Permission {
50
+ public:
51
+ Permission();
52
+
53
+ FORCE_INLINE bool is_granted(Environment* env,
54
+ const PermissionScope permission,
55
+ const std::string_view& res = "") const {
56
+ if (!enabled_) [[likely]] {
57
+ return true;
58
+ }
59
+ return is_scope_granted(env, permission, res);
60
+ }
61
+
62
+ FORCE_INLINE bool enabled() const { return enabled_; }
63
+
64
+ static PermissionScope StringToPermission(const std::string& perm);
65
+ static const char* PermissionToString(PermissionScope perm);
66
+ static void ThrowAccessDenied(Environment* env,
67
+ PermissionScope perm,
68
+ const std::string_view& res);
69
+ static void AsyncThrowAccessDenied(Environment* env,
70
+ fs::FSReqBase* req_wrap,
71
+ PermissionScope perm,
72
+ const std::string_view& res);
73
+
74
+ // CLI Call
75
+ void Apply(Environment* env,
76
+ const std::vector<std::string>& allow,
77
+ PermissionScope scope);
78
+ void EnablePermissions();
79
+
80
+ private:
81
+ COLD_NOINLINE bool is_scope_granted(Environment* env,
82
+ const PermissionScope permission,
83
+ const std::string_view& res = "") const {
84
+ auto perm_node = nodes_.find(permission);
85
+ if (perm_node != nodes_.end()) {
86
+ return perm_node->second->is_granted(env, permission, res);
87
+ }
88
+ return false;
89
+ }
90
+
91
+ std::unordered_map<PermissionScope, std::shared_ptr<PermissionBase>> nodes_;
92
+ bool enabled_;
93
+ };
94
+
95
+ } // namespace permission
96
+
97
+ } // namespace node
98
+
99
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
100
+ #endif // SRC_PERMISSION_PERMISSION_H_
@@ -0,0 +1,65 @@
1
+ #ifndef SRC_PERMISSION_PERMISSION_BASE_H_
2
+ #define SRC_PERMISSION_PERMISSION_BASE_H_
3
+
4
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
+
6
+ #include <map>
7
+ #include <string>
8
+ #include <string_view>
9
+ #include "v8.h"
10
+
11
+ namespace node {
12
+
13
+ class Environment;
14
+
15
+ namespace permission {
16
+
17
+ #define FILESYSTEM_PERMISSIONS(V) \
18
+ V(FileSystem, "fs", PermissionsRoot, "") \
19
+ V(FileSystemRead, "fs.read", FileSystem, "--allow-fs-read") \
20
+ V(FileSystemWrite, "fs.write", FileSystem, "--allow-fs-write")
21
+
22
+ #define CHILD_PROCESS_PERMISSIONS(V) \
23
+ V(ChildProcess, "child", PermissionsRoot, "--allow-child-process")
24
+
25
+ #define WASI_PERMISSIONS(V) V(WASI, "wasi", PermissionsRoot, "--allow-wasi")
26
+
27
+ #define WORKER_THREADS_PERMISSIONS(V) \
28
+ V(WorkerThreads, "worker", PermissionsRoot, "--allow-worker")
29
+
30
+ #define INSPECTOR_PERMISSIONS(V) V(Inspector, "inspector", PermissionsRoot, "")
31
+
32
+ #define ADDON_PERMISSIONS(V) \
33
+ V(Addon, "addon", PermissionsRoot, "--allow-addons")
34
+
35
+ #define PERMISSIONS(V) \
36
+ FILESYSTEM_PERMISSIONS(V) \
37
+ CHILD_PROCESS_PERMISSIONS(V) \
38
+ WASI_PERMISSIONS(V) \
39
+ WORKER_THREADS_PERMISSIONS(V) \
40
+ INSPECTOR_PERMISSIONS(V) \
41
+ ADDON_PERMISSIONS(V)
42
+
43
+ #define V(name, _, __, ___) k##name,
44
+ enum class PermissionScope {
45
+ kPermissionsRoot = -1,
46
+ PERMISSIONS(V) kPermissionsCount
47
+ };
48
+ #undef V
49
+
50
+ class PermissionBase {
51
+ public:
52
+ virtual void Apply(Environment* env,
53
+ const std::vector<std::string>& allow,
54
+ PermissionScope scope) = 0;
55
+ virtual bool is_granted(Environment* env,
56
+ PermissionScope perm,
57
+ const std::string_view& param = "") const = 0;
58
+ };
59
+
60
+ } // namespace permission
61
+
62
+ } // namespace node
63
+
64
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
65
+ #endif // SRC_PERMISSION_PERMISSION_BASE_H_
@@ -0,0 +1,80 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ #ifndef SRC_PIPE_WRAP_H_
23
+ #define SRC_PIPE_WRAP_H_
24
+
25
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
+
27
+ #include "async_wrap.h"
28
+ #include "connection_wrap.h"
29
+
30
+ namespace node {
31
+
32
+ class ExternalReferenceRegistry;
33
+ class Environment;
34
+
35
+ class PipeWrap : public ConnectionWrap<PipeWrap, uv_pipe_t> {
36
+ public:
37
+ enum SocketType {
38
+ SOCKET,
39
+ SERVER,
40
+ IPC
41
+ };
42
+
43
+ static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
44
+ AsyncWrap* parent,
45
+ SocketType type);
46
+ static void Initialize(v8::Local<v8::Object> target,
47
+ v8::Local<v8::Value> unused,
48
+ v8::Local<v8::Context> context,
49
+ void* priv);
50
+
51
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
52
+ SET_NO_MEMORY_INFO()
53
+ SET_MEMORY_INFO_NAME(PipeWrap)
54
+ SET_SELF_SIZE(PipeWrap)
55
+
56
+ private:
57
+ PipeWrap(Environment* env,
58
+ v8::Local<v8::Object> object,
59
+ ProviderType provider,
60
+ bool ipc);
61
+
62
+ static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
63
+ static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args);
64
+ static void Listen(const v8::FunctionCallbackInfo<v8::Value>& args);
65
+ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args);
66
+ static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
67
+
68
+ #ifdef _WIN32
69
+ static void SetPendingInstances(
70
+ const v8::FunctionCallbackInfo<v8::Value>& args);
71
+ #endif
72
+ static void Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args);
73
+ };
74
+
75
+
76
+ } // namespace node
77
+
78
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
79
+
80
+ #endif // SRC_PIPE_WRAP_H_
@@ -0,0 +1,72 @@
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 <ngtcp2/ngtcp2.h>
8
+ #include <node_internals.h>
9
+ #include <v8.h>
10
+ #include <string>
11
+ #include "defs.h"
12
+
13
+ namespace node::quic {
14
+
15
+ // PreferredAddress is a helper class used only when a client Session receives
16
+ // an advertised preferred address from a server. The helper provides
17
+ // information about the server advertised preferred address and allows
18
+ // the preferred address to be selected.
19
+ class PreferredAddress final {
20
+ public:
21
+ enum class Policy : uint32_t {
22
+ // Ignore the server-advertised preferred address.
23
+ IGNORE_PREFERRED,
24
+ // Use the server-advertised preferred address.
25
+ USE_PREFERRED,
26
+ };
27
+
28
+ static v8::Maybe<Policy> tryGetPolicy(Environment* env,
29
+ v8::Local<v8::Value> value);
30
+
31
+ // The QUIC_* constants are expected to be exported out to be used on
32
+ // the JavaScript side of the API.
33
+ static constexpr auto PREFERRED_ADDRESS_USE =
34
+ static_cast<uint32_t>(Policy::USE_PREFERRED);
35
+ static constexpr auto PREFERRED_ADDRESS_IGNORE =
36
+ static_cast<uint32_t>(Policy::IGNORE_PREFERRED);
37
+ static constexpr auto DEFAULT_PREFERRED_ADDRESS_POLICY =
38
+ static_cast<uint32_t>(Policy::USE_PREFERRED);
39
+
40
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
41
+
42
+ struct AddressInfo final {
43
+ char host[NI_MAXHOST];
44
+ int family;
45
+ uint16_t port;
46
+ std::string_view address;
47
+ };
48
+
49
+ explicit PreferredAddress(ngtcp2_path* dest,
50
+ const ngtcp2_preferred_addr* paddr);
51
+ DISALLOW_COPY_AND_MOVE(PreferredAddress)
52
+
53
+ void Use(const AddressInfo& address);
54
+
55
+ std::optional<const AddressInfo> ipv4() const;
56
+ std::optional<const AddressInfo> ipv6() const;
57
+
58
+ // Set the preferred address in the transport params.
59
+ // The address family (ipv4 or ipv6) will be automatically
60
+ // detected from the given addr. Any other address family
61
+ // will be ignored.
62
+ static void Set(ngtcp2_transport_params* params, const sockaddr* addr);
63
+
64
+ private:
65
+ ngtcp2_path* dest_;
66
+ const ngtcp2_preferred_addr* paddr_;
67
+ };
68
+
69
+ } // namespace node::quic
70
+
71
+ #endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
72
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,27 @@
1
+ #ifndef SRC_INSPECTOR_PROTOCOL_HELPER_H_
2
+ #define SRC_INSPECTOR_PROTOCOL_HELPER_H_
3
+
4
+ #include "node/inspector/protocol/Protocol.h"
5
+ #include "util.h"
6
+ #include "v8-inspector.h"
7
+
8
+ namespace node::inspector {
9
+
10
+ // Convert a V8 string to v8_inspector StringBuffer, encoded in UTF16.
11
+ inline std::unique_ptr<v8_inspector::StringBuffer> ToInspectorString(
12
+ v8::Isolate* isolate, v8::Local<v8::Value> value) {
13
+ TwoByteValue buffer(isolate, value);
14
+ return v8_inspector::StringBuffer::create(
15
+ v8_inspector::StringView(*buffer, buffer.length()));
16
+ }
17
+
18
+ // Convert a V8 string to node::inspector::protocol::String, encoded in UTF8.
19
+ inline protocol::String ToProtocolString(v8::Isolate* isolate,
20
+ v8::Local<v8::Value> value) {
21
+ Utf8Value buffer(isolate, value);
22
+ return *buffer;
23
+ }
24
+
25
+ } // namespace node::inspector
26
+
27
+ #endif // SRC_INSPECTOR_PROTOCOL_HELPER_H_
@@ -0,0 +1,306 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #include <base_object.h>
6
+ #include <memory_tracker.h>
7
+ #include <node.h>
8
+ #include <node_bob.h>
9
+ #include <node_file.h>
10
+ #include <stream_base.h>
11
+ #include <uv.h>
12
+ #include <v8.h>
13
+
14
+ #include <memory>
15
+ #include <optional>
16
+ #include <vector>
17
+
18
+ namespace node {
19
+
20
+ // Represents a sequenced collection of data sources that can be
21
+ // consumed as a single logical stream of data. Sources can be
22
+ // memory-resident or streaming.
23
+ //
24
+ // There are two essential kinds of DataQueue:
25
+ //
26
+ // * Idempotent - Multiple reads always produce the same result.
27
+ // This is even the case if individual sources
28
+ // are not memory-resident. Reads never change
29
+ // the state of the DataQueue. Every entry in
30
+ // an Idempotent DataQueue must also be idempotent.
31
+ //
32
+ // * Non-idempotent - Reads are destructive of the internal state.
33
+ // A non-idempotent DataQueue can be read at
34
+ // most once and only by a single reader.
35
+ // Entries in a non-idempotent DataQueue can
36
+ // be a mix of idempotent and non-idempotent
37
+ // entries.
38
+ //
39
+ // The DataQueue is essentially a collection of DataQueue::Entry
40
+ // instances. A DataQueue::Entry is a single logical source of
41
+ // data. The data may be memory-resident or streaming. The entry
42
+ // can be idempotent or non-idempotent. An entry cannot be read
43
+ // by itself, it must be part of a DataQueue to be consumed.
44
+ //
45
+ // Example of creating an idempotent DataQueue:
46
+ //
47
+ // std::shared_ptr<v8::BackingStore> store1 = getBackingStoreSomehow();
48
+ // std::shared_ptr<v8::BackingStore> store2 = getBackingStoreSomehow();
49
+ //
50
+ // std::vector<std::unique_ptr<DataQueue::Entry>> list;
51
+ // list.push_back(DataQueue::CreateInMemoryEntryFromBackingStore(
52
+ // store1, 0, len1));
53
+ // list.push_back(DataQueue::CreateInMemoryEntryFromBackingStore(
54
+ // store2, 0, len2));
55
+ //
56
+ // std::shared_ptr<DataQueue> data_queue =
57
+ // DataQueue::CreateIdempotent(std::move(list));
58
+ //
59
+ // Importantly, idempotent DataQueue's are immutable and all entries
60
+ // must be provided when the DataQueue is constructed. Every entry
61
+ // must be idempotent with known sizes. The entries may be memory
62
+ // resident or streaming. Streaming entries must be capable of
63
+ // being read multiple times.
64
+ //
65
+ // Because idempotent DataQueue's will always produce the same results
66
+ // when read, they can be sliced. Slices yield a new DataQueue instance
67
+ // that is a subset view over the original:
68
+ //
69
+ // std::shared_ptr<DataQueue> slice = data_queue.slice(
70
+ // 5, v8::Just(10UL));
71
+ //
72
+ // Example of creating a non-idempotent DataQueue:
73
+ //
74
+ // std::shared_ptr<v8::BackingStore> store1 = getBackingStoreSomehow();
75
+ // std::shared_ptr<v8::BackingStore> store2 = getBackingStoreSomehow();
76
+ //
77
+ // std::shared_ptr<DataQueue> data_queue = DataQueue::Create();
78
+ //
79
+ // data_queue->append(DataQueue::CreateInMemoryEntryFromBackingStore(
80
+ // store1, 0, len1));
81
+ //
82
+ // data_queue->append(DataQueue::CreateInMemoryEntryFromBackingStore(
83
+ // store2, 0, len2));
84
+ //
85
+ // These data-queues can have new entries appended to them. Entries can
86
+ // be memory-resident or streaming. Streaming entries might not have
87
+ // a known size. Entries may not be capable of being read multiple
88
+ // times.
89
+ //
90
+ // A non-idempotent data queue will, by default, allow any amount of
91
+ // entries to be appended to it. To limit the size of the DataQueue,
92
+ // or the close the DataQueue (preventing new entries from being
93
+ // appending), use the cap() method. The DataQueue can be capped
94
+ // at a specific size or whatever size it currently it.
95
+ //
96
+ // It might not be possible for a non-idempotent DataQueue to provide
97
+ // a size because it might not know how much data a streaming entry
98
+ // will ultimately provide.
99
+ //
100
+ // Non-idempotent DataQueues cannot be sliced.
101
+ //
102
+ // To read from a DataQueue, we use the node::bob::Source API
103
+ // (see src/node_bob.h).
104
+ //
105
+ // std::shared_ptr<DataQueue::Reader> reader = data_queue->get_reader();
106
+ //
107
+ // reader->Pull(
108
+ // [](int status, const DataQueue::Vec* vecs,
109
+ // uint64_t count, Done done) {
110
+ // // status is one of node::bob::Status
111
+ // // vecs is zero or more data buffers containing the read data
112
+ // // count is the number of vecs
113
+ // // done is a callback to be invoked when done processing the data
114
+ // }, options, nullptr, 0, 16);
115
+ //
116
+ // Keep calling Pull() until status is equal to node::bob::Status::STATUS_EOS.
117
+ //
118
+ // For idempotent DataQueues, any number of readers can be created and
119
+ // pull concurrently from the same DataQueue. The DataQueue can be read
120
+ // multiple times. Successful reads should always produce the same result.
121
+ // If, for whatever reason, the implementation cannot ensure that the
122
+ // data read will remain the same, the read must fail with an error status.
123
+ //
124
+ // For non-idempotent DataQueues, only a single reader is ever allowed for
125
+ // the DataQueue, and the data can only ever be read once.
126
+
127
+ class DataQueue : public MemoryRetainer {
128
+ public:
129
+ struct Vec {
130
+ uint8_t* base;
131
+ uint64_t len;
132
+ };
133
+
134
+ // A DataQueue::Reader consumes the DataQueue. If the data queue is
135
+ // idempotent, multiple Readers can be attached to the DataQueue at
136
+ // any given time, all guaranteed to yield the same result when the
137
+ // data is read. Otherwise, only a single Reader can be attached.
138
+ class Reader : public MemoryRetainer, public bob::Source<Vec> {
139
+ public:
140
+ using Next = bob::Next<Vec>;
141
+ using Done = bob::Done;
142
+ };
143
+
144
+ // A BackpressureListener can be used to receive notifications
145
+ // when a non-idempotent DataQueue releases entries as they
146
+ // are consumed.
147
+ class BackpressureListener {
148
+ public:
149
+ virtual void EntryRead(size_t amount) = 0;
150
+ };
151
+
152
+ // A DataQueue::Entry represents a logical chunk of data in the queue.
153
+ // The entry may or may not represent memory-resident data. It may
154
+ // or may not be consumable more than once.
155
+ class Entry : public MemoryRetainer {
156
+ public:
157
+ // Returns a new Entry that is a view over this entries data
158
+ // from the start offset to the ending offset. If the end
159
+ // offset is omitted, the slice extends to the end of the
160
+ // data.
161
+ //
162
+ // Creating a slice is only possible if is_idempotent() returns
163
+ // true. This is because consuming either the original entry or
164
+ // the new entry would change the state of the other in non-
165
+ // deterministic ways. When is_idempotent() returns false, slice()
166
+ // must return a nulled unique_ptr.
167
+ //
168
+ // Creating a slice is also only possible if the size of the
169
+ // entry is known. If size() returns std::nullopt, slice()
170
+ // must return a nulled unique_ptr.
171
+ virtual std::unique_ptr<Entry> slice(
172
+ uint64_t start, std::optional<uint64_t> end = std::nullopt) = 0;
173
+
174
+ // Returns the number of bytes represented by this Entry if it is
175
+ // known. Certain types of entries, such as those backed by streams
176
+ // might not know the size in advance and therefore cannot provide
177
+ // a value. In such cases, size() must return v8::Nothing<uint64_t>.
178
+ //
179
+ // If the entry is idempotent, a size should always be available.
180
+ virtual std::optional<uint64_t> size() const = 0;
181
+
182
+ // When true, multiple reads on the object must produce the exact
183
+ // same data or the reads will fail. Some sources of entry data,
184
+ // such as streams, may not be capable of preserving idempotency
185
+ // and therefore must not claim to be. If an entry claims to be
186
+ // idempotent and cannot preserve that quality, subsequent reads
187
+ // must fail with an error when a variance is detected.
188
+ virtual bool is_idempotent() const = 0;
189
+ };
190
+
191
+ // Creates an idempotent DataQueue with a pre-established collection
192
+ // of entries. All of the entries must also be idempotent otherwise
193
+ // an empty std::unique_ptr will be returned.
194
+ static std::shared_ptr<DataQueue> CreateIdempotent(
195
+ std::vector<std::unique_ptr<Entry>> list);
196
+
197
+ // Creates a non-idempotent DataQueue. This kind of queue can be
198
+ // mutated and updated such that multiple reads are not guaranteed
199
+ // to produce the same result. The entries added can be of any type.
200
+ static std::shared_ptr<DataQueue> Create(
201
+ std::optional<uint64_t> capped = std::nullopt);
202
+
203
+ // Creates an idempotent Entry from a v8::ArrayBufferView. To help
204
+ // ensure idempotency, the underlying ArrayBuffer is detached from
205
+ // the BackingStore. It is the callers responsibility to ensure that
206
+ // the BackingStore is not otherwise modified through any other
207
+ // means. If the ArrayBuffer is not detachable, nullptr will be
208
+ // returned.
209
+ static std::unique_ptr<Entry> CreateInMemoryEntryFromView(
210
+ v8::Local<v8::ArrayBufferView> view);
211
+
212
+ // Creates an idempotent Entry from a v8::BackingStore. It is the
213
+ // callers responsibility to ensure that the BackingStore is not
214
+ // otherwise modified through any other means. If the ArrayBuffer
215
+ // is not detachable, nullptr will be returned.
216
+ static std::unique_ptr<Entry> CreateInMemoryEntryFromBackingStore(
217
+ std::shared_ptr<v8::BackingStore> store,
218
+ uint64_t offset,
219
+ uint64_t length);
220
+
221
+ static std::unique_ptr<Entry> CreateDataQueueEntry(
222
+ std::shared_ptr<DataQueue> data_queue);
223
+
224
+ static std::unique_ptr<Entry> CreateFdEntry(Environment* env,
225
+ v8::Local<v8::Value> path);
226
+
227
+ // Creates a Reader for the given queue. If the queue is idempotent,
228
+ // any number of readers can be created, all of which are guaranteed
229
+ // to provide the same data. Otherwise, only a single reader is
230
+ // permitted.
231
+ virtual std::shared_ptr<Reader> get_reader() = 0;
232
+
233
+ // Append a single new entry to the queue. Appending is only allowed
234
+ // when is_idempotent() is false. std::nullopt will be returned
235
+ // if is_idempotent() is true. std::optional(false) will be returned if the
236
+ // data queue is not idempotent but the entry otherwise cannot be added.
237
+ virtual std::optional<bool> append(std::unique_ptr<Entry> entry) = 0;
238
+
239
+ // Caps the size of this DataQueue preventing additional entries to
240
+ // be added if those cause the size to extend beyond the specified
241
+ // limit.
242
+ //
243
+ // If limit is zero, or is less than the known current size of the
244
+ // data queue, the limit is set to the current known size, meaning
245
+ // that no additional entries can be added at all.
246
+ //
247
+ // If the size of the data queue is not known, the limit will be
248
+ // ignored and no additional entries will be allowed at all.
249
+ //
250
+ // If is_idempotent is true capping is unnecessary because the data
251
+ // queue cannot be appended to. In that case, cap() is a non-op.
252
+ //
253
+ // If the data queue has already been capped, cap can be called
254
+ // again with a smaller size.
255
+ virtual void cap(uint64_t limit = 0) = 0;
256
+
257
+ // Returns a new DataQueue that is a view over this queues data
258
+ // from the start offset to the ending offset. If the end offset
259
+ // is omitted, the slice extends to the end of the data.
260
+ //
261
+ // The slice will coverage a range from start up to, but excluding, end.
262
+ //
263
+ // Creating a slice is only possible if is_idempotent() returns
264
+ // true. This is because consuming either the original DataQueue or
265
+ // the new queue would change the state of the other in non-
266
+ // deterministic ways. When is_idempotent() returns false, slice()
267
+ // must return a nulled unique_ptr.
268
+ //
269
+ // Creating a slice is also only possible if the size of the
270
+ // DataQueue is known. If size() returns std::nullopt, slice()
271
+ // must return a null unique_ptr.
272
+ virtual std::shared_ptr<DataQueue> slice(
273
+ uint64_t start, std::optional<uint64_t> end = std::nullopt) = 0;
274
+
275
+ // The size of DataQueue is the total size of all of its member entries.
276
+ // If any of the entries is not able to specify a size, the DataQueue
277
+ // will also be incapable of doing so, in which case size() must return
278
+ // std::nullopt.
279
+ virtual std::optional<uint64_t> size() const = 0;
280
+
281
+ // A DataQueue is idempotent only if all of its member entries are
282
+ // idempotent.
283
+ virtual bool is_idempotent() const = 0;
284
+
285
+ // True only if cap is called or the data queue is a limited to a
286
+ // fixed size.
287
+ virtual bool is_capped() const = 0;
288
+
289
+ // If the data queue has been capped, and the size of the data queue
290
+ // is known, maybeCapRemaining will return the number of additional
291
+ // bytes the data queue can receive before reaching the cap limit.
292
+ // If the size of the queue cannot be known, or the cap has not
293
+ // been set, maybeCapRemaining() will return std::nullopt.
294
+ virtual std::optional<uint64_t> maybeCapRemaining() const = 0;
295
+
296
+ // BackpressureListeners only work on non-idempotent DataQueues.
297
+ virtual void addBackpressureListener(BackpressureListener* listener) = 0;
298
+ virtual void removeBackpressureListener(BackpressureListener* listener) = 0;
299
+
300
+ static void Initialize(Environment* env, v8::Local<v8::Object> target);
301
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
302
+ };
303
+
304
+ } // namespace node
305
+
306
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS