# HG changeset patch # User Matthew Wild # Date 1225401082 0 # Node ID bfa8a30ea488e985286c9b641796476743691332 # Parent a67c88ce1c6a1fcfd584f39d592f1bfe6d9a232f sends2s -> s2s_session.send(), s2s_session.send() -> s2s_session.sends2s() Should fix outward routing problems. diff -r a67c88ce1c6a -r bfa8a30ea488 core/s2smanager.lua --- 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([[]], 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("%s", session.from_host, session.to_host, session.dialback_key)); + session.sends2s(format("%s", 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; diff -r a67c88ce1c6a -r bfa8a30ea488 core/stanza_router.lua --- 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("%s", attr.to, attr.from, attr.id, type, stanza[1])); + origin.sends2s(format("%s", 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("%s", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); + origin.dialback_verifying.sends2s(format("%s", 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