Software /
code /
prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 7666:03aa330562ed
Merge 0.10->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 12 Sep 2016 22:31:25 +0100 |
parent | 7647:e9d7a409e236 |
parent | 7662:946871f6e3c8 |
child | 7686:8d6f367bed8c |
comparison
equal
deleted
inserted
replaced
7661:37ab6c6326fe | 7666:03aa330562ed |
---|---|
36 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... | 36 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... |
37 local secure_domains, insecure_domains = | 37 local secure_domains, insecure_domains = |
38 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; | 38 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; |
39 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); | 39 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); |
40 | 40 |
41 local measure_connections = module:measure("connections", "counter"); | 41 local measure_connections = module:measure("connections", "amount"); |
42 | 42 |
43 local sessions = module:shared("sessions"); | 43 local sessions = module:shared("sessions"); |
44 | 44 |
45 local runner_callbacks = {}; | 45 local runner_callbacks = {}; |
46 | 46 |
47 local log = module._log; | 47 local log = module._log; |
48 | 48 |
49 do | 49 module:hook("stats-update", function () |
50 -- Connection counter resets to 0 on load and reload | 50 -- Connection counter resets to 0 on load and reload |
51 -- Bump it up to current value | 51 -- Bump it up to current value |
52 local count = 0; | 52 local count = 0; |
53 for _ in pairs(sessions) do | 53 for _ in pairs(sessions) do |
54 count = count + 1; | 54 count = count + 1; |
55 end | 55 end |
56 measure_connections(count); | 56 measure_connections(count); |
57 end | 57 end); |
58 | 58 |
59 --- Handle stanzas to remote domains | 59 --- Handle stanzas to remote domains |
60 | 60 |
61 local bouncy_stanzas = { message = true, presence = true, iq = true }; | 61 local bouncy_stanzas = { message = true, presence = true, iq = true }; |
62 local function bounce_sendq(session, reason) | 62 local function bounce_sendq(session, reason) |
617 function runner_callbacks:error(err) | 617 function runner_callbacks:error(err) |
618 (self.data.log or log)("error", "Traceback[s2s]: %s", err); | 618 (self.data.log or log)("error", "Traceback[s2s]: %s", err); |
619 end | 619 end |
620 | 620 |
621 function listener.onconnect(conn) | 621 function listener.onconnect(conn) |
622 measure_connections(1); | |
623 conn:setoption("keepalive", opt_keepalives); | 622 conn:setoption("keepalive", opt_keepalives); |
624 local session = sessions[conn]; | 623 local session = sessions[conn]; |
625 if not session then -- New incoming connection | 624 if not session then -- New incoming connection |
626 session = s2s_new_incoming(conn); | 625 session = s2s_new_incoming(conn); |
627 sessions[conn] = session; | 626 sessions[conn] = session; |
648 session:open_stream(session.from_host, session.to_host); | 647 session:open_stream(session.from_host, session.to_host); |
649 end | 648 end |
650 end | 649 end |
651 end | 650 end |
652 | 651 |
653 function listener.ontimeout(conn) | |
654 -- Called instead of onconnect when the connection times out | |
655 measure_connections(1); | |
656 end | |
657 | |
658 function listener.ondisconnect(conn, err) | 652 function listener.ondisconnect(conn, err) |
659 measure_connections(-1); | |
660 local session = sessions[conn]; | 653 local session = sessions[conn]; |
661 if session then | 654 if session then |
662 sessions[conn] = nil; | 655 sessions[conn] = nil; |
663 if err and session.direction == "outgoing" and session.notopen then | 656 if err and session.direction == "outgoing" and session.notopen then |
664 (session.log or log)("debug", "s2s connection attempt failed: %s", err); | 657 (session.log or log)("debug", "s2s connection attempt failed: %s", err); |