Skip to content

Commit

Permalink
direct connections for peers
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamISZ committed Nov 1, 2021
1 parent 2cc1ac9 commit c39e3d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion jmdaemon/jmdaemon/jmcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def init(options, configuration, plugin):
@plugin.subscribe("connect")
def on_connect(plugin, id, address, **kwargs):
plugin.log("Received connect event for peer {}".format(id))
send_local_control_message(785, id)
plugin.log("With address: {}".format(address))
send_local_control_message(785, id + "@" + address)

@plugin.subscribe("disconnect")
def on_disconnect(plugin, id, **kwargs):
Expand Down
19 changes: 16 additions & 3 deletions jmdaemon/jmdaemon/lnonion.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ def _privmsg(self, nick, cmd, msg):
encoded_privmsg = LNOnionMessage(self.get_privmsg(nick, cmd, msg),
JM_MESSAGE_TYPES["privmsg"]).encode()
peerid = self.get_peerid_by_nick(nick)
if not peerid:
peer = self.get_peer_by_id(peerid)
if not peerid or not peer or not peer.is_connected:
# If we are trying to message a peer via their nick, we
# may not yet have connection info; then we just
# may not yet have a connection; then we just
# forward via directory nodes.
log.debug("Privmsg peer: {} but don't have peerid; "
"sending via directory.".format(nick))
Expand Down Expand Up @@ -720,12 +721,24 @@ def add_peer(self, peerdata: str, connection: bool=False,
# assumed that it's passing a full string
# TODO need to think about logic of 'is_connected'
# state here.
temp_p = LNOnionPeer.from_location_string(peer)
try:
temp_p = LNOnionPeer.from_location_string(peer)
except Exception as e:
# There are currently a few ways the location
# parsing and Peer object construction can fail;
# TODO specify exception types.
log.warn("Failed to add peer: {}, exception: {}".format(peer, repr(e)))
return
if not self.get_peer_by_id(temp_p.peerid):
temp_p.is_connected = connection
if with_nick:
temp_p.set_nick(nick)
self.peers.add(temp_p)
if not connection:
# Here, we have a full location string,
# and we are not currently connected. We
# try to connect asynchronously:
reactor.callLater(0.0, temp_p.connect, self.rpc_client)
return temp_p
else:
p = self.get_peer_by_id(temp_p.peerid)
Expand Down

0 comments on commit c39e3d0

Please sign in to comment.