aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/dns/cache.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/dns/cache.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/dns/cache.h')
-rw-r--r--library/cpp/dns/cache.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/library/cpp/dns/cache.h b/library/cpp/dns/cache.h
new file mode 100644
index 0000000000..eda5dc4070
--- /dev/null
+++ b/library/cpp/dns/cache.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <util/network/socket.h>
+#include <util/generic/strbuf.h>
+#include <util/generic/string.h>
+
+namespace NDns {
+ struct TResolveInfo {
+ inline TResolveInfo(const TStringBuf& host, ui16 port)
+ : Host(host)
+ , Port(port)
+ {
+ }
+
+ TStringBuf Host;
+ ui16 Port;
+ };
+
+ struct TResolvedHost {
+ inline TResolvedHost(const TString& host, const TNetworkAddress& addr) noexcept
+ : Host(host)
+ , Addr(addr)
+ , Id(0)
+ {
+ }
+
+ TString Host; //resolved hostname (from TResolveInfo, - before aliasing)
+ TNetworkAddress Addr;
+ size_t Id; //cache record id
+ };
+
+ // Resolving order:
+ // 1. check local thread cache, return if found
+ // 2. check global cache, return if found
+ // 3. search alias for hostname, if found, continue resolving alias
+ // 4. normal resolver
+ const TResolvedHost* CachedResolve(const TResolveInfo& ri);
+
+ //like previous, but at stage 4 use separate thread for resolving (created on first usage)
+ //useful in green-threads with tiny stack
+ const TResolvedHost* CachedThrResolve(const TResolveInfo& ri);
+
+ //create alias for host, which can be used for static resolving (when alias is ip address)
+ void AddHostAlias(const TString& host, const TString& alias);
+}