You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2021/07/13 22:01:49 UTC

[GitHub] [trafficserver] ywkaras commented on a change in pull request #7874: Hostdb restructuring

ywkaras commented on a change in pull request #7874:
URL: https://github.com/apache/trafficserver/pull/7874#discussion_r669139737



##########
File path: iocore/hostdb/HostDB.cc
##########
@@ -50,78 +54,214 @@ unsigned int hostdb_ip_stale_interval          = HOST_DB_IP_STALE;
 unsigned int hostdb_ip_timeout_interval        = HOST_DB_IP_TIMEOUT;
 unsigned int hostdb_ip_fail_timeout_interval   = HOST_DB_IP_FAIL_TIMEOUT;
 unsigned int hostdb_serve_stale_but_revalidate = 0;
-unsigned int hostdb_hostfile_check_interval    = 86400; // 1 day
+ts_seconds hostdb_hostfile_check_interval{std::chrono::hours(24)};
 // Epoch timestamp of the current hosts file check.
-ink_time_t hostdb_current_interval = 0;
+ts_time hostdb_current_interval{TS_TIME_ZERO};
 // Epoch timestamp of the last time we actually checked for a hosts file update.
-static ink_time_t hostdb_last_interval = 0;
+static ts_time hostdb_last_interval{TS_TIME_ZERO};
 // Epoch timestamp when we updated the hosts file last.
-static ink_time_t hostdb_hostfile_update_timestamp = 0;
-static char hostdb_filename[PATH_NAME_MAX]         = DEFAULT_HOST_DB_FILENAME;
-int hostdb_max_count                               = DEFAULT_HOST_DB_SIZE;
-char hostdb_hostfile_path[PATH_NAME_MAX]           = "";
-int hostdb_sync_frequency                          = 0;
-int hostdb_disable_reverse_lookup                  = 0;
-int hostdb_max_iobuf_index                         = BUFFER_SIZE_INDEX_32K;
-
-// Verify the generic storage is sufficient to cover all alternate members.
-static_assert(sizeof(HostDBApplicationInfo::allotment) == sizeof(HostDBApplicationInfo),
-              "Generic storage for HostDBApplicationInfo is smaller than the union storage.");
+static ts_time hostdb_hostfile_update_timestamp{TS_TIME_ZERO};
+static char hostdb_filename[PATH_NAME_MAX] = DEFAULT_HOST_DB_FILENAME;
+int hostdb_max_count                       = DEFAULT_HOST_DB_SIZE;
+static ts::file::path hostdb_hostfile_path;
+ts_seconds hostdb_sync_frequency{0};
+int hostdb_disable_reverse_lookup = 0;
+int hostdb_max_iobuf_index        = BUFFER_SIZE_INDEX_32K;
 
 ClassAllocator<HostDBContinuation> hostDBContAllocator("hostDBContAllocator");
 
+namespace
+{
+/** Assign raw storage to an @c IpAddr
+ *
+ * @param ip Destination.
+ * @param af IP family.
+ * @param ptr Raw data for an address of family @a af.
+ */
+void
+ip_addr_set(IpAddr &ip,     ///< Target storage.
+            uint8_t af,     ///< Address format.
+            void const *ptr ///< Raw address data
+)
+{
+  if (AF_INET6 == af) {
+    ip = *static_cast<in6_addr const *>(ptr);
+  } else if (AF_INET == af) {
+    ip = *static_cast<in_addr_t const *>(ptr);
+  } else {
+    ip.invalidate();
+  }
+}
+
+unsigned int
+HOSTDB_CLIENT_IP_HASH(sockaddr const *lhs, IpAddr const &rhs)
+{
+  unsigned int zret = ~static_cast<unsigned int>(0);
+  if (lhs->sa_family == rhs.family()) {
+    if (rhs.isIp4()) {
+      in_addr_t ip1 = ats_ip4_addr_cast(lhs);
+      in_addr_t ip2 = rhs._addr._ip4;
+      zret          = (ip1 >> 16) ^ ip1 ^ ip2 ^ (ip2 >> 16);
+    } else if (rhs.isIp6()) {
+      uint32_t const *ip1 = ats_ip_addr32_cast(lhs);
+      uint32_t const *ip2 = rhs._addr._u32;
+      for (int i = 0; i < 4; ++i, ++ip1, ++ip2) {
+        zret ^= (*ip1 >> 16) ^ *ip1 ^ *ip2 ^ (*ip2 >> 16);
+      }
+    }
+  }
+  return zret & 0xFFFF;
+}
+
+} // namespace
+
+char const *
+name_of(HostDBType t)
+{
+  switch (t) {
+  case HostDBType::UNSPEC:
+    return "*";
+  case HostDBType::ADDR:
+    return "Address";
+  case HostDBType::SRV:
+    return "SRV";
+  case HostDBType::HOST:
+    return "Reverse DNS";
+  }
+  return "";
+}
+
+/** Template for creating conversions and initialization for @c std::chrono based configuration variables.
+ *
+ * @tparam V The exact type of the configuration variable.
+ *
+ * The tricky template code is to enable having a class instance for each configuration variable, instead of for each _type_ of
+ * configuration variable. This is required because the callback interface requires functions and so the actual storage must be
+ * accessible from that function. *
+ */
+template <typename V> struct ConfigDuration {
+  using self_type = ConfigDuration;
+  V *_var; ///< Pointer to the variable to control.
+
+  /** Constructor.
+   *
+   * @param v The variable to update.
+   */
+  ConfigDuration(V &v) : _var(&v) {}

Review comment:
       explicit?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org