Software /
code /
prosody
Comparison
plugins/mod_s2s.lua @ 11668:f18fbae6d9fe
mod_s2s: Use module API to fire events
These direct accesses are probably more optimized, but weird when the
module API has methods for these things.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 11 Jul 2021 12:36:08 +0200 |
parent | 11624:1b7669c49459 |
child | 11669:bca75f34d374 |
comparison
equal
deleted
inserted
replaced
11667:7417e61dfbe1 | 11668:f18fbae6d9fe |
---|---|
23 local new_xmpp_stream = require "util.xmppstream".new; | 23 local new_xmpp_stream = require "util.xmppstream".new; |
24 local s2s_new_incoming = require "core.s2smanager".new_incoming; | 24 local s2s_new_incoming = require "core.s2smanager".new_incoming; |
25 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; | 25 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; |
26 local s2s_destroy_session = require "core.s2smanager".destroy_session; | 26 local s2s_destroy_session = require "core.s2smanager".destroy_session; |
27 local uuid_gen = require "util.uuid".generate; | 27 local uuid_gen = require "util.uuid".generate; |
28 local fire_global_event = prosody.events.fire_event; | |
29 local runner = require "util.async".runner; | 28 local runner = require "util.async".runner; |
30 local connect = require "net.connect".connect; | 29 local connect = require "net.connect".connect; |
31 local service = require "net.resolvers.service"; | 30 local service = require "net.resolvers.service"; |
32 local errors = require "util.error"; | 31 local errors = require "util.error"; |
33 local set = require "util.set"; | 32 local set = require "util.set"; |
270 | 269 |
271 session.log("info", "%s s2s connection %s->%s complete", session.direction:gsub("^.", string.upper), from, to); | 270 session.log("info", "%s s2s connection %s->%s complete", session.direction:gsub("^.", string.upper), from, to); |
272 | 271 |
273 local event_data = { session = session }; | 272 local event_data = { session = session }; |
274 if session.type == "s2sout" then | 273 if session.type == "s2sout" then |
275 fire_global_event("s2sout-established", event_data); | 274 module:fire_event("s2sout-established", event_data); |
276 hosts[from].events.fire_event("s2sout-established", event_data); | 275 module:context(from):fire_event("s2sout-established", event_data); |
277 | 276 |
278 if session.incoming then | 277 if session.incoming then |
279 session.send = function(stanza) | 278 session.send = function(stanza) |
280 return hosts[from].events.fire_event("route/remote", { from_host = from, to_host = to, stanza = stanza }); | 279 return module:context(from):fire_event("route/remote", { from_host = from, to_host = to, stanza = stanza }); |
281 end; | 280 end; |
282 end | 281 end |
283 | 282 |
284 else | 283 else |
285 if session.outgoing and not hosts[to].s2sout[from] then | 284 if session.outgoing and not hosts[to].s2sout[from] then |
289 local host_session = hosts[to]; | 288 local host_session = hosts[to]; |
290 session.send = function(stanza) | 289 session.send = function(stanza) |
291 return host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza }); | 290 return host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza }); |
292 end; | 291 end; |
293 | 292 |
294 fire_global_event("s2sin-established", event_data); | 293 module:fire_event("s2sin-established", event_data); |
295 hosts[to].events.fire_event("s2sin-established", event_data); | 294 module:context(to):fire_event("s2sin-established", event_data); |
296 end | 295 end |
297 | 296 |
298 if session.direction == "outgoing" then | 297 if session.direction == "outgoing" then |
299 if sendq then | 298 if sendq then |
300 session.log("debug", "sending %d queued stanzas across new outgoing connection to %s", #sendq, session.to_host); | 299 session.log("debug", "sending %d queued stanzas across new outgoing connection to %s", #sendq, session.to_host); |
469 session.notopen = nil; | 468 session.notopen = nil; |
470 if session.version >= 1.0 then | 469 if session.version >= 1.0 then |
471 local features = st.stanza("stream:features"); | 470 local features = st.stanza("stream:features"); |
472 | 471 |
473 if to then | 472 if to then |
474 hosts[to].events.fire_event("s2s-stream-features", { origin = session, features = features }); | 473 module:context(to):fire_event("s2s-stream-features", { origin = session, features = features }); |
475 else | 474 else |
476 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host"); | 475 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host"); |
477 fire_global_event("s2s-stream-features-legacy", { origin = session, features = features }); | 476 module:fire_event("s2s-stream-features-legacy", { origin = session, features = features }); |
478 end | 477 end |
479 | 478 |
480 if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then | 479 if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then |
481 log("debug", "Sending stream features: %s", features); | 480 log("debug", "Sending stream features: %s", features); |
482 session.sends2s(features); | 481 session.sends2s(features); |
501 end | 500 end |
502 | 501 |
503 -- If server is pre-1.0, don't wait for features, just do dialback | 502 -- If server is pre-1.0, don't wait for features, just do dialback |
504 if session.version < 1.0 then | 503 if session.version < 1.0 then |
505 if not session.dialback_verifying then | 504 if not session.dialback_verifying then |
506 hosts[session.from_host].events.fire_event("s2sout-authenticate-legacy", { origin = session }); | 505 module:context(session.from_host):fire_event("s2sout-authenticate-legacy", { origin = session }); |
507 else | 506 else |
508 mark_connected(session); | 507 mark_connected(session); |
509 end | 508 end |
510 end | 509 end |
511 end | 510 end |