139 return; |
139 return; |
140 end |
140 end |
141 |
141 |
142 -- New session |
142 -- New session |
143 sid = new_uuid(); |
143 sid = new_uuid(); |
144 local session = { type = "c2s_unauthed", conn = {}, sid = sid, rid = attr.rid, host = attr.to, bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid, |
144 local session = { type = "c2s_unauthed", conn = {}, sid = sid, rid = tonumber(attr.rid), host = attr.to, bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid, |
145 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, |
145 bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, |
146 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, close = bosh_close_stream, |
146 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, close = bosh_close_stream, |
147 dispatch_stanza = core_process_stanza, log = logger.init("bosh"..sid), secure = request.secure }; |
147 dispatch_stanza = core_process_stanza, log = logger.init("bosh"..sid), secure = request.secure }; |
148 sessions[sid] = session; |
148 sessions[sid] = session; |
149 |
149 |
204 request:send{ headers = default_headers, body = tostring(st.stanza("body", { xmlns = xmlns_bosh, type = "terminate", condition = "item-not-found" })) }; |
204 request:send{ headers = default_headers, body = tostring(st.stanza("body", { xmlns = xmlns_bosh, type = "terminate", condition = "item-not-found" })) }; |
205 request.notopen = nil; |
205 request.notopen = nil; |
206 return; |
206 return; |
207 end |
207 end |
208 |
208 |
|
209 if session.rid then |
|
210 local rid = tonumber(attr.rid); |
|
211 if rid - session.rid > 1 then |
|
212 session.log("warn", "rid too large (means a request was lost). Last rid: %d New rid: %s", session.rid, attr.rid); |
|
213 elseif session.rid >= rid then |
|
214 -- Repeated, ignore |
|
215 session.log("debug", "rid repeated (on request %s), ignoring: %d", request.id, session.rid); |
|
216 request.notopen = nil; |
|
217 t_insert(session.requests, request); |
|
218 return; |
|
219 end |
|
220 request.rid = rid; |
|
221 session.rid = rid; |
|
222 end |
|
223 |
209 if attr.type == "terminate" then |
224 if attr.type == "terminate" then |
210 -- Client wants to end this session |
225 -- Client wants to end this session |
211 session:close(); |
226 session:close(); |
212 request.notopen = nil; |
227 request.notopen = nil; |
213 return; |
228 return; |