Comparison

core/s2smanager.lua @ 2090:7810648ea26d

s2smanager: Fail outgoing s2s connection if hostname does not pass idna_to_ascii(), thanks Flo + waqas
author Matthew Wild <mwild1@gmail.com>
date Fri, 20 Nov 2009 15:07:39 +0000
parent 2089:fdd7280c4621
child 2100:c8005be640b1
child 2127:be3c906f4770
child 2165:529af807ba1a
comparison
equal deleted inserted replaced
2089:fdd7280c4621 2090:7810648ea26d
104 host.log("debug", "stanza sent over "..host.type); 104 host.log("debug", "stanza sent over "..host.type);
105 end 105 end
106 else 106 else
107 log("debug", "opening a new outgoing connection for this stanza"); 107 log("debug", "opening a new outgoing connection for this stanza");
108 local host_session = new_outgoing(from_host, to_host); 108 local host_session = new_outgoing(from_host, to_host);
109
109 -- Store in buffer 110 -- Store in buffer
110 host_session.sendq = { {tostring(data), st.reply(data)} }; 111 host_session.sendq = { {tostring(data), st.reply(data)} };
111 log("debug", "stanza [%s] queued until connection complete", tostring(data.name)); 112 log("debug", "stanza [%s] queued until connection complete", tostring(data.name));
112 if (not host_session.connecting) and (not host_session.conn) then 113 if (not host_session.connecting) and (not host_session.conn) then
113 log("warn", "Connection to %s failed already, destroying session...", to_host); 114 log("warn", "Connection to %s failed already, destroying session...", to_host);
153 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); 154 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$");
154 log = logger_init(conn_name); 155 log = logger_init(conn_name);
155 host_session.log = log; 156 host_session.log = log;
156 end 157 end
157 158
158 -- This is the first call, can't fail (the first step is DNS lookup) 159 -- Kick the connection attempting machine
159 attempt_connection(host_session); 160 attempt_connection(host_session);
160 161
161 if not host_session.sends2s then 162 if not host_session.sends2s then
162 -- A sends2s which buffers data (until the stream is opened) 163 -- A sends2s which buffers data (until the stream is opened)
163 -- note that data in this buffer will be sent before the stream is authed 164 -- note that data in this buffer will be sent before the stream is authed
180 181
181 182
182 function attempt_connection(host_session, err) 183 function attempt_connection(host_session, err)
183 local from_host, to_host = host_session.from_host, host_session.to_host; 184 local from_host, to_host = host_session.from_host, host_session.to_host;
184 local connect_host, connect_port = idna_to_ascii(to_host), 5269; 185 local connect_host, connect_port = idna_to_ascii(to_host), 5269;
186
187 if not connect_host then
188 return false;
189 end
185 190
186 if not err then -- This is our first attempt 191 if not err then -- This is our first attempt
187 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host); 192 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host);
188 host_session.connecting = true; 193 host_session.connecting = true;
189 local handle; 194 local handle;