diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | 6170310e8721e225f64ddabf7a7358253d7a1249 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/messagebus/config | |
parent | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (diff) | |
download | ydb-6170310e8721e225f64ddabf7a7358253d7a1249.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/config')
-rw-r--r-- | library/cpp/messagebus/config/netaddr.cpp | 32 | ||||
-rw-r--r-- | library/cpp/messagebus/config/netaddr.h | 28 |
2 files changed, 30 insertions, 30 deletions
diff --git a/library/cpp/messagebus/config/netaddr.cpp b/library/cpp/messagebus/config/netaddr.cpp index f82378c345..962ac538e2 100644 --- a/library/cpp/messagebus/config/netaddr.cpp +++ b/library/cpp/messagebus/config/netaddr.cpp @@ -4,7 +4,7 @@ #include <cstdlib> -namespace NBus { +namespace NBus { const char* ToCString(EIpVersion ipVersion) { switch (ipVersion) { case EIP_VERSION_ANY: @@ -37,12 +37,12 @@ namespace NBus { { } }; - + static bool Compare(const IRemoteAddr& l, const IRemoteAddr& r) noexcept { if (l.Addr()->sa_family != r.Addr()->sa_family) { return false; } - + switch (l.Addr()->sa_family) { case AF_INET: { return memcmp(&(((const sockaddr_in*)l.Addr())->sin_addr), &(((const sockaddr_in*)r.Addr())->sin_addr), sizeof(in_addr)) == 0 && @@ -53,25 +53,25 @@ namespace NBus { return memcmp(&(((const sockaddr_in6*)l.Addr())->sin6_addr), &(((const sockaddr_in6*)r.Addr())->sin6_addr), sizeof(in6_addr)) == 0 && ((const sockaddr_in6*)l.Addr())->sin6_port == ((const sockaddr_in6*)r.Addr())->sin6_port; } - } - + } + return memcmp(l.Addr(), r.Addr(), Min<size_t>(l.Len(), r.Len())) == 0; - } - + } + TNetAddr::TNetAddr() : Ptr(new TOpaqueAddr) { } - + TNetAddr::TNetAddr(TAutoPtr<IRemoteAddr> addr) : Ptr(addr) { Y_VERIFY(!!Ptr); } - + namespace { using namespace NAddr; - + const char* Describe(EIpVersion version) { switch (version) { case EIP_VERSION_4: @@ -150,7 +150,7 @@ namespace NBus { socklen_t TNetAddr::Len() const { return Ptr->Len(); } - + int TNetAddr::GetPort() const { switch (Ptr->Addr()->sa_family) { case AF_INET: @@ -162,11 +162,11 @@ namespace NBus { throw 1; } } - + bool TNetAddr::IsIpv4() const { return Ptr->Addr()->sa_family == AF_INET; } - + bool TNetAddr::IsIpv6() const { return Ptr->Addr()->sa_family == AF_INET6; } @@ -177,7 +177,7 @@ namespace NBus { } -template <> +template <> void Out<NBus::TNetAddr>(IOutputStream& out, const NBus::TNetAddr& addr) { - Out<NAddr::IRemoteAddr>(out, addr); -} + Out<NAddr::IRemoteAddr>(out, addr); +} diff --git a/library/cpp/messagebus/config/netaddr.h b/library/cpp/messagebus/config/netaddr.h index 2e40f1464b..b79c0cc355 100644 --- a/library/cpp/messagebus/config/netaddr.h +++ b/library/cpp/messagebus/config/netaddr.h @@ -1,22 +1,22 @@ -#pragma once - +#pragma once + #include <util/digest/numeric.h> #include <util/generic/hash.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/strbuf.h> -#include <util/generic/vector.h> -#include <util/network/address.h> - -namespace NBus { +#include <util/generic/vector.h> +#include <util/network/address.h> + +namespace NBus { using namespace NAddr; - + /// IP protocol version. enum EIpVersion { EIP_VERSION_4 = 1, EIP_VERSION_6 = 2, EIP_VERSION_ANY = EIP_VERSION_4 | EIP_VERSION_6, }; - + inline bool IsFamilyAllowed(ui16 sa_family, EIpVersion ipVersion) { if (ipVersion == EIP_VERSION_4 && sa_family != AF_INET) { return false; @@ -51,26 +51,26 @@ namespace NBus { inline explicit operator bool() const noexcept { return !!Ptr; } - + const sockaddr* Addr() const override; socklen_t Len() const override; - + bool IsIpv4() const; bool IsIpv6() const; int GetPort() const; - + private: TAtomicSharedPtr<IRemoteAddr> Ptr; }; using TSockAddrInVector = TVector<TNetAddr>; - + struct TNetAddrHostPortHash { inline size_t operator()(const TNetAddr& a) const { const sockaddr* s = a.Addr(); const sockaddr_in* const sa = reinterpret_cast<const sockaddr_in*>(s); const sockaddr_in6* const sa6 = reinterpret_cast<const sockaddr_in6*>(s); - + switch (s->sa_family) { case AF_INET: return CombineHashes<size_t>(ComputeHash(TStringBuf(reinterpret_cast<const char*>(&sa->sin_addr), sizeof(sa->sin_addr))), IntHashImpl(sa->sin_port)); |