Comparison

plugins/mod_bosh.lua @ 7653:17e42f793341

mod_bosh: Make 'hold' and 'requests' fixed to '1' and '2' respectively, as this is what all implementations realistically use
author Matthew Wild <mwild1@gmail.com>
date Fri, 02 Sep 2016 22:13:54 +0100
parent 7652:7cc3d6c764ce
child 7654:b40776ee2aef
child 7659:449de852cf38
comparison
equal deleted inserted replaced
7652:7cc3d6c764ce 7653:17e42f793341
28 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) 28 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send)
29 29
30 local stream_callbacks = { 30 local stream_callbacks = {
31 stream_ns = xmlns_bosh, stream_tag = "body", default_ns = "jabber:client" }; 31 stream_ns = xmlns_bosh, stream_tag = "body", default_ns = "jabber:client" };
32 32
33 local BOSH_DEFAULT_HOLD = module:get_option_number("bosh_default_hold", 1); 33 -- These constants are implicitly assumed within the code, and cannot be changed
34 local BOSH_DEFAULT_INACTIVITY = module:get_option_number("bosh_max_inactivity", 60); 34 local BOSH_HOLD = 1;
35 local BOSH_DEFAULT_POLLING = module:get_option_number("bosh_max_polling", 5); 35 local BOSH_MAX_REQUESTS = 2;
36 local BOSH_DEFAULT_REQUESTS = module:get_option_number("bosh_max_requests", 2); 36
37 -- The number of seconds a BOSH session should remain open with no requests
38 local bosh_max_inactivity = module:get_option_number("bosh_max_inactivity", 60);
39 -- The minimum amount of time between requests with no payload
40 local bosh_max_polling = module:get_option_number("bosh_max_polling", 5);
41 -- The maximum amount of time that the server will hold onto a request before replying
42 -- (the client can set this to a lower value when it connects, if it chooses)
37 local bosh_max_wait = module:get_option_number("bosh_max_wait", 120); 43 local bosh_max_wait = module:get_option_number("bosh_max_wait", 120);
38 44
39 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); 45 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure");
40 local cross_domain = module:get_option("cross_domain_bosh", false); 46 local cross_domain = module:get_option("cross_domain_bosh", false);
41 47
145 if inactive_sessions[session] and #session.requests > 0 then 151 if inactive_sessions[session] and #session.requests > 0 then
146 inactive_sessions[session] = nil; 152 inactive_sessions[session] = nil;
147 end 153 end
148 154
149 local r = session.requests; 155 local r = session.requests;
150 log("debug", "Session %s has %d out of %d requests open", context.sid, #r, session.bosh_hold); 156 log("debug", "Session %s has %d out of %d requests open", context.sid, #r, BOSH_HOLD);
151 log("debug", "and there are %d things in the send_buffer:", #session.send_buffer); 157 log("debug", "and there are %d things in the send_buffer:", #session.send_buffer);
152 if #r > session.bosh_hold then 158 if #r > BOSH_HOLD then
153 -- We are holding too many requests, send what's in the buffer, 159 -- We are holding too many requests, send what's in the buffer,
154 log("debug", "We are holding too many requests, so..."); 160 log("debug", "We are holding too many requests, so...");
155 if #session.send_buffer > 0 then 161 if #session.send_buffer > 0 then
156 log("debug", "...sending what is in the buffer") 162 log("debug", "...sending what is in the buffer")
157 session.send(t_concat(session.send_buffer)); 163 session.send(t_concat(session.send_buffer));
275 -- New session 281 -- New session
276 sid = new_uuid(); 282 sid = new_uuid();
277 local session = { 283 local session = {
278 type = "c2s_unauthed", conn = {}, sid = sid, rid = rid, host = attr.to, 284 type = "c2s_unauthed", conn = {}, sid = sid, rid = rid, host = attr.to,
279 bosh_version = attr.ver, bosh_wait = wait, streamid = sid, 285 bosh_version = attr.ver, bosh_wait = wait, streamid = sid,
280 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, 286 bosh_max_inactive = bosh_max_inactivity,
281 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, 287 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream,
282 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true, 288 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true,
283 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, 289 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure,
284 ip = get_ip_from_request(request); 290 ip = get_ip_from_request(request);
285 }; 291 };
315 type = session.bosh_terminate and "terminate" or nil; 321 type = session.bosh_terminate and "terminate" or nil;
316 sid = sid; 322 sid = sid;
317 }; 323 };
318 if creating_session then 324 if creating_session then
319 creating_session = nil; 325 creating_session = nil;
320 body_attr.inactivity = tostring(BOSH_DEFAULT_INACTIVITY); 326 body_attr.requests = tostring(BOSH_MAX_REQUESTS);
321 body_attr.polling = tostring(BOSH_DEFAULT_POLLING); 327 body_attr.hold = tostring(BOSH_HOLD);
322 body_attr.requests = tostring(BOSH_DEFAULT_REQUESTS); 328 body_attr.inactivity = tostring(bosh_max_inactivity);
329 body_attr.polling = tostring(bosh_max_polling);
323 body_attr.wait = tostring(session.bosh_wait); 330 body_attr.wait = tostring(session.bosh_wait);
324 body_attr.hold = tostring(session.bosh_hold);
325 body_attr.authid = sid; 331 body_attr.authid = sid;
326 body_attr.secure = "true"; 332 body_attr.secure = "true";
327 body_attr.ver = '1.6'; 333 body_attr.ver = '1.6';
328 body_attr.from = session.host; 334 body_attr.from = session.host;
329 body_attr["xmlns:xmpp"] = "urn:xmpp:xbosh"; 335 body_attr["xmlns:xmpp"] = "urn:xmpp:xbosh";