From: Forrest Voight Date: Mon, 20 Feb 2012 00:21:47 +0000 (-0500) Subject: removed support for optional checksums from p2p protocol and transition logic X-Git-Tag: 0.9.1~23 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=38a461338e2ba55c7cdf28e360209d7771b03086;p=p2pool.git removed support for optional checksums from p2p protocol and transition logic --- diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index 9592ef3..62efb93 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -31,22 +31,15 @@ class BaseProtocol(protocol.Protocol): command = (yield 12).rstrip('\0') length, = struct.unpack(' self.max_payload_length: print 'length too large' continue - - if self.use_checksum: - checksum = yield 4 - else: - checksum = None - + checksum = yield 4 payload = yield length - if checksum is not None: - if hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] != checksum: - print 'invalid hash for', self.transport.getPeer().host, repr(command), length, checksum.encode('hex'), hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4].encode('hex'), payload.encode('hex') - continue + if hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] != checksum: + print 'invalid hash for', self.transport.getPeer().host, repr(command), length, checksum.encode('hex'), hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4].encode('hex'), payload.encode('hex') + continue type_ = getattr(self, 'message_' + command, None) if type_ is None: @@ -57,7 +50,7 @@ class BaseProtocol(protocol.Protocol): try: payload2 = type_.unpack(payload) except: - print 'RECV', command, checksum.encode('hex') if checksum is not None else None, repr(payload.encode('hex')), len(payload) + print 'RECV', command, repr(payload.encode('hex')), len(payload) log.err(None, 'Error parsing message: (see RECV line)') continue @@ -86,12 +79,7 @@ class BaseProtocol(protocol.Protocol): payload = type_.pack(payload2) if len(payload) > self.max_payload_length: raise TooLong('payload too long') - if self.use_checksum: - checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] - else: - checksum = '' - data = self._prefix + struct.pack('<12sI', command, len(payload)) + checksum + payload - self.transport.write(data) + self.transport.write(self._prefix + struct.pack('<12sI', command, len(payload)) + hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] + payload) def __getattr__(self, attr): prefix = 'send_' @@ -105,14 +93,8 @@ class Protocol(BaseProtocol): def __init__(self, net): self._prefix = net.P2P_PREFIX - version = 0 - max_payload_length = 1000000 - @property - def use_checksum(self): - return self.version >= 209 or time.time() > 1329696000 - def connectionMade(self): BaseProtocol.connectionMade(self) @@ -146,17 +128,10 @@ class Protocol(BaseProtocol): ('start_height', pack.IntType(32)), ]) def handle_version(self, version, services, time, addr_to, addr_from, nonce, sub_version_num, start_height): - #print 'VERSION', locals() - self.version_after = version self.send_verack() message_verack = pack.ComposedType([]) def handle_verack(self): - self.version = self.version_after - - self.ready() - - def ready(self): self.get_block = deferral.ReplyMatcher(lambda hash: self.send_getdata(requests=[dict(type='block', hash=hash)])) self.get_block_header = deferral.ReplyMatcher(lambda hash: self.send_getheaders(version=1, have=[], last=hash)) self.get_tx = deferral.ReplyMatcher(lambda hash: self.send_getdata(requests=[dict(type='tx', hash=hash)])) diff --git a/p2pool/p2p.py b/p2pool/p2p.py index cf90a78..2089d55 100644 --- a/p2pool/p2p.py +++ b/p2pool/p2p.py @@ -24,7 +24,6 @@ class Protocol(bitcoin_p2p.BaseProtocol): self._prefix = self.node.net.PREFIX max_payload_length = 1000000 - use_checksum = True other_version = None connected2 = False