Mercurial > prosody-hg
comparison plugins/mod_s2s/mod_s2s.lua @ 4820:c65edd3bb334
mod_s2s: Cache to_host and from_host in local variables, and use these instead of repeated lookups
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 04 May 2012 02:27:26 +0100 |
| parents | 4fa47fc6f20c |
| children | 5ef05f32bc42 |
comparison
equal
deleted
inserted
replaced
| 4819:4fa47fc6f20c | 4820:c65edd3bb334 |
|---|---|
| 211 elseif to ~= session.to_host then | 211 elseif to ~= session.to_host then |
| 212 session:close({ condition = "improper-addressing", text = "New stream 'to' attribute does not match original" }); | 212 session:close({ condition = "improper-addressing", text = "New stream 'to' attribute does not match original" }); |
| 213 return; | 213 return; |
| 214 end | 214 end |
| 215 | 215 |
| 216 -- For convenience we'll put the sanitised values into these variables | |
| 217 to, from = session.to_host, session.from_host; | |
| 218 | |
| 216 session.streamid = uuid_gen(); | 219 session.streamid = uuid_gen(); |
| 217 (session.log or log)("debug", "Incoming s2s received %s", st.stanza("stream:stream", attr):top_tag()); | 220 (session.log or log)("debug", "Incoming s2s received %s", st.stanza("stream:stream", attr):top_tag()); |
| 218 if session.to_host then | 221 if to then |
| 219 if not hosts[session.to_host] then | 222 if not hosts[to] then |
| 220 -- Attempting to connect to a host we don't serve | 223 -- Attempting to connect to a host we don't serve |
| 221 session:close({ | 224 session:close({ |
| 222 condition = "host-unknown"; | 225 condition = "host-unknown"; |
| 223 text = "This host does not serve "..session.to_host | 226 text = "This host does not serve "..to |
| 224 }); | 227 }); |
| 225 return; | 228 return; |
| 226 elseif hosts[session.to_host].disallow_s2s then | 229 elseif hosts[to].disallow_s2s then |
| 227 -- Attempting to connect to a host that disallows s2s | 230 -- Attempting to connect to a host that disallows s2s |
| 228 session:close({ | 231 session:close({ |
| 229 condition = "policy-violation"; | 232 condition = "policy-violation"; |
| 230 text = "Server-to-server communication is not allowed to this host"; | 233 text = "Server-to-server communication is not allowed to this host"; |
| 231 }); | 234 }); |
| 235 | 238 |
| 236 if session.secure and not session.cert_chain_status then check_cert_status(session); end | 239 if session.secure and not session.cert_chain_status then check_cert_status(session); end |
| 237 | 240 |
| 238 send("<?xml version='1.0'?>"); | 241 send("<?xml version='1.0'?>"); |
| 239 send(st.stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', | 242 send(st.stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', |
| 240 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); | 243 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=to, to=from, version=(session.version > 0 and "1.0" or nil) }):top_tag()); |
| 241 if session.version >= 1.0 then | 244 if session.version >= 1.0 then |
| 242 local features = st.stanza("stream:features"); | 245 local features = st.stanza("stream:features"); |
| 243 | 246 |
| 244 if session.to_host then | 247 if to then |
| 245 hosts[session.to_host].events.fire_event("s2s-stream-features", { origin = session, features = features }); | 248 hosts[to].events.fire_event("s2s-stream-features", { origin = session, features = features }); |
| 246 else | 249 else |
| 247 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", session.from_host or "unknown host"); | 250 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or "unknown host"); |
| 248 end | 251 end |
| 249 | 252 |
| 250 log("debug", "Sending stream features: %s", tostring(features)); | 253 log("debug", "Sending stream features: %s", tostring(features)); |
| 251 send(features); | 254 send(features); |
| 252 end | 255 end |
| 253 | 256 |
| 254 local host_session = hosts[session.to_host]; | 257 local host_session = hosts[to]; |
| 255 session.send = function(stanza) | 258 session.send = function(stanza) |
| 256 host_session.events.fire_event("route/remote", { from_host = session.to_host, to_host = session.from_host, stanza = stanza}) | 259 host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza}) |
| 257 end; | 260 end; |
| 258 elseif session.direction == "outgoing" then | 261 elseif session.direction == "outgoing" then |
| 259 -- If we are just using the connection for verifying dialback keys, we won't try and auth it | 262 -- If we are just using the connection for verifying dialback keys, we won't try and auth it |
| 260 if not attr.id then error("stream response did not give us a streamid!!!"); end | 263 if not attr.id then error("stream response did not give us a streamid!!!"); end |
| 261 session.streamid = attr.id; | 264 session.streamid = attr.id; |
