Software /
code /
prosody
Changeset
186:bfa8a30ea488
sends2s -> s2s_session.send(), s2s_session.send() -> s2s_session.sends2s()
Should fix outward routing problems.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 30 Oct 2008 21:11:22 +0000 |
parents | 185:a67c88ce1c6a |
children | 187:2e16e5077d8f |
files | core/s2smanager.lua core/stanza_router.lua |
diffstat | 2 files changed, 23 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/core/s2smanager.lua Sun Oct 26 21:22:59 2008 +0500 +++ b/core/s2smanager.lua Thu Oct 30 21:11:22 2008 +0000 @@ -30,7 +30,7 @@ function send_to_host(from_host, to_host, data) if hosts[to_host] then -- Write to connection - hosts[to_host].send(data); + hosts[to_host].sends2s(data); log("debug", "stanza sent over s2s"); else log("debug", "opening a new outgoing connection for this stanza"); @@ -54,7 +54,7 @@ end open_sessions = open_sessions + 1; local w = conn.write; - session.send = function (t) w(tostring(t)); end + session.sends2s = function (t) w(tostring(t)); end return session; end @@ -81,7 +81,7 @@ end local w = conn.write; - host_session.send = function (t) w(tostring(t)); end + host_session.sends2s = function (t) w(tostring(t)); end conn.write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0'>]], from_host, to_host)); @@ -90,7 +90,7 @@ function streamopened(session, attr) session.log("debug", "s2s stream opened"); - local send = session.send; + local send = session.sends2s; session.version = tonumber(attr.version) or 0; if session.version >= 1.0 and not (attr.to and attr.from) then @@ -118,7 +118,7 @@ if not attr.id then error("stream response did not give us a streamid!!!"); end session.streamid = attr.id; session.dialback_key = generate_dialback(session.streamid, session.to_host, session.from_host); - session.send(format("<db:result from='%s' to='%s'>%s</db:result>", session.from_host, session.to_host, session.dialback_key)); + session.sends2s(format("<db:result from='%s' to='%s'>%s</db:result>", session.from_host, session.to_host, session.dialback_key)); session.log("info", "sent dialback key on outgoing s2s stream"); else mark_connected(session); @@ -163,10 +163,17 @@ end function mark_connected(session) - local sendq, send = session.sendq, session.send; + local sendq, send = session.sendq, session.sends2s; + + local from, to = session.from_host, session.to_host; + session.log("debug", session.direction.." s2s connection "..session.from_host.."->"..session.to_host.." is now complete"); + + local send_to_host = send_to_host; + function session.send(data) send_to_host(from, to, data); end + if sendq then - session.log("debug", "sending queued stanzas across new outgoing connection"); + session.log("debug", "sending queued stanzas across new outgoing connection to "..session.to_host); for i, data in ipairs(sendq) do send(data); sendq[i] = nil;
--- a/core/stanza_router.lua Sun Oct 26 21:22:59 2008 +0500 +++ b/core/stanza_router.lua Thu Oct 30 21:11:22 2008 +0000 @@ -8,20 +8,7 @@ local log = require "util.logger".init("stanzarouter") local st = require "util.stanza"; -local _send = require "core.sessionmanager".send_to_session; -local send_s2s = require "core.s2smanager".send_to_host; -function send(session, stanza) - if session.type == "c2s" then - _send(session, stanza); - else - local xmlns = stanza.attr.xmlns; - --stanza.attr.xmlns = "jabber:server"; - stanza.attr.xmlns = nil; - log("debug", "sending s2s stanza: %s", tostring(stanza)); - send_s2s(session.host, host, stanza); -- TODO handle remote routing errors - stanza.attr.xmlns = xmlns; -- reset - end -end + local user_exists = require "core.usermanager".user_exists; local rostermanager = require "core.rostermanager"; @@ -142,7 +129,7 @@ type = "invalid" log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); end - origin.send(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); + origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then -- he wants to be identified through dialback -- We need to check the key with the Authoritative server @@ -175,7 +162,7 @@ log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); valid = "invalid"; end - origin.dialback_verifying.send(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); + origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); end end else @@ -194,7 +181,7 @@ if pres then pres.attr.to = jid; pres.attr.from = session.full_jid; - send(recipient_session, pres); + recipient_session.send(pres); pres.attr.to = nil; pres.attr.from = nil; count = count + 1; @@ -318,7 +305,7 @@ for k in pairs(user.sessions) do -- presence broadcast to all user resources. FIXME should this be just for available resources? Do we need to check subscription? if user.sessions[k].full_jid then stanza.attr.to = user.sessions[k].full_jid; -- reset at the end of function - send(user.sessions[k], stanza); + user.sessions[k].send(stanza); end end end @@ -330,14 +317,14 @@ end end -- TODO find resource with greatest priority - send(res, stanza); + res.send(stanza); else -- TODO send IQ error end else -- User + resource is online... stanza.attr.to = res.full_jid; -- reset at the end of function - send(res, stanza); -- Yay \o/ + res.send(stanza); -- Yay \o/ end else -- user not online @@ -357,11 +344,11 @@ -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? if stanza.name == "presence" then if stanza.attr.type == "probe" then - send(origin, st.presence({from = to_bare, to = from_bare, type = "unsubscribed"})); + origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"})); end -- else ignore else - send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); + origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end end end