Comparison

net/resolvers/basic.lua @ 12409:9f0baf15e792

net.resolvers.basic: Alternate IP address family targets, per RFC 8305
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2022 16:10:26 +0000
parent 12408:acfc51b9530c
child 12410:596625eed326
comparison
equal deleted inserted replaced
12408:acfc51b9530c 12409:9f0baf15e792
40 end); 40 end);
41 end 41 end
42 42
43 local function merge_targets(ipv4_targets, ipv6_targets) 43 local function merge_targets(ipv4_targets, ipv6_targets)
44 local result = { secure = ipv4_targets.secure and ipv6_targets.secure }; 44 local result = { secure = ipv4_targets.secure and ipv6_targets.secure };
45 t_move(ipv6_targets, 1, #ipv6_targets, 1, result); 45 local common_length = math.min(#ipv4_targets, #ipv6_targets);
46 t_move(ipv4_targets, 1, #ipv4_targets, #result+1, result); 46 for i = 1, common_length do
47 table.insert(result, ipv6_targets[i]);
48 table.insert(result, ipv4_targets[i]);
49 end
50 if common_length < #ipv4_targets then
51 t_move(ipv4_targets, common_length+1, #ipv4_targets, common_length+1, result);
52 elseif common_length < #ipv6_targets then
53 t_move(ipv6_targets, common_length+1, #ipv6_targets, common_length+1, result);
54 end
47 return result; 55 return result;
48 end 56 end
49 57
50 -- Find the next target to connect to, and 58 -- Find the next target to connect to, and
51 -- pass it to cb() 59 -- pass it to cb()