82 |
82 |
83 local all_old_sessions = module:open_store("smacks_h"); |
83 local all_old_sessions = module:open_store("smacks_h"); |
84 local old_session_registry = module:open_store("smacks_h", "map"); |
84 local old_session_registry = module:open_store("smacks_h", "map"); |
85 local session_registry = module:shared "/*/smacks/resumption-tokens"; -- > user@host/resumption-token --> resource |
85 local session_registry = module:shared "/*/smacks/resumption-tokens"; -- > user@host/resumption-token --> resource |
86 |
86 |
|
87 local function registry_key(session, id) |
|
88 return jid.join(session.username, session.host, id or session.resumption_token); |
|
89 end |
|
90 |
87 local function track_session(session, id) |
91 local function track_session(session, id) |
88 session_registry[jid.join(session.username, session.host, id or session.resumption_token)] = session; |
92 session_registry[registry_key(session, id)] = session; |
89 session.resumption_token = id; |
93 session.resumption_token = id; |
90 end |
94 end |
91 |
95 |
92 local function save_old_session(session) |
96 local function save_old_session(session) |
93 session_registry[jid.join(session.username, session.host, session.resumption_token)] = nil; |
97 session_registry[registry_key(session)] = nil; |
94 return old_session_registry:set(session.username, session.resumption_token, |
98 return old_session_registry:set(session.username, session.resumption_token, |
95 { h = session.handled_stanza_count; t = os.time() }) |
99 { h = session.handled_stanza_count; t = os.time() }) |
96 end |
100 end |
97 |
101 |
98 local function clear_old_session(session, id) |
102 local function clear_old_session(session, id) |
99 session_registry[jid.join(session.username, session.host, id or session.resumption_token)] = nil; |
103 session_registry[registry_key(session, id)] = nil; |
100 return old_session_registry:set(session.username, id or session.resumption_token, nil) |
104 return old_session_registry:set(session.username, id or session.resumption_token, nil) |
101 end |
105 end |
102 |
106 |
103 local ack_errors = require"util.error".init("mod_smacks", xmlns_sm3, { |
107 local ack_errors = require"util.error".init("mod_smacks", xmlns_sm3, { |
104 head = { condition = "undefined-condition"; text = "Client acknowledged more stanzas than sent by server" }; |
108 head = { condition = "undefined-condition"; text = "Client acknowledged more stanzas than sent by server" }; |
568 session.log("warn", "Tried to resume after resource binding"); |
572 session.log("warn", "Tried to resume after resource binding"); |
569 return nil, enable_errors.new("already_bound"); |
573 return nil, enable_errors.new("already_bound"); |
570 end |
574 end |
571 |
575 |
572 local id = stanza.attr.previd; |
576 local id = stanza.attr.previd; |
573 local original_session = session_registry[jid.join(session.username, session.host, id)]; |
577 local original_session = session_registry[registry_key(session, id)]; |
574 if not original_session then |
578 if not original_session then |
575 local old_session = old_session_registry:get(session.username, id); |
579 local old_session = old_session_registry:get(session.username, id); |
576 if old_session then |
580 if old_session then |
577 session.log("debug", "Tried to resume old expired session with id %s", id); |
581 session.log("debug", "Tried to resume old expired session with id %s", id); |
578 clear_old_session(session, id); |
582 clear_old_session(session, id); |