+ origin.hosts[attr.from] = { dialback_key = stanza[1] };
+
+ if not hosts[attr.to] then
+ -- Not a host that we serve
+ origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to);
+ origin:close("host-unknown");
+ return true;
+ end
+
+ dialback_requests[attr.from.."/"..origin.streamid] = origin;
+
+ if not origin.from_host then
+ -- Just used for friendlier logging
+ origin.from_host = attr.from;
+ -- COMPAT: Fix ejabberd chopness by resetting the send function
+ origin.log("debug", "Remote server didn't specify a from attr, resetting session.send now that we know where to knock to.");
+ origin.send = function(stanza) hosts[attr.to].events.fire_event("route/remote", { from_host = origin.to_host, to_host = origin.from_host, stanza = stanza}); end
+ end
+ if not origin.to_host then
+ -- Just used for friendlier logging
+ origin.to_host = attr.to;
+ end
+
+ origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]);
+ origin.send(st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1]));
+ return true;
+ end
+end);
+
+module:hook("stanza/jabber:server:dialback:verify", function(event)
+ local origin, stanza = event.origin, event.stanza;
+
+ if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then