Comparison

core/s2smanager.lua @ 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
parent 233:23585c323daa
child 243:09a80c8b2d73
comparison
equal deleted inserted replaced
240:c48dbfa6b1a6 241:021ccf988f3b
29 end 29 end
30 30
31 function send_to_host(from_host, to_host, data) 31 function send_to_host(from_host, to_host, data)
32 local host = hosts[to_host]; 32 local host = hosts[to_host];
33 if host then 33 if host then
34 -- Write to connection 34 -- We have a connection to this host already
35 if host.type == "s2sout_unauthed" and not host.notopen and not host.dialback_key then 35 if host.type == "s2sout_unauthed" then
36 log("debug", "trying to send over unauthed s2sout to "..to_host..", authing it now..."); 36 host.log("debug", "trying to send over unauthed s2sout to "..to_host..", authing it now...");
37 initiate_dialback(host); 37 if not host.notopen and not host.dialback_key then
38 if not host.sendq then host.sendq = { data }; 38 host.log("debug", "dialback had not been initiated");
39 else t_insert(host.sendq, data); end 39 initiate_dialback(host);
40 end
41
42 -- Queue stanza until we are able to send it
43 if host.sendq then t_insert(host.sendq, data);
44 else host.sendq = { data }; end
40 else 45 else
41 log("debug", "going to send stanza to "..to_host.." from "..from_host); 46 host.log("debug", "going to send stanza to "..to_host.." from "..from_host);
42 -- FIXME 47 -- FIXME
43 if hosts[to_host].from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); end 48 if hosts[to_host].from_host ~= from_host then log("error", "WARNING! This might, possibly, be a bug, but it might not..."); end
44 hosts[to_host].sends2s(data); 49 hosts[to_host].sends2s(data);
45 log("debug", "stanza sent over "..hosts[to_host].type); 50 host.log("debug", "stanza sent over "..hosts[to_host].type);
46 end 51 end
47 else 52 else
48 log("debug", "opening a new outgoing connection for this stanza"); 53 log("debug", "opening a new outgoing connection for this stanza");
49 local host_session = new_outgoing(from_host, to_host); 54 local host_session = new_outgoing(from_host, to_host);
50 -- Store in buffer 55 -- Store in buffer
75 hosts[to_host] = host_session; 80 hosts[to_host] = host_session;
76 local cl = connlisteners_get("xmppserver"); 81 local cl = connlisteners_get("xmppserver");
77 82
78 local conn, handler = socket.tcp() 83 local conn, handler = socket.tcp()
79 84
80 85 --FIXME: Below parameters (ports/ip) are incorrect (use SRV)
86 to_host = srvmap[to_host] or to_host;
87
88 conn:settimeout(0);
89 local success, err = conn:connect(to_host, 5269);
90 if not success then
91 log("warn", "s2s connect() failed: %s", err);
92 end
93
94 conn = wraptlsclient(cl, conn, to_host, 5269, 0, 1, hosts[from_host].ssl_ctx );
95 host_session.conn = conn;
96
81 -- Register this outgoing connection so that xmppserver_listener knows about it 97 -- Register this outgoing connection so that xmppserver_listener knows about it
82 -- otherwise it will assume it is a new incoming connection 98 -- otherwise it will assume it is a new incoming connection
83 cl.register_outgoing(conn, host_session); 99 cl.register_outgoing(conn, host_session);
84 100
85 --FIXME: Below parameters (ports/ip) are incorrect (use SRV)
86 to_host = srvmap[to_host] or to_host;
87 conn:settimeout(0.1);
88 conn:connect(to_host, 5269);
89 conn = wraptlsclient(cl, conn, to_host, 5269, 0, 1, hosts[from_host].ssl_ctx );
90 host_session.conn = conn;
91
92 do 101 do
93 local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$"); 102 local conn_name = "s2sout"..tostring(conn):match("[a-f0-9]*$");
94 host_session.log = logger_init(conn_name); 103 host_session.log = logger_init(conn_name);
95 end 104 end
96 105