aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-03-05 11:30:55 +0000
committerMatthew Wild <mwild1@gmail.com>2022-03-05 11:30:55 +0000
commitfa68985f24c2160d4cb2e634a0e0df857e4a666e (patch)
tree83f0df411f610d8e0880abc6aa77b4d279483d1d
parent9df580f9975d2915de333efcbb573a61774c1257 (diff)
downloadprosody-fa68985f24c2160d4cb2e634a0e0df857e4a666e.tar.gz
prosody-fa68985f24c2160d4cb2e634a0e0df857e4a666e.zip
net.stun: Support for xor-relayed-address attribute
-rw-r--r--net/stun.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/net/stun.lua b/net/stun.lua
index b8e96d0e..2c35786f 100644
--- a/net/stun.lua
+++ b/net/stun.lua
@@ -197,13 +197,18 @@ function packet_methods:deserialize(bytes)
return self;
end
-function packet_methods:get_attribute(attr_type)
+function packet_methods:get_attribute(attr_type, idx)
+ idx = math.max(idx or 1, 1);
if type(attr_type) == "string" then
attr_type = assert(attribute_lookup[attr_type:lower()], "unknown attribute: "..attr_type);
end
for _, attribute in ipairs(self.attributes) do
if struct.unpack(">I2", attribute) == attr_type then
- return attribute:sub(5);
+ if idx == 1 then
+ return attribute:sub(5);
+ else
+ idx = idx - 1;
+ end
end
end
end
@@ -249,6 +254,19 @@ function packet_methods:add_xor_peer_address(address, port)
self:add_attribute("xor-peer-address", self:_pack_address(family, parsed_ip.packed, port or 0, true));
end
+function packet_methods:get_xor_relayed_address(idx)
+ local data = self:get_attribute("xor-relayed-address", idx);
+ if not data then return; end
+ return self:_unpack_address(data, true);
+end
+
+function packet_methods:get_xor_relayed_addresses()
+ return {
+ self:get_xor_relayed_address(1);
+ self:get_xor_relayed_address(2);
+ };
+end
+
function packet_methods:add_message_integrity(key)
-- Add attribute with a dummy value so we can artificially increase
-- the packet 'length'