diff options
author | James M Snell <jasnell@gmail.com> | 2021-03-25 13:27:03 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-04-02 06:16:42 -0700 |
commit | e79471deb7b5c91f061bf395bbef9816e26b4bf9 (patch) | |
tree | 4fd83036cf9e667f16324bb733955aee1aed34b1 /src/node_sockaddr.h | |
parent | 0b90d352948393e5f92ceb2ef749c643b1002a68 (diff) | |
download | node-new-e79471deb7b5c91f061bf395bbef9816e26b4bf9.tar.gz |
net: allow net.BlockList to use net.SocketAddress objects
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/37917
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/node_sockaddr.h')
-rw-r--r-- | src/node_sockaddr.h | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/node_sockaddr.h b/src/node_sockaddr.h index 62dcab6bad..704fe0c511 100644 --- a/src/node_sockaddr.h +++ b/src/node_sockaddr.h @@ -168,6 +168,10 @@ class SocketAddressBase : public BaseObject { v8::Local<v8::Object> wrap, std::shared_ptr<SocketAddress> address); + inline const std::shared_ptr<SocketAddress>& address() const { + return address_; + } + void MemoryInfo(MemoryTracker* tracker) const override; SET_MEMORY_INFO_NAME(SocketAddressBase); SET_SELF_SIZE(SocketAddressBase); @@ -246,38 +250,36 @@ class SocketAddressBlockList : public MemoryRetainer { std::shared_ptr<SocketAddressBlockList> parent = {}); ~SocketAddressBlockList() = default; - void AddSocketAddress( - const SocketAddress& address); + void AddSocketAddress(const std::shared_ptr<SocketAddress>& address); - void RemoveSocketAddress( - const SocketAddress& address); + void RemoveSocketAddress(const std::shared_ptr<SocketAddress>& address); void AddSocketAddressRange( - const SocketAddress& start, - const SocketAddress& end); + const std::shared_ptr<SocketAddress>& start, + const std::shared_ptr<SocketAddress>& end); void AddSocketAddressMask( - const SocketAddress& address, + const std::shared_ptr<SocketAddress>& address, int prefix); - bool Apply(const SocketAddress& address); + bool Apply(const std::shared_ptr<SocketAddress>& address); size_t size() const { return rules_.size(); } v8::MaybeLocal<v8::Array> ListRules(Environment* env); struct Rule : public MemoryRetainer { - virtual bool Apply(const SocketAddress& address) = 0; + virtual bool Apply(const std::shared_ptr<SocketAddress>& address) = 0; inline v8::MaybeLocal<v8::Value> ToV8String(Environment* env); virtual std::string ToString() = 0; }; struct SocketAddressRule final : Rule { - SocketAddress address; + std::shared_ptr<SocketAddress> address; - explicit SocketAddressRule(const SocketAddress& address); + explicit SocketAddressRule(const std::shared_ptr<SocketAddress>& address); - bool Apply(const SocketAddress& address) override; + bool Apply(const std::shared_ptr<SocketAddress>& address) override; std::string ToString() override; void MemoryInfo(node::MemoryTracker* tracker) const override; @@ -286,14 +288,14 @@ class SocketAddressBlockList : public MemoryRetainer { }; struct SocketAddressRangeRule final : Rule { - SocketAddress start; - SocketAddress end; + std::shared_ptr<SocketAddress> start; + std::shared_ptr<SocketAddress> end; SocketAddressRangeRule( - const SocketAddress& start, - const SocketAddress& end); + const std::shared_ptr<SocketAddress>& start, + const std::shared_ptr<SocketAddress>& end); - bool Apply(const SocketAddress& address) override; + bool Apply(const std::shared_ptr<SocketAddress>& address) override; std::string ToString() override; void MemoryInfo(node::MemoryTracker* tracker) const override; @@ -302,14 +304,14 @@ class SocketAddressBlockList : public MemoryRetainer { }; struct SocketAddressMaskRule final : Rule { - SocketAddress network; + std::shared_ptr<SocketAddress> network; int prefix; SocketAddressMaskRule( - const SocketAddress& address, + const std::shared_ptr<SocketAddress>& address, int prefix); - bool Apply(const SocketAddress& address) override; + bool Apply(const std::shared_ptr<SocketAddress>& address) override; std::string ToString() override; void MemoryInfo(node::MemoryTracker* tracker) const override; |