Permalink
Browse files

make p2p connection to bitcoin first when on testnet so connections a…

…ren't required
  • Loading branch information...
1 parent 1403fdd commit bb83efb3e834e9344de92a6cec26f824e763324a @forrestv forrestv committed with forrestv Sep 21, 2012
Showing with 17 additions and 8 deletions.
  1. +17 −8 p2pool/main.py
View
@@ -67,6 +67,20 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
traffic_happened = variable.Event()
+ @defer.inlineCallbacks
+ def connect_p2p():
+ # connect to bitcoind over bitcoin-p2p
+ print '''Testing bitcoind P2P connection to '%s:%s'...''' % (args.bitcoind_address, args.bitcoind_p2p_port)
+ factory = bitcoin_p2p.ClientFactory(net.PARENT)
+ reactor.connectTCP(args.bitcoind_address, args.bitcoind_p2p_port, factory)
+ yield factory.getProtocol() # waits until handshake is successful
+ print ' ...success!'
+ print
+ defer.returnValue(factory)
+
+ if args.testnet: # establish p2p connection first if testnet so bitcoind can work without connections
+ factory = yield connect_p2p()
+
# connect to bitcoind over JSON-RPC and do initial getmemorypool
url = '%s://%s:%i/' % ('https' if args.bitcoind_rpc_ssl else 'http', args.bitcoind_address, args.bitcoind_rpc_port)
print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
@@ -83,6 +97,9 @@ def check():
yield check()
temp_work = yield getwork(bitcoind)
+ if not args.testnet:
+ factory = yield connect_p2p()
+
block_height_var = variable.Variable(None)
@defer.inlineCallbacks
def poll_height():
@@ -103,14 +120,6 @@ def poll_warnings():
print ' Current block height: %i' % (block_height_var.value,)
print
- # connect to bitcoind over bitcoin-p2p
- print '''Testing bitcoind P2P connection to '%s:%s'...''' % (args.bitcoind_address, args.bitcoind_p2p_port)
- factory = bitcoin_p2p.ClientFactory(net.PARENT)
- reactor.connectTCP(args.bitcoind_address, args.bitcoind_p2p_port, factory)
- yield factory.getProtocol() # waits until handshake is successful
- print ' ...success!'
- print
-
print 'Determining payout address...'
if args.pubkey_hash is None:
address_path = os.path.join(datadir_path, 'cached_payout_address')

0 comments on commit bb83efb

Please sign in to comment.