# HG changeset patch # User Matthew Wild # Date 1282400989 -3600 # Node ID 6cc0ca4aa6649195d66a5b392fbfca259d72e8ba # Parent a167d3248842063dcc4b83aca86e4211ef0f40e1 verse.plugins.proxy65: Add proxies discovered by disco plugin to proxy65.available_streamhosts diff -r a167d3248842 -r 6cc0ca4aa664 plugins/proxy65.lua --- a/plugins/proxy65.lua Sat Aug 21 15:28:54 2010 +0100 +++ b/plugins/proxy65.lua Sat Aug 21 15:29:49 2010 +0100 @@ -11,8 +11,31 @@ function verse.plugins.proxy65(stream) stream.proxy65 = setmetatable({ stream = stream }, proxy65_mt); - stream:hook("disco-result", function (result) + stream.proxy65.available_streamhosts = {}; + local outstanding_proxies = 0; + stream:hook("disco/service-discovered/proxy", function (service) -- Fill list with available proxies + if service.type == "bytestreams" then + outstanding_proxies = outstanding_proxies + 1; + stream:send_iq(verse.iq({ to = service.jid, type = "get" }) + :tag("query", { xmlns = xmlns_bytestreams }), function (result) + + outstanding_proxies = outstanding_proxies - 1; + if result.attr.type == "result" then + local streamhost = result:get_child("query", xmlns_bytestreams) + :get_child("streamhost").attr; + + stream.proxy65.available_streamhosts[streamhost.jid] = { + jid = streamhost.jid; + host = streamhost.host; + port = tonumber(streamhost.port); + }; + end + if outstanding_proxies == 0 then + stream:event("proxy65/discovered-proxies", stream.proxy65.available_streamhosts); + end + end); + end end); stream:hook("iq/"..xmlns_bytestreams, function (request) local conn = verse.new(nil, {