Software /
code /
prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 7662:946871f6e3c8
mod_c2s, mod_s2s: Switch connection counting to 'amount' type and enumerate once per statistics interval
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 12 Sep 2016 15:01:16 +0200 |
parent | 7642:2dcb402c4a0d |
child | 7666:03aa330562ed |
child | 7679:589e27b47d56 |
comparison
equal
deleted
inserted
replaced
7659:449de852cf38 | 7662:946871f6e3c8 |
---|---|
35 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... | 35 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... |
36 local secure_domains, insecure_domains = | 36 local secure_domains, insecure_domains = |
37 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; | 37 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; |
38 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); | 38 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); |
39 | 39 |
40 local measure_connections = module:measure("connections", "counter"); | 40 local measure_connections = module:measure("connections", "amount"); |
41 | 41 |
42 local sessions = module:shared("sessions"); | 42 local sessions = module:shared("sessions"); |
43 | 43 |
44 local log = module._log; | 44 local log = module._log; |
45 | 45 |
46 do | 46 module:hook("stats-update", function () |
47 -- Connection counter resets to 0 on load and reload | 47 -- Connection counter resets to 0 on load and reload |
48 -- Bump it up to current value | 48 -- Bump it up to current value |
49 local count = 0; | 49 local count = 0; |
50 for _ in pairs(sessions) do | 50 for _ in pairs(sessions) do |
51 count = count + 1; | 51 count = count + 1; |
52 end | 52 end |
53 measure_connections(count); | 53 measure_connections(count); |
54 end | 54 end); |
55 | 55 |
56 --- Handle stanzas to remote domains | 56 --- Handle stanzas to remote domains |
57 | 57 |
58 local bouncy_stanzas = { message = true, presence = true, iq = true }; | 58 local bouncy_stanzas = { message = true, presence = true, iq = true }; |
59 local function bounce_sendq(session, reason) | 59 local function bounce_sendq(session, reason) |
586 session:close("connection-timeout"); | 586 session:close("connection-timeout"); |
587 end); | 587 end); |
588 end | 588 end |
589 | 589 |
590 function listener.onconnect(conn) | 590 function listener.onconnect(conn) |
591 measure_connections(1); | |
592 conn:setoption("keepalive", opt_keepalives); | 591 conn:setoption("keepalive", opt_keepalives); |
593 local session = sessions[conn]; | 592 local session = sessions[conn]; |
594 if not session then -- New incoming connection | 593 if not session then -- New incoming connection |
595 session = s2s_new_incoming(conn); | 594 session = s2s_new_incoming(conn); |
596 sessions[conn] = session; | 595 sessions[conn] = session; |
617 session:open_stream(session.from_host, session.to_host); | 616 session:open_stream(session.from_host, session.to_host); |
618 end | 617 end |
619 end | 618 end |
620 end | 619 end |
621 | 620 |
622 function listener.ontimeout(conn) | |
623 -- Called instead of onconnect when the connection times out | |
624 measure_connections(1); | |
625 end | |
626 | |
627 function listener.ondisconnect(conn, err) | 621 function listener.ondisconnect(conn, err) |
628 measure_connections(-1); | |
629 local session = sessions[conn]; | 622 local session = sessions[conn]; |
630 if session then | 623 if session then |
631 sessions[conn] = nil; | 624 sessions[conn] = nil; |
632 if err and session.direction == "outgoing" and session.notopen then | 625 if err and session.direction == "outgoing" and session.notopen then |
633 (session.log or log)("debug", "s2s connection attempt failed: %s", err); | 626 (session.log or log)("debug", "s2s connection attempt failed: %s", err); |