X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=p2pool%2Fp2p.py;h=6383ef910204a1348fe57131eead1732d3e4fc76;hb=3ca723ee19cb8e2ee54e32a81e0d3caa2ff51441;hp=189fd2c1b0e533d5d416cc9f80506cbb01c681c6;hpb=90574e6a152ffe4277de3c351ad75032d3a0dea7;p=p2pool.git diff --git a/p2pool/p2p.py b/p2pool/p2p.py index 189fd2c..6383ef9 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -25,6 +25,8 @@ def fragment(f, **kwargs): fragment(f, **dict((k, v[len(v)//2:]) for k, v in kwargs.iteritems())) class Protocol(p2protocol.Protocol): + VERSION = 1300 + max_remembered_txs_size = 2500000 def __init__(self, node, incoming): @@ -43,7 +45,7 @@ class Protocol(p2protocol.Protocol): self.addr = self.transport.getPeer().host, self.transport.getPeer().port self.send_version( - version=1300, + version=self.VERSION, services=0, addr_to=dict( services=0, @@ -116,7 +118,7 @@ class Protocol(p2protocol.Protocol): def handle_version(self, version, services, addr_to, addr_from, nonce, sub_version, mode, best_share_hash): if self.other_version is not None: raise PeerMisbehavingError('more than one version message') - if version < 8: + if version < 1300: raise PeerMisbehavingError('peer too old') self.other_version = version @@ -252,11 +254,43 @@ class Protocol(p2protocol.Protocol): ('shares', pack.ListType(p2pool_data.share_type)), ]) def handle_shares(self, shares): - self.node.handle_shares([p2pool_data.load_share(share, self.node.net, self.addr) for share in shares if share['type'] >= 9], self) + result = [] + for wrappedshare in shares: + if wrappedshare['type'] < 9: continue + share = p2pool_data.load_share(wrappedshare, self.node.net, self.addr) + if wrappedshare['type'] >= 13: + txs = [] + for tx_hash in share.share_info['new_transaction_hashes']: + if tx_hash in self.node.known_txs_var.value: + tx = self.node.known_txs_var.value[tx_hash] + else: + for cache in self.known_txs_cache.itervalues(): + if tx_hash in cache: + tx = cache[tx_hash] + print 'Transaction %064x rescued from peer latency cache!' % (tx_hash,) + break + else: + print >>sys.stderr, 'Peer referenced unknown transaction %064x, disconnecting' % (tx_hash,) + self.disconnect() + return + txs.append(tx) + else: + txs = None + + result.append((share, txs)) + + self.node.handle_shares(result, self) def sendShares(self, shares, tracker, known_txs, include_txs_with=[]): tx_hashes = set() for share in shares: + if share.VERSION >= 13: + # send full transaction for every new_transaction_hash that peer does not know + for tx_hash in share.share_info['new_transaction_hashes']: + assert tx_hash in known_txs, 'tried to broadcast share without knowing all its new transactions' + if tx_hash not in self.remote_tx_hashes: + tx_hashes.add(tx_hash) + continue if share.hash in include_txs_with: x = share.get_other_tx_hashes(tracker) if x is not None: @@ -296,11 +330,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] else: - res = failure.Failure("sharereply result: " + result) + res = failure.Failure(self.ShareReplyError(result)) self.get_shares.got_response(id, res)