X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=p2pool%2Fp2p.py;h=707d3462760f9f0cc71858ba4e817ae2e90ca3ba;hb=b671a57c5ef37568532ef28925df728bfe855eec;hp=cd85a2ee97a5c9346c97e8b0f10d1a1b7c44060f;hpb=fc98547deffa225b47f77393d914d0165bcd5a7d;p=p2pool.git diff --git a/p2pool/p2p.py b/p2pool/p2p.py index cd85a2e..707d346 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -152,9 +152,10 @@ class Protocol(p2protocol.Protocol): self.send_ping(), random.expovariate(1/100)][-1]) - self._stop_thread2 = deferral.run_repeatedly(lambda: [ - self.send_addrme(port=self.node.serverfactory.listen_port.getHost().port) if self.node.serverfactory.listen_port is not None else None, - random.expovariate(1/(100*len(self.node.peers) + 1))][-1]) + if self.node.advertise_ip: + self._stop_thread2 = deferral.run_repeatedly(lambda: [ + self.send_addrme(port=self.node.serverfactory.listen_port.getHost().port) if self.node.serverfactory.listen_port is not None else None, + random.expovariate(1/(100*len(self.node.peers) + 1))][-1]) if best_share_hash is not None: self.node.handle_share_hashes([best_share_hash], self) @@ -256,7 +257,7 @@ class Protocol(p2protocol.Protocol): def handle_shares(self, shares): result = [] for wrappedshare in shares: - if wrappedshare['type'] < 9: continue + if wrappedshare['type'] < p2pool_data.Share.VERSION: continue share = p2pool_data.load_share(wrappedshare, self.node.net, self.addr) if wrappedshare['type'] >= 13: txs = [] @@ -330,11 +331,12 @@ class Protocol(p2protocol.Protocol): ('result', pack.EnumType(pack.VarIntType(), {0: 'good', 1: 'too long', 2: 'unk2', 3: 'unk3', 4: 'unk4', 5: 'unk5', 6: 'unk6'})), ('shares', pack.ListType(p2pool_data.share_type)), ]) + class ShareReplyError(Exception): pass def handle_sharereply(self, id, result, shares): if result == 'good': - res = [p2pool_data.load_share(share, self.node.net, self.addr) for share in shares if share['type'] >= 9] + res = [p2pool_data.load_share(share, self.node.net, self.addr) for share in shares if share['type'] >= p2pool_data.Share.VERSION] else: - res = failure.Failure("sharereply result: " + result) + res = failure.Failure(self.ShareReplyError(result)) self.get_shares.got_response(id, res) @@ -423,7 +425,8 @@ class Protocol(p2protocol.Protocol): if self.connected2: self.factory.proto_disconnected(self, reason) self._stop_thread() - self._stop_thread2() + if self.node.advertise_ip: + self._stop_thread2() self.connected2 = False self.factory.proto_lost_connection(self, reason) if p2pool.DEBUG: @@ -580,7 +583,7 @@ class SingleClientFactory(protocol.ReconnectingClientFactory): self.node.lost_conn(proto, reason) class Node(object): - def __init__(self, best_share_hash_func, port, net, addr_store={}, connect_addrs=set(), desired_outgoing_conns=10, max_outgoing_attempts=30, max_incoming_conns=50, preferred_storage=1000, known_txs_var=variable.Variable({}), mining_txs_var=variable.Variable({})): + def __init__(self, best_share_hash_func, port, net, addr_store={}, connect_addrs=set(), desired_outgoing_conns=10, max_outgoing_attempts=30, max_incoming_conns=50, preferred_storage=1000, known_txs_var=variable.Variable({}), mining_txs_var=variable.Variable({}), advertise_ip=True): self.best_share_hash_func = best_share_hash_func self.port = port self.net = net @@ -589,6 +592,7 @@ class Node(object): self.preferred_storage = preferred_storage self.known_txs_var = known_txs_var self.mining_txs_var = mining_txs_var + self.advertise_ip = advertise_ip self.traffic_happened = variable.Event() self.nonce = random.randrange(2**64)