From e915daef8819b812e0946757b2e366407aa3885a Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Wed, 6 Apr 2022 09:52:49 +0100 Subject: [PATCH] Passive mode for ob-watcher bots on onion-mc Prior to this commit, running ob-watcher with an onion-type message channel configured would result in the bot attempting to connect to all the makers, which is bad. This happened because the internal logic of the onion message channel is that receivers of privmsgs will be sent peer info from the directory, so that they can immediately respond p2p if they succeed in outward connecting. But for bots who do not intend to engage in a coinjoin interactive protocol, like ob-watchers, this is absolutely not the desired outcome. After this commit, a bot can specify mode "PASSIVE" in the call to get_mchannels(), which results in the OnionMessageChannel object only creating non-directory remote peer objects of type OnionPeerPassive, instead of OnionPeer, which means they never try to connect to those remote peers. --- jmclient/jmclient/configure.py | 1 + jmdaemon/jmdaemon/onionmc.py | 15 ++++++++++++++- scripts/obwatch/ob-watcher.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jmclient/jmclient/configure.py b/jmclient/jmclient/configure.py index 2899af6..1fa7c26 100644 --- a/jmclient/jmclient/configure.py +++ b/jmclient/jmclient/configure.py @@ -582,6 +582,7 @@ def get_mchannels(mode="TAKER"): # the onion messaging section must specify whether # to serve an onion: onion_data["serving"] = mode == "MAKER" + onion_data["passive"] = mode == "PASSIVE" onion_data['btcnet'] = get_network() # Just to allow a dynamic set of var: onion_data["section-name"] = s diff --git a/jmdaemon/jmdaemon/onionmc.py b/jmdaemon/jmdaemon/onionmc.py index 400053f..f398ec1 100644 --- a/jmdaemon/jmdaemon/onionmc.py +++ b/jmdaemon/jmdaemon/onionmc.py @@ -551,6 +551,13 @@ class OnionPeer(object): self.update_status(PEER_STATUS_DISCONNECTED) self.factory = None +class OnionPeerPassive(OnionPeer): + """ a type of remote peer that we are + not interested in connecting outwards to. + """ + def try_to_connect(self) -> None: + pass + class OnionDirectoryPeer(OnionPeer): delay = 4.0 def try_to_connect(self) -> None: @@ -603,6 +610,11 @@ class OnionMessageChannel(MessageChannel): # client side config: self.socks5_host = configdata["socks5_host"] self.socks5_port = configdata["socks5_port"] + # passive configuration is for bots who never need/want to connect + # to peers (apart from directories) + self.passive = False + if "passive" in configdata: + self.passive = configdata["passive"] # we use the setting in the config sent over from # the client, to decide whether to set up our connections # over localhost (if testing), without Tor: @@ -1226,9 +1238,10 @@ class OnionMessageChannel(MessageChannel): else: peer = peerdata + cls = OnionPeerPassive if self.passive else OnionPeer # assumed that it's passing a full string try: - temp_p = OnionPeer.from_location_string(self, peer, + temp_p = cls.from_location_string(self, peer, self.socks5_host, self.socks5_port, handshake_callback=self.handshake_as_client) except Exception as e: diff --git a/scripts/obwatch/ob-watcher.py b/scripts/obwatch/ob-watcher.py index f94629b..7835feb 100755 --- a/scripts/obwatch/ob-watcher.py +++ b/scripts/obwatch/ob-watcher.py @@ -807,7 +807,7 @@ def main(): check_and_start_tor() hostport = (options.host, options.port) mcs = [] - chan_configs = get_mchannels() + chan_configs = get_mchannels(mode="PASSIVE") for c in chan_configs: if "type" in c and c["type"] == "onion": mcs.append(OnionMessageChannel(c))