Browse Source

Ensure OnionDirectoryPeerNotFound is raised

Fixes #1306.
Prior to this commit, it was possible (unlikely) for a peer to exist in
the active_directories nick in OnionMessageChannel, but to have False
entries (i.e. disconnected) for every directory, meaning that the random
choice from those directories raised an Exception which was not caught,
causing a crash.
This is now fixed by checking whether the list of directories to be
chosen from randomly, is empty, and if so raising the correct Exception
type, namely OnionDirectoryPeerNotFound.
master
Adam Gibson 4 years ago
parent
commit
c2abb939d6
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 5
      jmdaemon/jmdaemon/onionmc.py

5
jmdaemon/jmdaemon/onionmc.py

@ -1012,7 +1012,10 @@ class OnionMessageChannel(MessageChannel):
adn = self.active_directories[nick]
if len(adn) == 0:
raise OnionDirectoryPeerNotFound
return random.choice([x for x in list(adn) if adn[x] is True])
candidates = [x for x in list(adn) if adn[x] is True]
if len(candidates) == 0:
raise OnionDirectoryPeerNotFound
return random.choice(candidates)
def forward_pubmsg_to_peers(self, msg: str, from_nick: str) -> None:
""" Used by directory nodes currently. Takes a received

Loading…
Cancel
Save