From 3a2c462c6b037fe5089fc040d1d623b7ba6a1ed3 Mon Sep 17 00:00:00 2001 From: AdamISZ Date: Sat, 26 Jan 2019 20:56:19 +0100 Subject: [PATCH] Fix bug in channel selection in prepare_privmsg Fixes #105. Prior to this commit the channel chosen to send on in a call to MessageChannelCollection.prepare_privmsg was not respect and instead the entry in the active_channels was used, resulting in a Taker not seeing the presence of Makers in other channels than the one chosen here. This meant that in cases of channel disconnection, fallback to other channels was failing (although not always deterministically). This commit fixes this by allowing the sending of the privmsg on a specific channel, as was intended, and so when Makers send messages on multiple channels, they are marked as seen on all those channels, allowing dynamic switching in case of channel connection failures. In addition there are two minor improvements to debug messages. --- jmdaemon/jmdaemon/message_channel.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/jmdaemon/jmdaemon/message_channel.py b/jmdaemon/jmdaemon/message_channel.py index c7eb91a..88773c7 100644 --- a/jmdaemon/jmdaemon/message_channel.py +++ b/jmdaemon/jmdaemon/message_channel.py @@ -144,7 +144,7 @@ class MessageChannelCollection(object): for mc2 in self.available_channels(): if peer in self.nicks_seen[mc2]: log.debug("Dynamically switching: " + peer + " to: " + \ - str(mc2.serverport)) + str(mc2.hostid)) self.active_channels[peer] = mc2 break #Remove all entries for the newly unavailable channel @@ -235,12 +235,16 @@ class MessageChannelCollection(object): #to the signature; this prevents cross-channel replay but NOT #same-channel replay (in case of snooper after dropped connection #on this channel). - if nick in self.active_channels: - hostid = self.active_channels[nick].hostid + if mc is None: + if nick in self.active_channels: + hostid = self.active_channels[nick].hostid + else: + log.info("Failed to send message to: " + str(nick) + \ + "; cannot find on any message channel.") + return else: - log.info("Failed to send message to: " + str(nick) + \ - "; cannot find on any message channel.") - return + hostid = mc.hostid + msg_to_be_signed = message + str(hostid) self.daemon.request_signed_message(nick, cmd, message, msg_to_be_signed, @@ -402,8 +406,10 @@ class MessageChannelCollection(object): """ self.mc_status[mc] = 2 self.flush_nicks() + # construct a readable nicks seen: + readablens = dict([(k.hostid, self.nicks_seen[k]) for k in self.nicks_seen]) log.debug("On disconnect fired, nicks_seen is now: " + str( - self.nicks_seen) + " " + mc.hostid) + readablens) + " " + mc.hostid) if not any([x == 1 for x in self.mc_status.values()]): if self.on_disconnect: self.on_disconnect()