NVC protocol v. 60011 support
[p2pool.git] / p2pool / bitcoin / p2p.py
index cdb98de..6048d81 100644 (file)
@@ -6,7 +6,7 @@ import random
 import sys
 import time
 
-from twisted.internet import protocol, task
+from twisted.internet import protocol
 
 import p2pool
 from . import data as bitcoin_data
@@ -18,7 +18,7 @@ class Protocol(p2protocol.Protocol):
     
     def connectionMade(self):
         self.send_version(
-            version=32200,
+            version=60011,
             services=1,
             time=int(time.time()),
             addr_to=dict(
@@ -59,7 +59,7 @@ class Protocol(p2protocol.Protocol):
         if hasattr(self.factory, 'gotConnection'):
             self.factory.gotConnection(self)
         
-        self.pinger = task.LoopingCall(self.send_ping)
+        self.pinger = deferral.RobustLoopingCall(self.send_ping, nonce=1234)
         self.pinger.start(30)
     
     message_inv = pack.ComposedType([
@@ -115,7 +115,7 @@ class Protocol(p2protocol.Protocol):
         ('block', bitcoin_data.block_type),
     ])
     def handle_block(self, block):
-        block_hash = bitcoin_data.hash256(bitcoin_data.block_header_type.pack(block['header']))
+        block_hash = bitcoin_data.scrypt(bitcoin_data.block_header_type.pack(block['header']))
         self.get_block.got_response(block_hash, block)
         self.get_block_header.got_response(block_hash, block['header'])
     
@@ -125,11 +125,19 @@ class Protocol(p2protocol.Protocol):
     def handle_headers(self, headers):
         for header in headers:
             header = header['header']
-            self.get_block_header.got_response(bitcoin_data.hash256(bitcoin_data.block_header_type.pack(header)), header)
+            self.get_block_header.got_response(bitcoin_data.scrypt(bitcoin_data.block_header_type.pack(header)), header)
         self.factory.new_headers.happened([header['header'] for header in headers])
     
-    message_ping = pack.ComposedType([])
-    def handle_ping(self):
+    message_ping = pack.ComposedType([
+        ('nonce', pack.IntType(64)),
+    ])
+    def handle_ping(self, nonce):
+        self.send_pong(nonce=nonce)
+    
+    message_pong = pack.ComposedType([
+        ('nonce', pack.IntType(64)),
+    ])
+    def handle_pong(self, nonce):
         pass
     
     message_alert = pack.ComposedType([