Browse Source

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.
master
Adam Gibson 4 years ago
parent
commit
e915daef88
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 1
      jmclient/jmclient/configure.py
  2. 15
      jmdaemon/jmdaemon/onionmc.py
  3. 2
      scripts/obwatch/ob-watcher.py

1
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

15
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:

2
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))

Loading…
Cancel
Save