Software /
code /
prosody
Changeset
241:021ccf988f3b
Some s2s fixes. Now connect() does not block, and stanzas are not lost when connection is slow
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 12 Nov 2008 19:26:08 +0000 |
parents | 240:c48dbfa6b1a6 |
children | 242:f15afbcbc55c |
files | core/s2smanager.lua |
diffstat | 1 files changed, 25 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/core/s2smanager.lua Mon Nov 10 00:00:46 2008 +0000 +++ b/core/s2smanager.lua Wed Nov 12 19:26:08 2008 +0000 @@ -31,18 +31,23 @@ 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 @@ local conn, handler = socket.tcp() + --FIXME: Below parameters (ports/ip) are incorrect (use SRV) + to_host = srvmap[to_host] or to_host; + 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); - - --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 = wraptlsclient(cl, conn, to_host, 5269, 0, 1, hosts[from_host].ssl_ctx ); - host_session.conn = conn; - + do local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$"); host_session.log = logger_init(conn_name);