Software /
code /
verse
Comparison
plugins/proxy65.lua @ 103:6cc0ca4aa664
verse.plugins.proxy65: Add proxies discovered by disco plugin to proxy65.available_streamhosts
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 21 Aug 2010 15:29:49 +0100 |
parent | 56:014bdb4154e9 |
child | 380:0891b4e27766 |
comparison
equal
deleted
inserted
replaced
102:a167d3248842 | 103:6cc0ca4aa664 |
---|---|
9 | 9 |
10 local negotiate_socks5; | 10 local negotiate_socks5; |
11 | 11 |
12 function verse.plugins.proxy65(stream) | 12 function verse.plugins.proxy65(stream) |
13 stream.proxy65 = setmetatable({ stream = stream }, proxy65_mt); | 13 stream.proxy65 = setmetatable({ stream = stream }, proxy65_mt); |
14 stream:hook("disco-result", function (result) | 14 stream.proxy65.available_streamhosts = {}; |
15 local outstanding_proxies = 0; | |
16 stream:hook("disco/service-discovered/proxy", function (service) | |
15 -- Fill list with available proxies | 17 -- Fill list with available proxies |
18 if service.type == "bytestreams" then | |
19 outstanding_proxies = outstanding_proxies + 1; | |
20 stream:send_iq(verse.iq({ to = service.jid, type = "get" }) | |
21 :tag("query", { xmlns = xmlns_bytestreams }), function (result) | |
22 | |
23 outstanding_proxies = outstanding_proxies - 1; | |
24 if result.attr.type == "result" then | |
25 local streamhost = result:get_child("query", xmlns_bytestreams) | |
26 :get_child("streamhost").attr; | |
27 | |
28 stream.proxy65.available_streamhosts[streamhost.jid] = { | |
29 jid = streamhost.jid; | |
30 host = streamhost.host; | |
31 port = tonumber(streamhost.port); | |
32 }; | |
33 end | |
34 if outstanding_proxies == 0 then | |
35 stream:event("proxy65/discovered-proxies", stream.proxy65.available_streamhosts); | |
36 end | |
37 end); | |
38 end | |
16 end); | 39 end); |
17 stream:hook("iq/"..xmlns_bytestreams, function (request) | 40 stream:hook("iq/"..xmlns_bytestreams, function (request) |
18 local conn = verse.new(nil, { | 41 local conn = verse.new(nil, { |
19 initiator_jid = request.attr.from, | 42 initiator_jid = request.attr.from, |
20 streamhosts = {}, | 43 streamhosts = {}, |