Software / code / prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 10483:c12a24f0a385
mod_s2s: Invert condition to return early and reduce indentation
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 04 Dec 2019 22:37:20 +0100 |
| parent | 10482:c7864f970969 |
| child | 10500:493cbfe99b64 |
comparison
equal
deleted
inserted
replaced
| 10482:c7864f970969 | 10483:c12a24f0a385 |
|---|---|
| 121 if hosts[to_host] then | 121 if hosts[to_host] then |
| 122 log("warn", "Attempt to route stanza to a remote %s - a host we do serve?!", from_host); | 122 log("warn", "Attempt to route stanza to a remote %s - a host we do serve?!", from_host); |
| 123 return false; | 123 return false; |
| 124 end | 124 end |
| 125 local host = hosts[from_host].s2sout[to_host]; | 125 local host = hosts[from_host].s2sout[to_host]; |
| 126 if host then | 126 if not host then return end |
| 127 -- We have a connection to this host already | 127 |
| 128 if host.type == "s2sout_unauthed" and (stanza.name ~= "db:verify" or not host.dialback_key) then | 128 -- We have a connection to this host already |
| 129 (host.log or log)("debug", "trying to send over unauthed s2sout to "..to_host); | 129 if host.type == "s2sout_unauthed" and (stanza.name ~= "db:verify" or not host.dialback_key) then |
| 130 | 130 (host.log or log)("debug", "trying to send over unauthed s2sout to "..to_host); |
| 131 -- Queue stanza until we are able to send it | 131 |
| 132 local queued_item = { | 132 -- Queue stanza until we are able to send it |
| 133 tostring(stanza), | 133 local queued_item = { |
| 134 stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza); | 134 tostring(stanza), |
| 135 }; | 135 stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza); |
| 136 if host.sendq then | 136 }; |
| 137 t_insert(host.sendq, queued_item); | 137 if host.sendq then |
| 138 else | 138 t_insert(host.sendq, queued_item); |
| 139 -- luacheck: ignore 122 | 139 else |
| 140 host.sendq = { queued_item }; | 140 -- luacheck: ignore 122 |
| 141 end | 141 host.sendq = { queued_item }; |
| 142 host.log("debug", "stanza [%s] queued ", stanza.name); | 142 end |
| 143 host.log("debug", "stanza [%s] queued ", stanza.name); | |
| 144 return true; | |
| 145 elseif host.type == "local" or host.type == "component" then | |
| 146 log("error", "Trying to send a stanza to ourselves??") | |
| 147 log("error", "Traceback: %s", traceback()); | |
| 148 log("error", "Stanza: %s", stanza); | |
| 149 return false; | |
| 150 else | |
| 151 if host.sends2s(stanza) then | |
| 143 return true; | 152 return true; |
| 144 elseif host.type == "local" or host.type == "component" then | |
| 145 log("error", "Trying to send a stanza to ourselves??") | |
| 146 log("error", "Traceback: %s", traceback()); | |
| 147 log("error", "Stanza: %s", stanza); | |
| 148 return false; | |
| 149 else | |
| 150 if host.sends2s(stanza) then | |
| 151 return true; | |
| 152 end | |
| 153 end | 153 end |
| 154 end | 154 end |
| 155 end | 155 end |
| 156 | 156 |
| 157 -- Create a new outgoing session for a stanza | 157 -- Create a new outgoing session for a stanza |