Software /
code /
prosody
Comparison
plugins/mod_s2s.lua @ 11678:f90a337d81a8
mod_s2s: Remove connection timeout once it's no longer needed
Reduces the number of left-over timers to handle after many s2s
connections were started, leaving only the ones related to incomplete
connections.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 13 Jul 2021 15:04:34 +0200 |
parent | 11670:7f6c816a2c09 |
child | 11682:7843f1ca3b33 |
comparison
equal
deleted
inserted
replaced
11677:98bcc19361db | 11678:f90a337d81a8 |
---|---|
15 local tostring, type = tostring, type; | 15 local tostring, type = tostring, type; |
16 local t_insert = table.insert; | 16 local t_insert = table.insert; |
17 local traceback = debug.traceback; | 17 local traceback = debug.traceback; |
18 | 18 |
19 local add_task = require "util.timer".add_task; | 19 local add_task = require "util.timer".add_task; |
20 local stop_timer = require "util.timer".stop; | |
20 local st = require "util.stanza"; | 21 local st = require "util.stanza"; |
21 local initialize_filters = require "util.filters".initialize; | 22 local initialize_filters = require "util.filters".initialize; |
22 local nameprep = require "util.encodings".stringprep.nameprep; | 23 local nameprep = require "util.encodings".stringprep.nameprep; |
23 local new_xmpp_stream = require "util.xmppstream".new; | 24 local new_xmpp_stream = require "util.xmppstream".new; |
24 local s2s_new_incoming = require "core.s2smanager".new_incoming; | 25 local s2s_new_incoming = require "core.s2smanager".new_incoming; |
303 sendq[i] = nil; | 304 sendq[i] = nil; |
304 end | 305 end |
305 session.sendq = nil; | 306 session.sendq = nil; |
306 end | 307 end |
307 end | 308 end |
309 | |
310 if session.connect_timeout then | |
311 stop_timer(session.connect_timeout); | |
312 session.connect_timeout = nil; | |
313 end | |
308 end | 314 end |
309 | 315 |
310 function make_authenticated(event) | 316 function make_authenticated(event) |
311 local session, host = event.session, event.host; | 317 local session, host = event.session, event.host; |
312 if not session.secure then | 318 if not session.secure then |
610 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction:gsub("^.", string.upper), | 616 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction:gsub("^.", string.upper), |
611 session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed"); | 617 session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed"); |
612 | 618 |
613 conn:resume_writes(); | 619 conn:resume_writes(); |
614 | 620 |
621 if session.connect_timeout then | |
622 stop_timer(session.connect_timeout); | |
623 session.connect_timeout = nil; | |
624 end | |
625 | |
615 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote | 626 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote |
616 if reason == nil and not session.notopen and session.direction == "incoming" then | 627 if reason == nil and not session.notopen and session.direction == "incoming" then |
617 add_task(stream_close_timeout, function () | 628 add_task(stream_close_timeout, function () |
618 if not session.destroyed then | 629 if not session.destroyed then |
619 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); | 630 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); |
704 return handlestanza(session, stanza); | 715 return handlestanza(session, stanza); |
705 end | 716 end |
706 | 717 |
707 module:fire_event("s2s-created", { session = session }); | 718 module:fire_event("s2s-created", { session = session }); |
708 | 719 |
709 add_task(connect_timeout, function () | 720 session.connect_timeout = add_task(connect_timeout, function () |
710 if session.type == "s2sin" or session.type == "s2sout" then | 721 if session.type == "s2sin" or session.type == "s2sout" then |
711 return; -- Ok, we're connected | 722 return; -- Ok, we're connected |
712 elseif session.type == "s2s_destroyed" then | 723 elseif session.type == "s2s_destroyed" then |
713 return; -- Session already destroyed | 724 return; -- Session already destroyed |
714 end | 725 end |