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.
/*
* 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;