cache.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <util/network/socket.h>
  3. #include <util/generic/strbuf.h>
  4. #include <util/generic/string.h>
  5. namespace NDns {
  6. struct TResolveInfo {
  7. inline TResolveInfo(const TStringBuf& host, ui16 port)
  8. : Host(host)
  9. , Port(port)
  10. {
  11. }
  12. TStringBuf Host;
  13. ui16 Port;
  14. };
  15. struct TResolvedHost {
  16. inline TResolvedHost(const TString& host, const TNetworkAddress& addr) noexcept
  17. : Host(host)
  18. , Addr(addr)
  19. , Id(0)
  20. {
  21. }
  22. TString Host; //resolved hostname (from TResolveInfo, - before aliasing)
  23. TNetworkAddress Addr;
  24. size_t Id; //cache record id
  25. };
  26. // Resolving order:
  27. // 1. check local thread cache, return if found
  28. // 2. check global cache, return if found
  29. // 3. search alias for hostname, if found, continue resolving alias
  30. // 4. normal resolver
  31. const TResolvedHost* CachedResolve(const TResolveInfo& ri);
  32. //like previous, but at stage 4 use separate thread for resolving (created on first usage)
  33. //useful in green-threads with tiny stack
  34. const TResolvedHost* CachedThrResolve(const TResolveInfo& ri);
  35. //create alias for host, which can be used for static resolving (when alias is ip address)
  36. void AddHostAlias(const TString& host, const TString& alias);
  37. }