Mercurial > prosody-hg
comparison core/sessionmanager.lua @ 12677:3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 26 Aug 2022 17:04:15 +0100 |
| parents | 07424992d7fc |
| children | b95771171439 |
comparison
equal
deleted
inserted
replaced
| 12676:3ab3ef9584e3 | 12677:3b9771d496ed |
|---|---|
| 8 -- luacheck: globals prosody.full_sessions prosody.bare_sessions | 8 -- luacheck: globals prosody.full_sessions prosody.bare_sessions |
| 9 | 9 |
| 10 local tostring, setmetatable = tostring, setmetatable; | 10 local tostring, setmetatable = tostring, setmetatable; |
| 11 local pairs, next= pairs, next; | 11 local pairs, next= pairs, next; |
| 12 | 12 |
| 13 local hosts = prosody.hosts; | 13 local prosody, hosts = prosody, prosody.hosts; |
| 14 local full_sessions = prosody.full_sessions; | 14 local full_sessions = prosody.full_sessions; |
| 15 local bare_sessions = prosody.bare_sessions; | 15 local bare_sessions = prosody.bare_sessions; |
| 16 | 16 |
| 17 local logger = require "util.logger"; | 17 local logger = require "util.logger"; |
| 18 local log = logger.init("sessionmanager"); | 18 local log = logger.init("sessionmanager"); |
| 88 function session.send(data) log("debug", "Discarding data sent to resting session: %s", data); return false; end | 88 function session.send(data) log("debug", "Discarding data sent to resting session: %s", data); return false; end |
| 89 function session.rawsend(data) log("debug", "Discarding data sent to resting session: %s", data); return false; end | 89 function session.rawsend(data) log("debug", "Discarding data sent to resting session: %s", data); return false; end |
| 90 function session.data(data) log("debug", "Discarding data received from resting session: %s", data); end | 90 function session.data(data) log("debug", "Discarding data received from resting session: %s", data); end |
| 91 session.thread = { run = function (_, data) return session.data(data) end }; | 91 session.thread = { run = function (_, data) return session.data(data) end }; |
| 92 return setmetatable(session, resting_session); | 92 return setmetatable(session, resting_session); |
| 93 end | |
| 94 | |
| 95 -- Update a session with a new one (transplanting connection, filters, etc.) | |
| 96 -- new_session should be discarded after this call returns | |
| 97 local function update_session(to_session, from_session) | |
| 98 to_session.log("debug", "Updating with parameters from session %s", from_session.id); | |
| 99 from_session.log("debug", "Session absorbed into %s", to_session.id); | |
| 100 | |
| 101 local replaced_conn = to_session.conn; | |
| 102 if replaced_conn then | |
| 103 to_session.log("debug", "closing a replaced connection for this session"); | |
| 104 replaced_conn:close(); | |
| 105 end | |
| 106 | |
| 107 to_session.ip = from_session.ip; | |
| 108 to_session.conn = from_session.conn; | |
| 109 to_session.rawsend = from_session.rawsend; | |
| 110 to_session.rawsend.session = to_session; | |
| 111 to_session.rawsend.conn = to_session.conn; | |
| 112 to_session.send = from_session.send; | |
| 113 to_session.send.session = to_session; | |
| 114 to_session.close = from_session.close; | |
| 115 to_session.filter = from_session.filter; | |
| 116 to_session.filter.session = to_session; | |
| 117 to_session.filters = from_session.filters; | |
| 118 to_session.send.filter = to_session.filter; | |
| 119 to_session.stream = from_session.stream; | |
| 120 to_session.secure = from_session.secure; | |
| 121 to_session.hibernating = nil; | |
| 122 to_session.resumption_counter = (to_session.resumption_counter or 0) + 1; | |
| 123 from_session.log = to_session.log; | |
| 124 from_session.type = to_session.type; | |
| 125 -- Inform xmppstream of the new session (passed to its callbacks) | |
| 126 to_session.stream:set_session(to_session); | |
| 127 | |
| 128 -- Retire the session we've pulled from, to avoid two sessions on the same connection | |
| 129 retire_session(from_session); | |
| 130 | |
| 131 prosody.events.fire_event("c2s-session-updated", { | |
| 132 session = to_session; | |
| 133 from_session = from_session; | |
| 134 replaced_conn = replaced_conn; | |
| 135 }); | |
| 93 end | 136 end |
| 94 | 137 |
| 95 local function destroy_session(session, err) | 138 local function destroy_session(session, err) |
| 96 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", | 139 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", |
| 97 session.full_jid or "(unknown)", session.username or "(unknown)", | 140 session.full_jid or "(unknown)", session.username or "(unknown)", |
| 265 end | 308 end |
| 266 | 309 |
| 267 return { | 310 return { |
| 268 new_session = new_session; | 311 new_session = new_session; |
| 269 retire_session = retire_session; | 312 retire_session = retire_session; |
| 313 update_session = update_session; | |
| 270 destroy_session = destroy_session; | 314 destroy_session = destroy_session; |
| 271 make_authenticated = make_authenticated; | 315 make_authenticated = make_authenticated; |
| 272 bind_resource = bind_resource; | 316 bind_resource = bind_resource; |
| 273 send_to_available_resources = send_to_available_resources; | 317 send_to_available_resources = send_to_available_resources; |
| 274 send_to_interested_resources = send_to_interested_resources; | 318 send_to_interested_resources = send_to_interested_resources; |
