Software /
code /
prosody
Comparison
plugins/mod_c2s.lua @ 7666:03aa330562ed
Merge 0.10->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 12 Sep 2016 22:31:25 +0100 |
parent | 7542:0f92dc8e8b88 |
parent | 7662:946871f6e3c8 |
child | 7868:11fcdef5022f |
comparison
equal
deleted
inserted
replaced
7661:37ab6c6326fe | 7666:03aa330562ed |
---|---|
26 | 26 |
27 local c2s_timeout = module:get_option_number("c2s_timeout"); | 27 local c2s_timeout = module:get_option_number("c2s_timeout"); |
28 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); | 28 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); |
29 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); | 29 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); |
30 | 30 |
31 local measure_connections = module:measure("connections", "counter"); | 31 local measure_connections = module:measure("connections", "amount"); |
32 | 32 |
33 local sessions = module:shared("sessions"); | 33 local sessions = module:shared("sessions"); |
34 local core_process_stanza = prosody.core_process_stanza; | 34 local core_process_stanza = prosody.core_process_stanza; |
35 local hosts = prosody.hosts; | 35 local hosts = prosody.hosts; |
36 | 36 |
37 local stream_callbacks = { default_ns = "jabber:client" }; | 37 local stream_callbacks = { default_ns = "jabber:client" }; |
38 local listener = {}; | 38 local listener = {}; |
39 local runner_callbacks = {}; | 39 local runner_callbacks = {}; |
40 | 40 |
41 do | 41 module:hook("stats-update", function () |
42 -- Connection counter resets to 0 on load and reload | 42 -- Connection counter resets to 0 on load and reload |
43 -- Bump it up to current value | 43 -- Bump it up to current value |
44 local count = 0; | 44 local count = 0; |
45 for _ in pairs(sessions) do | 45 for _ in pairs(sessions) do |
46 count = count + 1; | 46 count = count + 1; |
47 end | 47 end |
48 measure_connections(count); | 48 measure_connections(count); |
49 end | 49 end); |
50 | 50 |
51 --- Stream events handlers | 51 --- Stream events handlers |
52 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; | 52 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
53 | 53 |
54 function stream_callbacks.streamopened(session, attr) | 54 function stream_callbacks.streamopened(session, attr) |
216 (self.data.log or log)("error", "Traceback[c2s]: %s", err); | 216 (self.data.log or log)("error", "Traceback[c2s]: %s", err); |
217 end | 217 end |
218 | 218 |
219 --- Port listener | 219 --- Port listener |
220 function listener.onconnect(conn) | 220 function listener.onconnect(conn) |
221 measure_connections(1); | |
222 local session = sm_new_session(conn); | 221 local session = sm_new_session(conn); |
223 sessions[conn] = session; | 222 sessions[conn] = session; |
224 | 223 |
225 session.log("info", "Client connected"); | 224 session.log("info", "Client connected"); |
226 | 225 |
289 session.data(data); | 288 session.data(data); |
290 end | 289 end |
291 end | 290 end |
292 | 291 |
293 function listener.ondisconnect(conn, err) | 292 function listener.ondisconnect(conn, err) |
294 measure_connections(-1); | |
295 local session = sessions[conn]; | 293 local session = sessions[conn]; |
296 if session then | 294 if session then |
297 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); | 295 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); |
298 sm_destroy_session(session, err); | 296 sm_destroy_session(session, err); |
299 session.conn = nil; | 297 session.conn = nil; |