]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rename selfweighted to pickselfweighted; add pickselfweighted docs
authorn0tlu5 <darfisultoni@gmail.com>
Thu, 19 Dec 2024 14:15:56 +0000 (21:15 +0700)
committern0tlu5 <darfisultoni@gmail.com>
Thu, 19 Dec 2024 14:15:56 +0000 (21:15 +0700)
docs/lua-records/functions.rst
pdns/lua-record.cc

index 45af5dde9a4f71df45f4896d7d59e2a9becb57f0..715980e120fc799c4bdf629e17dec1138222fd28 100644 (file)
@@ -128,6 +128,21 @@ Record creation functions
 
   This function also works for CNAME or TXT records.
 
+.. function:: pickselfweighted(addresses[, options])
+
+  Selects an IP address from the supplied list, weighted according to the results of `isUp` checks. Each address is evaluated, and if its associated weight (from `isUp`) is greater than 0, it is considered for selection using a weighted hash based on `bestwho`. If no address is "up," the function defaults to a random selection.
+
+  :param addresses: A list of IP addresses to evaluate.
+  :param options: (Optional) A table of options for this specific check. Supports:
+    - ``source``: Source address for the check.
+    - ``timeout``: Maximum time in seconds for the check (default 2).
+  
+  Example usage::
+
+    pickselfweighted({ "192.0.2.20", "203.0.113.4", "203.0.113.2" }, { source = "192.0.2.1", timeout = 1 })
+
+  This function is ideal for scenarios where weighted selection is necessary to prioritize "up" addresses while still offering fallback behavior when all addresses are down.
+
 .. function:: pickrandomsample(number, values)
 
   Returns N random values from the list supplied.
index 0a0f5dbad0bbcdadb5219ac2929f47c7b4de87e8..fc0314ece5cb6c544ad81e31a7b4b93b89ce4573 100644 (file)
@@ -1180,9 +1180,9 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
   /*
    * Based on the hash of `bestwho`, returns an IP address from the list
    * supplied, weighted according to the results of isUp calls.
-   * @example selfweighted("{ "192.0.2.20", "203.0.113.4", "203.0.113.2" })
+   * @example pickselfweighted("{ "192.0.2.20", "203.0.113.4", "203.0.113.2" })
    */
-  lua.writeFunction("selfweighted", [](const iplist_t& ips,
+  lua.writeFunction("pickselfweighted", [](const iplist_t& ips,
                                           boost::optional<opts_t> options) {
       vector< pair<int, ComboAddress> > items;
       opts_t opts;