From 564fb0420a1e83294462f83cfe735fac3aae7875 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 12 Nov 2008 19:26:08 +0000 Subject: Some s2s fixes. Now connect() does not block, and stanzas are not lost when connection is slow --- core/s2smanager.lua | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index aed10753..1cfba592 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -31,18 +31,23 @@ end function send_to_host(from_host, to_host, data) local host = hosts[to_host]; if host then - -- Write to connection - if host.type == "s2sout_unauthed" and not host.notopen and not host.dialback_key then - log("debug", "trying to send over unauthed s2sout to "..to_host..", authing it now..."); - initiate_dialback(host); - if not host.sendq then host.sendq = { data }; - else t_insert(host.sendq, data); end + -- We have a connection to this host already + if host.type == "s2sout_unauthed" then + host.log("debug", "trying to send over unauthed s2sout to "..to_host..", authing it now..."); + if not host.notopen and not host.dialback_key then + host.log("debug", "dialback had not been initiated"); + initiate_dialback(host); + end + + -- Queue stanza until we are able to send it + if host.sendq then t_insert(host.sendq, data); + else host.sendq = { data }; end else - log("debug", "going to send stanza to "..to_host.." from "..from_host); + host.log("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME if hosts[to_host].from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); end hosts[to_host].sends2s(data); - log("debug", "stanza sent over "..hosts[to_host].type); + host.log("debug", "stanza sent over "..hosts[to_host].type); end else log("debug", "opening a new outgoing connection for this stanza"); @@ -77,18 +82,22 @@ function new_outgoing(from_host, to_host) local conn, handler = socket.tcp() - - -- Register this outgoing connection so that xmppserver_listener knows about it - -- otherwise it will assume it is a new incoming connection - cl.register_outgoing(conn, host_session); - --FIXME: Below parameters (ports/ip) are incorrect (use SRV) to_host = srvmap[to_host] or to_host; - conn:settimeout(0.1); - conn:connect(to_host, 5269); + + conn:settimeout(0); + local success, err = conn:connect(to_host, 5269); + if not success then + log("warn", "s2s connect() failed: %s", err); + end + conn = wraptlsclient(cl, conn, to_host, 5269, 0, 1, hosts[from_host].ssl_ctx ); host_session.conn = conn; - + + -- Register this outgoing connection so that xmppserver_listener knows about it + -- otherwise it will assume it is a new incoming connection + cl.register_outgoing(conn, host_session); + do local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$"); host_session.log = logger_init(conn_name); -- cgit v1.2.3 From a37d7db54f875e07c1bcc813265aaf112130b313 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 13 Nov 2008 03:48:20 +0000 Subject: Change sending reply stream header to use top_tag() --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 1cfba592..8a6d5b45 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -133,7 +133,7 @@ function streamopened(session, attr) session.streamid = uuid_gen(); print(session, session.from_host, "incoming s2s stream opened"); send(""); - send(format("", session.streamid, session.to_host)); + send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host })); elseif session.direction == "outgoing" then -- If we are just using the connection for verifying dialback keys, we won't try and auth it if not attr.id then error("stream response did not give us a streamid!!!"); end -- cgit v1.2.3 From 2a2cad9354e899fa367d8e5b8637e83400a3877c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 13 Nov 2008 03:56:22 +0000 Subject: Missed importing a function in last commit --- core/s2smanager.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 8a6d5b45..276873cd 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -10,6 +10,8 @@ local tostring, pairs, ipairs, getmetatable, print, newproxy, error, tonumber local connlisteners_get = require "net.connlisteners".get; local wraptlsclient = require "net.server".wraptlsclient; local modulemanager = require "core.modulemanager"; +local st = require "stanza"; +local stanza = st.stanza; local uuid_gen = require "util.uuid".generate; -- cgit v1.2.3 From 3349550650708464ff95669a41003f8086181167 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:06:17 +0000 Subject: Mmm, s2s fixed :) --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 276873cd..fe43b181 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -135,7 +135,7 @@ function streamopened(session, attr) session.streamid = uuid_gen(); print(session, session.from_host, "incoming s2s stream opened"); send(""); - send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host })); + send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host }):top_tag()); elseif session.direction == "outgoing" then -- If we are just using the connection for verifying dialback keys, we won't try and auth it if not attr.id then error("stream response did not give us a streamid!!!"); end -- cgit v1.2.3 From e110538068747e6595facc504f775c3555d546b8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:09:20 +0000 Subject: Another small fix, for logging in s2smanager --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index fe43b181..f5ad12f9 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -45,7 +45,7 @@ function send_to_host(from_host, to_host, data) if host.sendq then t_insert(host.sendq, data); else host.sendq = { data }; end else - host.log("debug", "going to send stanza to "..to_host.." from "..from_host); + (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME if hosts[to_host].from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); end hosts[to_host].sends2s(data); -- cgit v1.2.3 From 9acd51fbef35196c355bf03a9d7751a064649d29 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:12:08 +0000 Subject: Another small fix, for logging in s2smanager --- core/s2smanager.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index f5ad12f9..e0a6f3ca 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -47,7 +47,10 @@ function send_to_host(from_host, to_host, data) else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME - if hosts[to_host].from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); end + if hosts[to_host].from_host ~= from_host then + log("error", "WARNING! This might, possibly, be a bug, but it might not..."); + log("error", "We are going to send from %s instead of %s", hosts[to_host].from_host, from_host); + end hosts[to_host].sends2s(data); host.log("debug", "stanza sent over "..hosts[to_host].type); end -- cgit v1.2.3 From 1b422e8f1d173e7f70db93cfec3ef499e0f9e37c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:20:46 +0000 Subject: Fix for detecting when we are routing a stanza to ourself (I'm sure this has something to do with you, waqas...) --- core/s2smanager.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index e0a6f3ca..16092ba8 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -4,6 +4,7 @@ local sessions = sessions; local socket = require "socket"; local format = string.format; local t_insert = table.insert; +local get_traceback = debug.traceback; local tostring, pairs, ipairs, getmetatable, print, newproxy, error, tonumber = tostring, pairs, ipairs, getmetatable, print, newproxy, error, tonumber; @@ -44,6 +45,9 @@ function send_to_host(from_host, to_host, data) -- Queue stanza until we are able to send it if host.sendq then t_insert(host.sendq, data); else host.sendq = { data }; end + elseif host.type == "local" or host.type == "component" then + log("error", "Trying to send a stanza to ourselves??") + log("error", "Traceback: "..get_traceback()); else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME -- cgit v1.2.3 From f980ba5734e2a81348f14905147519b26ef8d794 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:23:43 +0000 Subject: Print out the stanza also --- core/s2smanager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 16092ba8..530e3087 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -47,7 +47,8 @@ function send_to_host(from_host, to_host, data) else host.sendq = { data }; end elseif host.type == "local" or host.type == "component" then log("error", "Trying to send a stanza to ourselves??") - log("error", "Traceback: "..get_traceback()); + log("error", "Traceback: %s", get_traceback()); + log("error", "Stanza: %s", stanza); else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME -- cgit v1.2.3 From c374478423b1fa6df31f2e133db77f89ceb91fac Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:33:20 +0000 Subject: I knew it ;) Fix sending error replies over s2s (though we shouldn't be error'ing on stream:features anyway) --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 530e3087..8b421f13 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -48,7 +48,7 @@ function send_to_host(from_host, to_host, data) elseif host.type == "local" or host.type == "component" then log("error", "Trying to send a stanza to ourselves??") log("error", "Traceback: %s", get_traceback()); - log("error", "Stanza: %s", stanza); + log("error", "Stanza: %s", data); else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME -- cgit v1.2.3 From 6d9485225a4c8c9b339ca9cea137ba3f2de6fd64 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:38:41 +0000 Subject: Yep, s2s definitely works now. This is just a small fix for logging... --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 8b421f13..4fa22957 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -48,7 +48,7 @@ function send_to_host(from_host, to_host, data) elseif host.type == "local" or host.type == "component" then log("error", "Trying to send a stanza to ourselves??") log("error", "Traceback: %s", get_traceback()); - log("error", "Stanza: %s", data); + log("error", "Stanza: %s", tostring(data)); else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME -- cgit v1.2.3 From 428fc65bbc595d80cb678dadcc9ea7cae055d5b9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:41:37 +0000 Subject: Some more logging fixes --- core/s2smanager.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4fa22957..6d00ff6e 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -103,11 +103,11 @@ function new_outgoing(from_host, to_host) conn = wraptlsclient(cl, conn, to_host, 5269, 0, 1, hosts[from_host].ssl_ctx ); host_session.conn = conn; - + -- Register this outgoing connection so that xmppserver_listener knows about it -- otherwise it will assume it is a new incoming connection cl.register_outgoing(conn, host_session); - + do local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$"); host_session.log = logger_init(conn_name); @@ -122,7 +122,6 @@ function new_outgoing(from_host, to_host) end function streamopened(session, attr) - session.log("debug", "s2s stream opened"); local send = session.sends2s; session.version = tonumber(attr.version) or 0; @@ -166,7 +165,7 @@ function streamopened(session, attr) end send("");]] - log("info", "s2s stream opened successfully"); + session.notopen = nil; end -- cgit v1.2.3 From 22df06d27db30cae5c7d3361a4fe51ab9a89dcbc Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 02:54:56 +0000 Subject: Now outgoing s2s sessions are associated with their from_host, fixes #15 --- core/s2smanager.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 6d00ff6e..3f286d0e 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -32,7 +32,7 @@ function connect_host(from_host, to_host) end function send_to_host(from_host, to_host, data) - local host = hosts[to_host]; + local host = hosts[from_host].s2sout[to_host]; if host then -- We have a connection to this host already if host.type == "s2sout_unauthed" then @@ -52,12 +52,12 @@ function send_to_host(from_host, to_host, data) else (host.log or log)("debug", "going to send stanza to "..to_host.." from "..from_host); -- FIXME - if hosts[to_host].from_host ~= from_host then + if host.from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); - log("error", "We are going to send from %s instead of %s", hosts[to_host].from_host, from_host); + log("error", "We are going to send from %s instead of %s", host.from_host, from_host); end - hosts[to_host].sends2s(data); - host.log("debug", "stanza sent over "..hosts[to_host].type); + host.sends2s(data); + host.log("debug", "stanza sent over "..host.type); end else log("debug", "opening a new outgoing connection for this stanza"); @@ -87,7 +87,7 @@ end function new_outgoing(from_host, to_host) local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; - hosts[to_host] = host_session; + hosts[from_host].s2sout[to_host] = host_session; local cl = connlisteners_get("xmppserver"); local conn, handler = socket.tcp() @@ -225,7 +225,7 @@ end function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); if session.direction == "outgoing" then - hosts[session.to_host] = nil; + hosts[session.from_host].s2sout[session.to_host] = nil; end session.conn = nil; session.disconnect = nil; -- cgit v1.2.3 From b06c5faec463339f95023abb0b1e2aa09dbefd7c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 18:54:19 +0000 Subject: Remove some old unused (and empty) functions from s2smanager --- core/s2smanager.lua | 7 ------- 1 file changed, 7 deletions(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 3f286d0e..490dfec4 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -28,9 +28,6 @@ local srvmap = { ["gmail.com"] = "talk.google.com", ["identi.ca"] = "longlance.c module "s2smanager" -function connect_host(from_host, to_host) -end - function send_to_host(from_host, to_host, data) local host = hosts[from_host].s2sout[to_host]; if host then @@ -67,10 +64,6 @@ function send_to_host(from_host, to_host, data) end end -function disconnect_host(host) - -end - local open_sessions = 0; function new_incoming(conn) -- cgit v1.2.3 From 1c704dcef79c640ffdbc259af63c29ac47599e89 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 14 Nov 2008 20:30:24 +0000 Subject: Update hostname for identi.ca --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 490dfec4..bec1c29b 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -24,7 +24,7 @@ local md5_hash = require "util.hashes".md5; local dialback_secret = "This is very secret!!! Ha!"; -local srvmap = { ["gmail.com"] = "talk.google.com", ["identi.ca"] = "longlance.controlezvous.ca", ["cdr.se"] = "jabber.cdr.se" }; +local srvmap = { ["gmail.com"] = "talk.google.com", ["identi.ca"] = "hampton.controlezvous.ca", ["cdr.se"] = "jabber.cdr.se" }; module "s2smanager" -- cgit v1.2.3 From 9318711f5f25a04aea6fe2fc9caa79a322a004b3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 15 Nov 2008 08:38:25 +0500 Subject: Log how many queued stanzas we send --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/s2smanager.lua') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index bec1c29b..c3d9bdb4 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -205,7 +205,7 @@ function mark_connected(session) if session.direction == "outgoing" then if sendq then - session.log("debug", "sending queued stanzas across new outgoing connection to "..session.to_host); + session.log("debug", "sending "..#sendq.." queued stanzas across new outgoing connection to "..session.to_host); for i, data in ipairs(sendq) do send(data); sendq[i] = nil; -- cgit v1.2.3