@encharm/cws 4.5.3 → 4.8.0
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.
- package/CHANGELOG.md +18 -0
- package/CLAUDE.md +83 -0
- package/README.md +20 -4
- package/binding.gyp +8 -2
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +15 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +16 -2
- package/dist/shared.d.ts +1 -0
- package/dist/shared.js +3 -2
- package/package.json +1 -1
- package/src/Addon.cpp +4 -1
- package/src/Addon.h +80 -15
- package/src/Extensions.cpp +7 -1
- package/src/Extensions.h +2 -1
- package/src/Group.cpp +1 -1
- package/src/Group.h +4 -1
- package/src/HTTPSocket.cpp +1 -1
- package/src/Hub.cpp +11 -76
- package/src/Hub.h +12 -10
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +8 -5
- package/src/Zlib.cpp +138 -0
- package/src/Zlib.h +38 -0
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node115.node.yml +0 -931
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Info.plist +0 -20
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/DWARF/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node.dSYM/Contents/Resources/Relocations/aarch64/cws_darwin_arm64_node127.node.yml +0 -931
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
#ifndef SRC_NODE_SOCKADDR_H_
|
|
2
|
+
#define SRC_NODE_SOCKADDR_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "base_object.h"
|
|
7
|
+
#include "env.h"
|
|
8
|
+
#include "memory_tracker.h"
|
|
9
|
+
#include "node.h"
|
|
10
|
+
#include "node_worker.h"
|
|
11
|
+
#include "uv.h"
|
|
12
|
+
#include "v8.h"
|
|
13
|
+
|
|
14
|
+
#include <compare>
|
|
15
|
+
#include <list>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <unordered_map>
|
|
19
|
+
|
|
20
|
+
namespace node {
|
|
21
|
+
|
|
22
|
+
class Environment;
|
|
23
|
+
|
|
24
|
+
class SocketAddress : public MemoryRetainer {
|
|
25
|
+
public:
|
|
26
|
+
struct Hash {
|
|
27
|
+
size_t operator()(const SocketAddress& addr) const;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Hashes and compares only the IP address, ignoring the port.
|
|
31
|
+
// Useful for per-host connection counting where clients from
|
|
32
|
+
// the same IP but different ports should be treated as one host.
|
|
33
|
+
struct IpHash {
|
|
34
|
+
size_t operator()(const SocketAddress& addr) const;
|
|
35
|
+
};
|
|
36
|
+
struct IpEqual {
|
|
37
|
+
bool operator()(const SocketAddress& a, const SocketAddress& b) const;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
inline bool operator==(const SocketAddress& other) const;
|
|
41
|
+
inline bool operator!=(const SocketAddress& other) const;
|
|
42
|
+
|
|
43
|
+
inline std::partial_ordering operator<=>(const SocketAddress& other) const;
|
|
44
|
+
|
|
45
|
+
inline static bool is_numeric_host(const char* hostname);
|
|
46
|
+
inline static bool is_numeric_host(const char* hostname, int family);
|
|
47
|
+
|
|
48
|
+
// Returns true if converting {family, host, port} to *addr succeeded.
|
|
49
|
+
static bool ToSockAddr(int32_t family,
|
|
50
|
+
const char* host,
|
|
51
|
+
uint32_t port,
|
|
52
|
+
sockaddr_storage* addr);
|
|
53
|
+
|
|
54
|
+
// Returns true if converting {family, host, port} to *addr succeeded.
|
|
55
|
+
static bool New(int32_t family,
|
|
56
|
+
const char* host,
|
|
57
|
+
uint32_t port,
|
|
58
|
+
SocketAddress* addr);
|
|
59
|
+
|
|
60
|
+
static bool New(const char* host, uint32_t port, SocketAddress* addr);
|
|
61
|
+
|
|
62
|
+
// Returns the port for an IPv4 or IPv6 address.
|
|
63
|
+
inline static int GetPort(const sockaddr* addr);
|
|
64
|
+
inline static int GetPort(const sockaddr_storage* addr);
|
|
65
|
+
|
|
66
|
+
// Returns the numeric host as a string for an IPv4 or IPv6 address.
|
|
67
|
+
inline static std::string GetAddress(const sockaddr* addr);
|
|
68
|
+
inline static std::string GetAddress(const sockaddr_storage* addr);
|
|
69
|
+
|
|
70
|
+
// Returns the struct length for an IPv4, IPv6 or UNIX domain.
|
|
71
|
+
inline static size_t GetLength(const sockaddr* addr);
|
|
72
|
+
inline static size_t GetLength(const sockaddr_storage* addr);
|
|
73
|
+
|
|
74
|
+
SocketAddress() = default;
|
|
75
|
+
|
|
76
|
+
inline explicit SocketAddress(const sockaddr* addr);
|
|
77
|
+
inline SocketAddress(const SocketAddress& addr);
|
|
78
|
+
inline SocketAddress& operator=(const sockaddr* other);
|
|
79
|
+
inline SocketAddress& operator=(const SocketAddress& other);
|
|
80
|
+
|
|
81
|
+
inline const sockaddr& operator*() const;
|
|
82
|
+
inline const sockaddr* operator->() const;
|
|
83
|
+
|
|
84
|
+
inline const sockaddr* data() const;
|
|
85
|
+
inline const uint8_t* raw() const;
|
|
86
|
+
inline sockaddr* storage();
|
|
87
|
+
inline size_t length() const;
|
|
88
|
+
|
|
89
|
+
inline int family() const;
|
|
90
|
+
inline std::string address() const;
|
|
91
|
+
inline int port() const;
|
|
92
|
+
|
|
93
|
+
// Returns true if the given other SocketAddress is a match
|
|
94
|
+
// for this one. The addresses are a match if:
|
|
95
|
+
// 1. They are the same family and match identically
|
|
96
|
+
// 2. They are different family but match semantically (
|
|
97
|
+
// for instance, an IPv4 address in IPv6 notation)
|
|
98
|
+
bool is_match(const SocketAddress& other) const;
|
|
99
|
+
|
|
100
|
+
// Compares this SocketAddress to the given other SocketAddress.
|
|
101
|
+
std::partial_ordering compare(const SocketAddress& other) const;
|
|
102
|
+
|
|
103
|
+
// Returns true if this SocketAddress is within the subnet
|
|
104
|
+
// identified by the given network address and CIDR prefix.
|
|
105
|
+
bool is_in_network(const SocketAddress& network, int prefix) const;
|
|
106
|
+
|
|
107
|
+
// If the SocketAddress is an IPv6 address, returns the
|
|
108
|
+
// current value of the IPv6 flow label, if set. Otherwise
|
|
109
|
+
// returns 0.
|
|
110
|
+
inline uint32_t flow_label() const;
|
|
111
|
+
|
|
112
|
+
// If the SocketAddress is an IPv6 address, sets the
|
|
113
|
+
// current value of the IPv6 flow label. If not an
|
|
114
|
+
// IPv6 address, set_flow_label is a non-op. It
|
|
115
|
+
// is important to note that the flow label,
|
|
116
|
+
// while represented as an uint32_t, the flow
|
|
117
|
+
// label is strictly limited to 20 bits, and
|
|
118
|
+
// this will assert if any value larger than
|
|
119
|
+
// 20-bits is specified.
|
|
120
|
+
inline void set_flow_label(uint32_t label = 0);
|
|
121
|
+
|
|
122
|
+
inline void Update(uint8_t* data, size_t len);
|
|
123
|
+
inline void Update(const sockaddr* data, size_t len);
|
|
124
|
+
|
|
125
|
+
static SocketAddress FromSockName(const uv_udp_t& handle);
|
|
126
|
+
static SocketAddress FromSockName(const uv_tcp_t& handle);
|
|
127
|
+
static SocketAddress FromPeerName(const uv_udp_t& handle);
|
|
128
|
+
static SocketAddress FromPeerName(const uv_tcp_t& handle);
|
|
129
|
+
|
|
130
|
+
inline v8::MaybeLocal<v8::Object> ToJS(
|
|
131
|
+
Environment* env,
|
|
132
|
+
v8::Local<v8::Object> obj = v8::Local<v8::Object>()) const;
|
|
133
|
+
|
|
134
|
+
inline std::string ToString() const;
|
|
135
|
+
|
|
136
|
+
SET_NO_MEMORY_INFO()
|
|
137
|
+
SET_MEMORY_INFO_NAME(SocketAddress)
|
|
138
|
+
SET_SELF_SIZE(SocketAddress)
|
|
139
|
+
|
|
140
|
+
template <typename T>
|
|
141
|
+
using Map = std::unordered_map<SocketAddress, T, Hash>;
|
|
142
|
+
|
|
143
|
+
template <typename T>
|
|
144
|
+
using IpMap = std::unordered_map<SocketAddress, T, IpHash, IpEqual>;
|
|
145
|
+
|
|
146
|
+
private:
|
|
147
|
+
sockaddr_storage address_;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
class SocketAddressBase : public BaseObject {
|
|
151
|
+
public:
|
|
152
|
+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
|
|
153
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
154
|
+
Environment* env);
|
|
155
|
+
static void Initialize(Environment* env, v8::Local<v8::Object> target);
|
|
156
|
+
static BaseObjectPtr<SocketAddressBase> Create(
|
|
157
|
+
Environment* env, std::shared_ptr<SocketAddress> address);
|
|
158
|
+
|
|
159
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
160
|
+
static void Detail(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
161
|
+
static void LegacyDetail(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
162
|
+
static void GetFlowLabel(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
163
|
+
|
|
164
|
+
SocketAddressBase(Environment* env,
|
|
165
|
+
v8::Local<v8::Object> wrap,
|
|
166
|
+
std::shared_ptr<SocketAddress> address);
|
|
167
|
+
|
|
168
|
+
inline const std::shared_ptr<SocketAddress>& address() const {
|
|
169
|
+
return address_;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
173
|
+
SET_MEMORY_INFO_NAME(SocketAddressBase)
|
|
174
|
+
SET_SELF_SIZE(SocketAddressBase)
|
|
175
|
+
|
|
176
|
+
BaseObject::TransferMode GetTransferMode() const override {
|
|
177
|
+
return TransferMode::kCloneable;
|
|
178
|
+
}
|
|
179
|
+
std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
|
|
180
|
+
|
|
181
|
+
class TransferData : public worker::TransferData {
|
|
182
|
+
public:
|
|
183
|
+
inline explicit TransferData(const SocketAddressBase* wrap)
|
|
184
|
+
: address_(wrap->address_) {}
|
|
185
|
+
|
|
186
|
+
inline explicit TransferData(std::shared_ptr<SocketAddress> address)
|
|
187
|
+
: address_(std::move(address)) {}
|
|
188
|
+
|
|
189
|
+
BaseObjectPtr<BaseObject> Deserialize(
|
|
190
|
+
Environment* env,
|
|
191
|
+
v8::Local<v8::Context> context,
|
|
192
|
+
std::unique_ptr<worker::TransferData> self) override;
|
|
193
|
+
|
|
194
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
195
|
+
SET_MEMORY_INFO_NAME(SocketAddressBase::TransferData)
|
|
196
|
+
SET_SELF_SIZE(TransferData)
|
|
197
|
+
|
|
198
|
+
private:
|
|
199
|
+
std::shared_ptr<SocketAddress> address_;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
private:
|
|
203
|
+
std::shared_ptr<SocketAddress> address_;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
template <typename T>
|
|
207
|
+
class SocketAddressLRU : public MemoryRetainer {
|
|
208
|
+
public:
|
|
209
|
+
using Type = typename T::Type;
|
|
210
|
+
|
|
211
|
+
inline explicit SocketAddressLRU(size_t max_size);
|
|
212
|
+
|
|
213
|
+
// If the item already exists, returns a reference to
|
|
214
|
+
// the existing item, adjusting items position in the
|
|
215
|
+
// LRU. If the item does not exist, emplaces the item
|
|
216
|
+
// and returns the new item. The caller provides a
|
|
217
|
+
// timestamp to avoid redundant uv_hrtime() calls.
|
|
218
|
+
Type* Upsert(const SocketAddress& address, uint64_t now);
|
|
219
|
+
|
|
220
|
+
// Returns a reference to the item if it exists, or
|
|
221
|
+
// nullptr. The position in the LRU is not modified.
|
|
222
|
+
Type* Peek(const SocketAddress& address) const;
|
|
223
|
+
|
|
224
|
+
size_t size() const { return map_.size(); }
|
|
225
|
+
size_t max_size() const { return max_size_; }
|
|
226
|
+
|
|
227
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
228
|
+
SET_MEMORY_INFO_NAME(SocketAddressLRU)
|
|
229
|
+
SET_SELF_SIZE(SocketAddressLRU)
|
|
230
|
+
|
|
231
|
+
private:
|
|
232
|
+
using Pair = std::pair<SocketAddress, Type>;
|
|
233
|
+
using Iterator = typename std::list<Pair>::iterator;
|
|
234
|
+
|
|
235
|
+
void CheckExpired(uint64_t now);
|
|
236
|
+
|
|
237
|
+
std::list<Pair> list_;
|
|
238
|
+
SocketAddress::Map<Iterator> map_;
|
|
239
|
+
size_t max_size_;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// A BlockList is used to evaluate whether a given
|
|
243
|
+
// SocketAddress should be accepted for inbound or
|
|
244
|
+
// outbound network activity.
|
|
245
|
+
class SocketAddressBlockList : public MemoryRetainer {
|
|
246
|
+
public:
|
|
247
|
+
explicit SocketAddressBlockList(
|
|
248
|
+
std::shared_ptr<SocketAddressBlockList> parent = {});
|
|
249
|
+
~SocketAddressBlockList() = default;
|
|
250
|
+
|
|
251
|
+
void AddSocketAddress(const SocketAddress& address);
|
|
252
|
+
|
|
253
|
+
void AddSocketAddresses(const SocketAddress* addresses, size_t count);
|
|
254
|
+
|
|
255
|
+
void RemoveSocketAddress(const SocketAddress& address);
|
|
256
|
+
|
|
257
|
+
void AddSocketAddressRange(const SocketAddress& start,
|
|
258
|
+
const SocketAddress& end);
|
|
259
|
+
|
|
260
|
+
void RemoveSocketAddressRange(const SocketAddress& start,
|
|
261
|
+
const SocketAddress& end);
|
|
262
|
+
|
|
263
|
+
void AddSocketAddressMask(const SocketAddress& address, int prefix);
|
|
264
|
+
|
|
265
|
+
void RemoveSocketAddressMask(const SocketAddress& address, int prefix);
|
|
266
|
+
|
|
267
|
+
bool Apply(const SocketAddress& address);
|
|
268
|
+
|
|
269
|
+
void Clear();
|
|
270
|
+
|
|
271
|
+
size_t size() const {
|
|
272
|
+
return address_count_ + rules_.size() + subnet_rules_.size();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
v8::MaybeLocal<v8::Array> ListRules(Environment* env);
|
|
276
|
+
|
|
277
|
+
struct Rule : public MemoryRetainer {
|
|
278
|
+
virtual bool Apply(const SocketAddress& address) = 0;
|
|
279
|
+
inline v8::MaybeLocal<v8::Value> ToV8String(Environment* env);
|
|
280
|
+
virtual std::string ToString() = 0;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
struct SocketAddressRangeRule final : Rule {
|
|
284
|
+
SocketAddress start;
|
|
285
|
+
SocketAddress end;
|
|
286
|
+
|
|
287
|
+
SocketAddressRangeRule(const SocketAddress& start,
|
|
288
|
+
const SocketAddress& end);
|
|
289
|
+
|
|
290
|
+
bool Apply(const SocketAddress& address) override;
|
|
291
|
+
std::string ToString() override;
|
|
292
|
+
|
|
293
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
294
|
+
SET_MEMORY_INFO_NAME(SocketAddressRangeRule)
|
|
295
|
+
SET_SELF_SIZE(SocketAddressRangeRule)
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
struct SocketAddressMaskRule final : Rule {
|
|
299
|
+
SocketAddress network;
|
|
300
|
+
int prefix;
|
|
301
|
+
|
|
302
|
+
SocketAddressMaskRule(const SocketAddress& address, int prefix);
|
|
303
|
+
|
|
304
|
+
bool Apply(const SocketAddress& address) override;
|
|
305
|
+
std::string ToString() override;
|
|
306
|
+
|
|
307
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
308
|
+
SET_MEMORY_INFO_NAME(SocketAddressMaskRule)
|
|
309
|
+
SET_SELF_SIZE(SocketAddressMaskRule)
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
313
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockList)
|
|
314
|
+
SET_SELF_SIZE(SocketAddressBlockList)
|
|
315
|
+
|
|
316
|
+
// A compressed radix trie for O(prefix_length) subnet lookups.
|
|
317
|
+
// Each node has two children (bit 0, bit 1). A node marked
|
|
318
|
+
// terminal means all addresses matching the prefix up to that
|
|
319
|
+
// depth are blocked. On insert, if a new prefix is shorter than
|
|
320
|
+
// or equal to an existing one, the subtree is pruned (the shorter
|
|
321
|
+
// prefix subsumes all longer ones). On lookup, we walk the bits
|
|
322
|
+
// of the address and return true as soon as we hit a terminal node.
|
|
323
|
+
class SubnetTrie {
|
|
324
|
+
public:
|
|
325
|
+
SubnetTrie() = default;
|
|
326
|
+
~SubnetTrie() = default;
|
|
327
|
+
|
|
328
|
+
// Insert a subnet (network address bytes, prefix length in bits).
|
|
329
|
+
// If a broader prefix already exists, the insert is a no-op.
|
|
330
|
+
// If this prefix is broader than existing children, they are pruned.
|
|
331
|
+
void Insert(const uint8_t* address_bytes, int prefix_length);
|
|
332
|
+
|
|
333
|
+
// Returns true if the given address falls within any inserted subnet.
|
|
334
|
+
bool Lookup(const uint8_t* address_bytes, int address_bits) const;
|
|
335
|
+
|
|
336
|
+
// Remove all entries.
|
|
337
|
+
void Clear();
|
|
338
|
+
|
|
339
|
+
bool empty() const { return root_ == nullptr; }
|
|
340
|
+
|
|
341
|
+
size_t size() const { return count_; }
|
|
342
|
+
|
|
343
|
+
private:
|
|
344
|
+
struct Node {
|
|
345
|
+
std::unique_ptr<Node> children[2];
|
|
346
|
+
bool terminal = false;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
std::unique_ptr<Node> root_;
|
|
350
|
+
size_t count_ = 0;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
private:
|
|
354
|
+
// Lock-free implementation used by both AddSocketAddress and
|
|
355
|
+
// AddSocketAddresses. Caller must hold the write lock.
|
|
356
|
+
void AddSocketAddressImpl(const SocketAddress& address);
|
|
357
|
+
bool ListRules(Environment* env, v8::LocalVector<v8::Value>* vec);
|
|
358
|
+
|
|
359
|
+
std::shared_ptr<SocketAddressBlockList> parent_;
|
|
360
|
+
// Range rules only. Scanned linearly by Apply().
|
|
361
|
+
std::list<std::unique_ptr<Rule>> rules_;
|
|
362
|
+
// Exact address rules. Keyed by IP only (port-insensitive) so that
|
|
363
|
+
// Apply() can perform O(1) lookups regardless of the port on the
|
|
364
|
+
// checked address. Not included in rules_ to avoid redundant scanning.
|
|
365
|
+
SocketAddress::IpMap<SocketAddress> address_rules_;
|
|
366
|
+
// User-visible address count (not inflated by cross-family dual-insert).
|
|
367
|
+
size_t address_count_ = 0;
|
|
368
|
+
// Subnet/mask rules stored in radix tries for O(prefix_length) lookup.
|
|
369
|
+
// Separate tries for IPv4 (max 32-bit depth) and IPv6 (max 128-bit).
|
|
370
|
+
SubnetTrie ipv4_subnets_;
|
|
371
|
+
SubnetTrie ipv6_subnets_;
|
|
372
|
+
// Subnet metadata kept for ListRules serialization only.
|
|
373
|
+
std::list<std::unique_ptr<SocketAddressMaskRule>> subnet_rules_;
|
|
374
|
+
|
|
375
|
+
// RwLock allows concurrent Apply() calls (shared/read lock) while
|
|
376
|
+
// mutations (Add*/Remove*/Clear) take an exclusive/write lock.
|
|
377
|
+
mutable RwLock mutex_;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
class SocketAddressBlockListWrap : public BaseObject {
|
|
381
|
+
public:
|
|
382
|
+
static bool HasInstance(Environment* env, v8::Local<v8::Value> value);
|
|
383
|
+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
|
384
|
+
Environment* env);
|
|
385
|
+
static void Initialize(v8::Local<v8::Object> target,
|
|
386
|
+
v8::Local<v8::Value> unused,
|
|
387
|
+
v8::Local<v8::Context> context,
|
|
388
|
+
void* priv);
|
|
389
|
+
|
|
390
|
+
static BaseObjectPtr<SocketAddressBlockListWrap> New(Environment* env);
|
|
391
|
+
static BaseObjectPtr<SocketAddressBlockListWrap> New(
|
|
392
|
+
Environment* env, std::shared_ptr<SocketAddressBlockList> blocklist);
|
|
393
|
+
|
|
394
|
+
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
395
|
+
static void AddAddress(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
396
|
+
static void AddAddresses(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
397
|
+
static void AddRange(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
398
|
+
static void AddSubnet(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
399
|
+
static void RemoveAddress(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
400
|
+
static void RemoveRange(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
401
|
+
static void RemoveSubnet(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
402
|
+
static void Check(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
403
|
+
static bool FastCheck(v8::Local<v8::Object> receiver,
|
|
404
|
+
v8::Local<v8::Object> addr_obj);
|
|
405
|
+
static void CheckString(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
406
|
+
static void GetRules(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
407
|
+
static void GetSize(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
408
|
+
static void Clear(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
409
|
+
|
|
410
|
+
SocketAddressBlockListWrap(Environment* env,
|
|
411
|
+
v8::Local<v8::Object> wrap,
|
|
412
|
+
std::shared_ptr<SocketAddressBlockList> blocklist =
|
|
413
|
+
std::make_shared<SocketAddressBlockList>());
|
|
414
|
+
|
|
415
|
+
inline const std::shared_ptr<SocketAddressBlockList>& blocklist() const {
|
|
416
|
+
return blocklist_;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
420
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockListWrap)
|
|
421
|
+
SET_SELF_SIZE(SocketAddressBlockListWrap)
|
|
422
|
+
|
|
423
|
+
BaseObject::TransferMode GetTransferMode() const override {
|
|
424
|
+
return TransferMode::kCloneable;
|
|
425
|
+
}
|
|
426
|
+
std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
|
|
427
|
+
|
|
428
|
+
class TransferData : public worker::TransferData {
|
|
429
|
+
public:
|
|
430
|
+
inline explicit TransferData(const SocketAddressBlockListWrap* wrap)
|
|
431
|
+
: blocklist_(wrap->blocklist_) {}
|
|
432
|
+
|
|
433
|
+
inline explicit TransferData(
|
|
434
|
+
std::shared_ptr<SocketAddressBlockList> blocklist)
|
|
435
|
+
: blocklist_(std::move(blocklist)) {}
|
|
436
|
+
|
|
437
|
+
BaseObjectPtr<BaseObject> Deserialize(
|
|
438
|
+
Environment* env,
|
|
439
|
+
v8::Local<v8::Context> context,
|
|
440
|
+
std::unique_ptr<worker::TransferData> self) override;
|
|
441
|
+
|
|
442
|
+
void MemoryInfo(MemoryTracker* tracker) const override;
|
|
443
|
+
SET_MEMORY_INFO_NAME(SocketAddressBlockListWrap::TransferData)
|
|
444
|
+
SET_SELF_SIZE(TransferData)
|
|
445
|
+
|
|
446
|
+
private:
|
|
447
|
+
std::shared_ptr<SocketAddressBlockList> blocklist_;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
private:
|
|
451
|
+
std::shared_ptr<SocketAddressBlockList> blocklist_;
|
|
452
|
+
static v8::CFunction fast_check_;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
} // namespace node
|
|
456
|
+
|
|
457
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
458
|
+
|
|
459
|
+
#endif // SRC_NODE_SOCKADDR_H_
|