diff options
author | James M Snell <jasnell@gmail.com> | 2020-08-05 02:03:30 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2020-08-11 21:13:17 +0300 |
commit | 1f9b20b6376e0949807729ef46727a4fafad7f1d (patch) | |
tree | 3448933182ca47dd949e93ead90a25a65d8272df /src/node_sockaddr-inl.h | |
parent | 6e1f6ec57398689740ab29acb6ce49bc94b95c79 (diff) |
net: introduce net.BlockList
`net.BlockList` provides an object intended to be used by net APIs to
specify rules for disallowing network activity with specific IP
addresses. This commit adds the basic mechanism but does not add the
specific uses.
PR-URL: https://github.com/nodejs/node/pull/34625
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Diffstat (limited to 'src/node_sockaddr-inl.h')
-rw-r--r-- | src/node_sockaddr-inl.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/node_sockaddr-inl.h b/src/node_sockaddr-inl.h index c8b985aedda..e5d8985771e 100644 --- a/src/node_sockaddr-inl.h +++ b/src/node_sockaddr-inl.h @@ -4,6 +4,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "node.h" +#include "env-inl.h" #include "node_internals.h" #include "node_sockaddr.h" #include "util-inl.h" @@ -88,11 +89,11 @@ SocketAddress& SocketAddress::operator=(const SocketAddress& addr) { } const sockaddr& SocketAddress::operator*() const { - return *this->data(); + return *data(); } const sockaddr* SocketAddress::operator->() const { - return this->data(); + return data(); } size_t SocketAddress::length() const { @@ -166,6 +167,24 @@ bool SocketAddress::operator!=(const SocketAddress& other) const { return !(*this == other); } +bool SocketAddress::operator<(const SocketAddress& other) const { + return compare(other) == CompareResult::LESS_THAN; +} + +bool SocketAddress::operator>(const SocketAddress& other) const { + return compare(other) == CompareResult::GREATER_THAN; +} + +bool SocketAddress::operator<=(const SocketAddress& other) const { + CompareResult c = compare(other); + return c == CompareResult::NOT_COMPARABLE ? false : + c <= CompareResult::SAME; +} + +bool SocketAddress::operator>=(const SocketAddress& other) const { + return compare(other) >= CompareResult::SAME; +} + template <typename T> SocketAddressLRU<T>::SocketAddressLRU( size_t max_size) @@ -231,6 +250,11 @@ typename T::Type* SocketAddressLRU<T>::Upsert( return &map_[address]->second; } +v8::MaybeLocal<v8::Value> SocketAddressBlockList::Rule::ToV8String( + Environment* env) { + std::string str = ToString(); + return ToV8Value(env->context(), str); +} } // namespace node #endif // NODE_WANT_INTERNALS |