diff net/resolvers/basic.lua @ 13901:cc406878209d

net.resolvers.basic: Allow a filter callback to eliminate potential targets
author Matthew Wild <mwild1@gmail.com>
date Thu, 26 Jun 2025 13:02:34 +0100
parents ba409c67353b
children bc33a7269f5a
line wrap: on
line diff
--- a/net/resolvers/basic.lua	Fri Jun 20 13:33:09 2025 +0200
+++ b/net/resolvers/basic.lua	Thu Jun 26 13:02:34 2025 +0100
@@ -66,6 +66,9 @@
 			return;
 		end
 		local next_target = table.remove(self.targets, 1);
+		if self.filter and not self.filter(next_target[1], next_target[2], next_target[3], next_target[4], not not self.targets[1]) then
+			return self:next(cb);
+		end
 		cb(next_target[1], next_target[2], next_target[3], next_target[4], not not self.targets[1]);
 		return;
 	end
@@ -142,6 +145,7 @@
 		port = port;
 		conn_type = conn_type;
 		extra = extra or {};
+		filter = extra and extra.filter;
 		targets = targets;
 	}, resolver_mt);
 end