Software /
code /
prosody
Comparison
plugins/mod_bosh.lua @ 5185:ca30b21946ef
mod_bosh: Add bosh_max_wait config option, to limit the amount of time a client can request for the server to hold open requests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Nov 2012 18:24:09 +0000 |
parent | 5179:f3662fea95d9 |
child | 5187:d71f731e8fe4 |
comparison
equal
deleted
inserted
replaced
5183:8461e8ed7c09 | 5185:ca30b21946ef |
---|---|
16 local fire_event = prosody.events.fire_event; | 16 local fire_event = prosody.events.fire_event; |
17 local core_process_stanza = prosody.core_process_stanza; | 17 local core_process_stanza = prosody.core_process_stanza; |
18 local st = require "util.stanza"; | 18 local st = require "util.stanza"; |
19 local logger = require "util.logger"; | 19 local logger = require "util.logger"; |
20 local log = logger.init("mod_bosh"); | 20 local log = logger.init("mod_bosh"); |
21 local math_min = math.min; | |
21 | 22 |
22 local xmlns_streams = "http://etherx.jabber.org/streams"; | 23 local xmlns_streams = "http://etherx.jabber.org/streams"; |
23 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; | 24 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; |
24 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) | 25 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) |
25 | 26 |
28 | 29 |
29 local BOSH_DEFAULT_HOLD = module:get_option_number("bosh_default_hold", 1); | 30 local BOSH_DEFAULT_HOLD = module:get_option_number("bosh_default_hold", 1); |
30 local BOSH_DEFAULT_INACTIVITY = module:get_option_number("bosh_max_inactivity", 60); | 31 local BOSH_DEFAULT_INACTIVITY = module:get_option_number("bosh_max_inactivity", 60); |
31 local BOSH_DEFAULT_POLLING = module:get_option_number("bosh_max_polling", 5); | 32 local BOSH_DEFAULT_POLLING = module:get_option_number("bosh_max_polling", 5); |
32 local BOSH_DEFAULT_REQUESTS = module:get_option_number("bosh_max_requests", 2); | 33 local BOSH_DEFAULT_REQUESTS = module:get_option_number("bosh_max_requests", 2); |
34 local bosh_max_wait = module:get_option_number("bosh_max_wait", 120); | |
33 | 35 |
34 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); | 36 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); |
35 | 37 |
36 local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8" }; | 38 local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8" }; |
37 | 39 |
241 | 243 |
242 -- New session | 244 -- New session |
243 sid = new_uuid(); | 245 sid = new_uuid(); |
244 local session = { | 246 local session = { |
245 type = "c2s_unauthed", conn = {}, sid = sid, rid = tonumber(attr.rid)-1, host = attr.to, | 247 type = "c2s_unauthed", conn = {}, sid = sid, rid = tonumber(attr.rid)-1, host = attr.to, |
246 bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid, | 248 bosh_version = attr.ver, bosh_wait = math_min(attr.wait, bosh_max_wait), streamid = sid, |
247 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, | 249 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, |
248 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, | 250 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, |
249 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true, | 251 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true, |
250 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, | 252 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, |
251 ip = get_ip_from_request(request); | 253 ip = get_ip_from_request(request); |
276 ["xmlns:stream"] = "http://etherx.jabber.org/streams"; | 278 ["xmlns:stream"] = "http://etherx.jabber.org/streams"; |
277 type = session.bosh_terminate and "terminate" or nil; | 279 type = session.bosh_terminate and "terminate" or nil; |
278 sid = sid; | 280 sid = sid; |
279 }; | 281 }; |
280 if creating_session then | 282 if creating_session then |
281 body_attr.wait = attr.wait; | |
282 body_attr.inactivity = tostring(BOSH_DEFAULT_INACTIVITY); | 283 body_attr.inactivity = tostring(BOSH_DEFAULT_INACTIVITY); |
283 body_attr.polling = tostring(BOSH_DEFAULT_POLLING); | 284 body_attr.polling = tostring(BOSH_DEFAULT_POLLING); |
284 body_attr.requests = tostring(BOSH_DEFAULT_REQUESTS); | 285 body_attr.requests = tostring(BOSH_DEFAULT_REQUESTS); |
286 body_attr.wait = tostring(session.bosh_wait); | |
285 body_attr.hold = tostring(session.bosh_hold); | 287 body_attr.hold = tostring(session.bosh_hold); |
286 body_attr.authid = sid; | 288 body_attr.authid = sid; |
287 body_attr.secure = "true"; | 289 body_attr.secure = "true"; |
288 body_attr.ver = '1.6'; from = session.host; | 290 body_attr.ver = '1.6'; from = session.host; |
289 body_attr["xmlns:xmpp"] = "urn:xmpp:xbosh"; | 291 body_attr["xmlns:xmpp"] = "urn:xmpp:xbosh"; |