Hubs-Foundation / hubs-discord-bot

A Discord bot that helps you use Hubs together with people in Discord.
Mozilla Public License 2.0
50 stars 31 forks source link

Fix session ID management to be more correct #37

Closed mqp closed 5 years ago

mqp commented 5 years ago

The previous implementation handled expiry incorrectly and was very confusing to think about. This version is much simpler and seems more obviously correct. The only remaining question is that of race conditions related to the time between you "having" a session ID (socket connection) and "knowing about" the session ID (channel join), and we're pretending those don't matter for now.

For simplicity, we now make no effort to reuse the session ID between reconnects, reflecting the reality that session IDs are not currently intended to actually be reliably reused by a user over time.

Note that the store of session IDs belonging to the bot is global, which actually seems "more correct" in the case that you have multiple ReticulumClient objects hanging around -- you would prefer the bot not to respond to messages from other copies of itself. It would be better for it to persist, because then the bot would know about its old session IDs if it restarted and rejoined the same Hubs room. When we implement a persistent data store it should probably go in there.

Also clean up logging to be more helpful and create log entries on reconnects.