Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
fix bug on all channels disconnect
Browse files Browse the repository at this point in the history
check for existence of callbacks
friendlier nick leave message
  • Loading branch information
AdamISZ committed Jun 29, 2016
1 parent eda7c64 commit c3646f0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions joinmarket/message_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def on_disconnect_trigger(self, mc):
self.flush_nicks()
log.debug("On disconnect fired, nicks_seen is now: " + str(self.nicks_seen))
if not any([x==1 for x in self.mc_status.values()]):
self.on_disconnect()
if self.on_disconnect:
self.on_disconnect()

def on_welcome_trigger(self, mc):
"""Update status of specified message channel
Expand All @@ -384,7 +385,8 @@ def on_welcome_trigger(self, mc):
#This way broadcasts orders or requests ONCE to ALL mchans
#which are actually available.
if not any([x == 0 for x in self.mc_status.values()]):
self.on_welcome()
if self.on_welcome:
self.on_welcome()
self.welcomed = True

def on_nick_leave_trigger(self, nick, mc):
Expand All @@ -402,7 +404,8 @@ def on_nick_leave_trigger(self, nick, mc):
#mark the nick as 'unseen' on that channel
self.unsee_nick(nick, mc)
if nick not in self.active_channels:
self.on_nick_leave(nick)
if self.on_nick_leave:
self.on_nick_leave(nick)
elif self.active_channels[nick] == mc:
del self.active_channels[nick]
#Attempt to dynamically switch channels
Expand All @@ -411,7 +414,8 @@ def on_nick_leave_trigger(self, nick, mc):
if len(other_channels) == 0:
log.debug(
"Cannot reconnect to dropped nick, no connections available.")
self.on_nick_leave(nick)
if self.on_nick_leave:
self.on_nick_leave(nick)
return
for oc in other_channels:
if nick in self.nicks_seen[oc]:
Expand All @@ -422,9 +426,9 @@ def on_nick_leave_trigger(self, nick, mc):
return
#If loop completed without success, we failed to find
#this counterparty anywhere else
log.debug("Failed to find an alternative message channel for: " + nick \
+ ", marking as left from: " + str(mc.serverport))
self.on_nick_leave(nick)
log.debug("Nick: " + nick + " has left.")
if self.on_nick_leave:
self.on_nick_leave(nick)
#The remaining case is if the channel that the
#nick has left is not the one we're currently using.
return
Expand Down Expand Up @@ -485,7 +489,8 @@ def on_order_seen_trigger(self, mc, counterparty, oid, ordertype, minsize,
self.nicks_seen[mc].add(counterparty)

self.active_channels[counterparty] = mc
self.on_order_seen(counterparty, oid, ordertype, minsize, maxsize,
if self.on_order_seen:
self.on_order_seen(counterparty, oid, ordertype, minsize, maxsize,
txfee, cjfee)

# orderbook watcher commands
Expand All @@ -507,7 +512,8 @@ def on_orderbook_requested_trigger(self, nick, mc):
taker on this message channel before pass-through.
"""
self.nicks_seen[mc].add(nick)
self.on_orderbook_requested(nick, mc)
if self.on_orderbook_requested:
self.on_orderbook_requested(nick, mc)

# maker commands
def register_maker_callbacks(self,
Expand Down

0 comments on commit c3646f0

Please sign in to comment.