work
authorforrest <forrest@470744a7-cac9-478e-843e-5ec1b25c69e8>
Wed, 15 Jun 2011 22:51:10 +0000 (22:51 +0000)
committerforrest <forrest@470744a7-cac9-478e-843e-5ec1b25c69e8>
Wed, 15 Jun 2011 22:51:10 +0000 (22:51 +0000)
git-svn-id: svn://forre.st/p2pool@1312 470744a7-cac9-478e-843e-5ec1b25c69e8

main.py
p2p.py

diff --git a/main.py b/main.py
index ad65431..94ecf73 100644 (file)
--- a/main.py
+++ b/main.py
@@ -230,6 +230,8 @@ def main(args):
                 print 'Got duplicate share, ignoring. Hash: %x' % (share.hash,)
             elif res == 'orphan':
                 print 'Got share referencing unknown share, requesting past shares from peer. Hash: %x' % (share.hash,)
+                if peer is None:
+                    raise ValueError()
                 peer.getsharesbychain(
                     chain_id=p2pool.chain_id_type.unpack(share.chain_id_data),
                     have=chain.highest.value[1].hash() if chain.highest.value[1] is not None else None
@@ -241,6 +243,17 @@ def main(args):
             w['highest_p2pool_share2'] = w['current_chain'].get_highest_share2()
             current_work.set(w)
         
+        def p2pCallback2(chain_id_data, hash, peer):
+            chain = get_chain(chain_id_data)
+            if chain is current_work.value['current_chain']:
+                if hash not in chain.shares:
+                    if hash not in chain.requesting:
+                        peer.send_getshares(hashes=[hash])
+                        chain.requesting.add(hash)
+                        reactor.callLater(5, chain.requesting.remove, hash)
+            else:
+                chain.
+        
         @defer.inlineCallbacks
         def getBlocksCallback2(chain_id_data, highest, contact):
             chain = get_chain(chain_id_data)
@@ -285,10 +298,11 @@ def main(args):
             port=args.p2pool_port,
             testnet=args.testnet,
             addr_store=gdbm.open(os.path.join(os.path.dirname(__file__), 'peers.dat'), 'cs'),
-            mode=1 if args.low_bandwidth else 0,
+            mode=0 if args.low_bandwidth else 1,
             preferred_addrs=map(parse, args.p2pool_nodes) + nodes,
         )
         p2p_node.handle_share = p2pCallback
+        p2p_node.handle_share_hash = p2pCallback2
         p2p_node.handle_get_blocks = getBlocksCallback
         
         p2p_node.start()
diff --git a/p2p.py b/p2p.py
index 602bb5b..47aeafd 100644 (file)
--- a/p2p.py
+++ b/p2p.py
@@ -218,7 +218,7 @@ class Protocol(bitcoin_p2p.BaseProtocol):
     def handle_share0s(self, chains):
         for chain in chains:
             for hash_ in chain['hashes']:
-                self.node.handle_share_hash(p2pool.chain_id_type.pack(chain['chain_id']), hash_)
+                self.node.handle_share_hash(p2pool.chain_id_type.pack(chain['chain_id']), hash_, self)
     def handle_share1s(self, share1s):
         for share1 in share1s:
             hash_ = bitcoin_p2p.block_hash(share1['header'])
@@ -434,8 +434,8 @@ class Node(object):
             self.addr_store[host, port] = services, timestamp, timestamp
     
     
-    def handle_share_hash(self, chain_id_data, hash):
-        print (chain_id_data, hash)
+    def handle_share_hash(self, chain_id_data, hash, peer):
+        pass
 
 if __name__ == '__main__':
     p = random.randrange(2**15, 2**16)