diff --git a/server.py b/server.py index 75d176788ff89a68859e6859b69952b7e4bb0b03..4140243aa6e2928cccd3ca52e1716ad3482d1b55 100644 --- a/server.py +++ b/server.py @@ -397,6 +397,7 @@ class ServerThread(Thread): tx.can_confirm = last_node if not entry_node: tx.sender_hash = peer.hash + peer.up_in = True utils.logprint("TX "+tx.sender_pubkey[:8]+" -> "+tx.receiver_pubkey[:8]+" = "+str(tx.in_amount)+":"+str(tx.in_base)+" -> "+str(tx.out_amount)+":"+str(tx.out_base), utils.LOG_TRACE) self.tx_out_index[out_seeds[1]] = tx self.tx_in_index[in_seeds[1]] = tx @@ -467,6 +468,7 @@ class ServerThread(Thread): tx.can_confirm = True resp["confirm_ok"] = tx.out_seeds[2] + peer.up_in = True if "getconfirm" in url: sender_pubkey = utils.getargv("getconfirm", "", 1, url) @@ -517,6 +519,7 @@ class ServerThread(Thread): utils.logprint("Peer: have more recent sig: "+new_peer.to_human_str(), utils.LOG_WARN) continue + new_peer.up_in = True utils.logprint("Peer: "+new_peer.to_human_str(), utils.LOG_TRACE) self.peers[new_peer.hash] = new_peer @@ -576,6 +579,7 @@ class ClientThread(Thread): # Ask the chosen peer try: header, content = utils.sdata(peer.host, "GET", "/peers/info", proxy=self.conf["client"]["proxy"], proxy_onion_only=self.conf["client"]["proxy_onion_only"]) + peer.up_out = True try: data = ubjson.loadb(content) @@ -606,6 +610,7 @@ class ClientThread(Thread): answered += 1 except (ConnectionRefusedError, socks.GeneralProxyError, socket.gaierror, socket.timeout): + peer.up_out = False utils.logprint("Peer detection: Network error: "+peer.to_human_str(), utils.LOG_WARN) # Choose the more recent peer infos @@ -640,7 +645,9 @@ class ClientThread(Thread): for peer in self.peers: try: utils.sdata(self.peers[peer].host, "POST", "/new", self.local_peer.raw, proxy=self.conf["client"]["proxy"], proxy_onion_only=self.conf["client"]["proxy_onion_only"]) + peer.up_out = True except (ConnectionRefusedError, socks.GeneralProxyError, socket.gaierror, socket.timeout): + peer.up_out = False utils.logprint("Network error: "+self.peers[peer].to_human_str(), utils.LOG_WARN) utils.logprint("Finished spreading peer info", utils.LOG_TRACE) @@ -762,10 +769,11 @@ class ClientThread(Thread): try: header, content = utils.sdata(peer.host, "POST", "/mix/"+base64.urlsafe_b64encode(self.local_peer.hash).decode()+"/"+str(tx.out_amount)+"/"+str(tx.out_base), message, proxy=self.conf["client"]["proxy"], proxy_onion_only=self.conf["client"]["proxy_onion_only"]) + peer.up_out = True data = ubjson.loadb(content) assert data["mix_ok"] == tx.out_seeds[1] except (ConnectionRefusedError, socks.GeneralProxyError, socket.gaierror, socket.timeout): - peer.up = False + peer.up_out = False utils.logprint("Network error: "+peer.to_human_str(), utils.LOG_WARN) continue except (ubjson.decoder.DecoderException, KeyError, AssertionError): @@ -791,13 +799,13 @@ class ClientThread(Thread): try: header, content = utils.sdata(peer.host, "POST", "/confirm/"+base64.urlsafe_b64encode(self.local_peer.hash).decode()+"/"+tx.in_seeds[1].hex(), message, proxy=self.conf["client"]["proxy"], proxy_onion_only=self.conf["client"]["proxy_onion_only"]) data = ubjson.loadb(content) + peer.up_out = True assert data["confirm_ok"] == tx.in_seeds[2] tx.need_confirm = False tx.export_ubjson(self.db_txs) - peer.up = True utils.logprint("Confirmed "+tx.sender_pubkey[:8]+" -> "+tx.receiver_pubkey[:8]+" = "+str(tx.in_amount)+":"+str(tx.in_base)+" -> "+str(tx.out_amount)+":"+str(tx.out_base), utils.LOG_TRACE) except (ConnectionRefusedError, socks.GeneralProxyError, socket.gaierror, socket.timeout): - peer.up = False + peer.up_out = False except (ubjson.decoder.DecoderException, KeyError, AssertionError): utils.logprint("Bad response: "+peer.to_human_str(), utils.LOG_WARN) else: diff --git a/utils.py b/utils.py index 28b7deb0e00601d66fc833fde016e337b89a51cf..d3dd5ff4f1a9bb524e3bd060818b9b989e57a89d 100644 --- a/utils.py +++ b/utils.py @@ -191,7 +191,8 @@ class Peer: self.hash = hashlib.sha512((self.pubkey+"@"+self.host[0]+":"+str(self.host[1])).encode()).digest() self.keys = PublicKey(self.pubkey) - self.up = None + self.up_in = None # can reach local node + self.up_out = None # is reachable by local node def to_human_str(self, short=True): return (self.pubkey[:8] if short else self.pubkey)+"@"+self.host[0]+":"+str(self.host[1])