aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2011-11-06 18:23:16 +0100
committerFlorian Zeitz <florob@babelmonkeys.de>2011-11-06 18:23:16 +0100
commit400449ed020462fe86f61d30b5ea7d79e76accca (patch)
tree1f8124e620c1427d68125444e61aeebc72a05aba
parent8d5ffd8d1a65a773ac7b67627b8ce116fbe522d2 (diff)
downloadprosody-400449ed020462fe86f61d30b5ea7d79e76accca.tar.gz
prosody-400449ed020462fe86f61d30b5ea7d79e76accca.zip
util.rfc3484: Use a stable sorting algorithm
-rw-r--r--util/rfc3484.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/util/rfc3484.lua b/util/rfc3484.lua
index 373d3c33..dd855a84 100644
--- a/util/rfc3484.lua
+++ b/util/rfc3484.lua
@@ -5,10 +5,20 @@
-- COPYING file in the source package for more information.
--
-local t_sort = table.sort;
local commonPrefixLength = require"util.ip".commonPrefixLength
local new_ip = require"util.ip".new_ip;
+local function t_sort(t, comp)
+ for i = 1, (#t - 1) do
+ for j = (i + 1), #t do
+ local a, b = t[i], t[j];
+ if not comp(a,b) then
+ t[i], t[j] = b, a;
+ end
+ end
+ end
+end
+
function source(dest, candidates)
local function comp(ipA, ipB)
-- Rule 1: Prefer same address
@@ -61,7 +71,6 @@ function source(dest, candidates)
end
function destination(candidates, sources)
- local t_sort = table.sort;
local sourceAddrs = {};
local function comp(ipA, ipB)
local ipAsource = sourceAddrs[ipA];