communicator now starts tor node
This commit is contained in:
parent
cf3af5b8c6
commit
3033de1d9e
@ -20,7 +20,7 @@ and code to operate as a daemon, getting commands from the command queue databas
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sqlite3, requests, hmac, hashlib, time, sys, os, math, logger, urllib.parse
|
||||
import core, onionrutils, onionrcrypto
|
||||
import core, onionrutils, onionrcrypto, pow, btc
|
||||
|
||||
class OnionrCommunicate:
|
||||
def __init__(self, debug, developmentMode):
|
||||
@ -32,10 +32,20 @@ class OnionrCommunicate:
|
||||
self._core = core.Core()
|
||||
self._utils = onionrutils.OnionrUtils(self._core)
|
||||
self._crypto = onionrcrypto.OnionrCrypto(self._core)
|
||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]))
|
||||
while True:
|
||||
try:
|
||||
self.bitcoin = btc.OnionrBTC(torP=int(sys.argv[2]))
|
||||
except:
|
||||
# ugly but needed
|
||||
pass
|
||||
else:
|
||||
break
|
||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()))
|
||||
blockProcessTimer = 0
|
||||
blockProcessAmount = 5
|
||||
heartBeatTimer = 0
|
||||
heartBeatRate = 100
|
||||
heartBeatRate = 5
|
||||
logger.debug('Communicator debugging enabled.')
|
||||
torID = open('data/hs/hostname').read()
|
||||
|
||||
|
@ -20,19 +20,24 @@
|
||||
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger
|
||||
import btc
|
||||
class POW:
|
||||
def pow(self):
|
||||
def pow(self, reporting=False):
|
||||
startTime = math.floor(time.time())
|
||||
self.hashing = True
|
||||
self.reporting = reporting
|
||||
iFound = False # if current thread is the one that found the answer
|
||||
answer = ''
|
||||
heartbeat = 200000
|
||||
hbCount = 0
|
||||
while self.hashing:
|
||||
blockCheck = 300000 # How often the hasher should check if the bitcoin block is updated (slows hashing but prevents less wasted work)
|
||||
blockCheckCount = 0
|
||||
block = self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
|
||||
if hbCount == heartbeat:
|
||||
logger.debug('hb')
|
||||
logger.debug('using bitcoin block: ' + block)
|
||||
hbCount = 0
|
||||
while self.hashing:
|
||||
if blockCheckCount == blockCheck:
|
||||
if self.reporting:
|
||||
logger.debug('Refreshing Bitcoin block')
|
||||
block = self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
|
||||
blockCheckCount = 0
|
||||
blockCheckCount += 1
|
||||
hbCount += 1
|
||||
token = nacl.hash.blake2b(nacl.utils.random() + block.encode()).decode()
|
||||
if self.mainHash[0:self.difficulty] == token[0:self.difficulty]:
|
||||
@ -40,8 +45,9 @@ class POW:
|
||||
iFound = True
|
||||
break
|
||||
if iFound:
|
||||
logger.info('Found token ' + token)
|
||||
endTime = math.floor(time.time())
|
||||
if self.reporting:
|
||||
logger.info('Found token ' + token)
|
||||
logger.info('took ' + str(endTime - startTime))
|
||||
self.result = token
|
||||
|
||||
@ -55,7 +61,7 @@ class POW:
|
||||
self.puzzle = self.mainHash[0:self.difficulty]
|
||||
self.bitcoinNode = bitcoinNode
|
||||
logger.debug('trying to find ' + str(self.mainHash))
|
||||
tOne = threading.Thread(name='one', target=self.pow)
|
||||
tOne = threading.Thread(name='one', target=self.pow, args=(True,))
|
||||
tTwo = threading.Thread(name='two', target=self.pow)
|
||||
tThree = threading.Thread(name='three', target=self.pow)
|
||||
tOne.start()
|
||||
|
Loading…
Reference in New Issue
Block a user