bug fixes
This commit is contained in:
parent
d0593ef300
commit
fc5d702706
@ -33,14 +33,14 @@ class OnionrCommunicate:
|
|||||||
self._utils = onionrutils.OnionrUtils(self._core)
|
self._utils = onionrutils.OnionrUtils(self._core)
|
||||||
self._crypto = onionrcrypto.OnionrCrypto(self._core)
|
self._crypto = onionrcrypto.OnionrCrypto(self._core)
|
||||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]))
|
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]))
|
||||||
while True:
|
#while True:
|
||||||
try:
|
#try:
|
||||||
self.bitcoin = btc.OnionrBTC(torP=int(sys.argv[2]))
|
self.bitcoin = btc.OnionrBTC(torP=int(sys.argv[2]))
|
||||||
except:
|
#except:
|
||||||
# ugly but needed
|
# ugly but needed
|
||||||
pass
|
# pass
|
||||||
else:
|
#else:
|
||||||
break
|
# break
|
||||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()))
|
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()))
|
||||||
blockProcessTimer = 0
|
blockProcessTimer = 0
|
||||||
blockProcessAmount = 5
|
blockProcessAmount = 5
|
||||||
@ -81,11 +81,11 @@ class OnionrCommunicate:
|
|||||||
peerList = self._core.listAdders()
|
peerList = self._core.listAdders()
|
||||||
blocks = ''
|
blocks = ''
|
||||||
for i in peerList:
|
for i in peerList:
|
||||||
lastDB = self._core.getPeerInfo(i, 'blockDBHash')
|
lastDB = self._core.getAddressInfo(i, 'DBHash')
|
||||||
if lastDB == None:
|
if lastDB == None:
|
||||||
logger.debug('Fetching hash from ' + i + ' No previous known.')
|
logger.debug('Fetching hash from ' + i + ' No previous known.')
|
||||||
else:
|
else:
|
||||||
logger.debug('Fetching hash from ' + i + ', ' + lastDB + ' last known')
|
logger.debug('Fetching hash from ' + str(i) + ', ' + lastDB + ' last known')
|
||||||
currentDB = self.performGet('getDBHash', i)
|
currentDB = self.performGet('getDBHash', i)
|
||||||
if currentDB != False:
|
if currentDB != False:
|
||||||
logger.debug(i + " hash db (from request): " + currentDB)
|
logger.debug(i + " hash db (from request): " + currentDB)
|
||||||
@ -96,7 +96,7 @@ class OnionrCommunicate:
|
|||||||
logger.debug('Fetching hash from ' + i + ' - ' + currentDB + ' current hash.')
|
logger.debug('Fetching hash from ' + i + ' - ' + currentDB + ' current hash.')
|
||||||
blocks += self.performGet('getBlockHashes', i)
|
blocks += self.performGet('getBlockHashes', i)
|
||||||
if self._utils.validateHash(currentDB):
|
if self._utils.validateHash(currentDB):
|
||||||
self._core.setPeerInfo(i, "blockDBHash", currentDB)
|
self._core.setAddressInfo(i, "DBHash", currentDB)
|
||||||
if len(blocks.strip()) != 0:
|
if len(blocks.strip()) != 0:
|
||||||
logger.debug('BLOCKS:' + blocks)
|
logger.debug('BLOCKS:' + blocks)
|
||||||
blockList = blocks.split('\n')
|
blockList = blocks.split('\n')
|
||||||
@ -162,7 +162,7 @@ class OnionrCommunicate:
|
|||||||
'''
|
'''
|
||||||
return urllib.parse.quote_plus(data)
|
return urllib.parse.quote_plus(data)
|
||||||
|
|
||||||
def performGet(self, action, peer, data=None, type='tor'):
|
def performGet(self, action, peer, data=None, peerType='tor'):
|
||||||
'''
|
'''
|
||||||
Performs a request to a peer through Tor or i2p (currently only Tor)
|
Performs a request to a peer through Tor or i2p (currently only Tor)
|
||||||
'''
|
'''
|
||||||
@ -172,10 +172,10 @@ class OnionrCommunicate:
|
|||||||
# Store peer in peerData dictionary (non permanent)
|
# Store peer in peerData dictionary (non permanent)
|
||||||
if not peer in self.peerData:
|
if not peer in self.peerData:
|
||||||
self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())}
|
self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())}
|
||||||
|
|
||||||
socksPort = sys.argv[2]
|
socksPort = sys.argv[2]
|
||||||
|
logger.debug('Contacting ' + peer + ' on port ' + socksPort)
|
||||||
'''We use socks5h to use tor as DNS'''
|
'''We use socks5h to use tor as DNS'''
|
||||||
proxies = {'http': 'socks5h://127.0.0.1:' + str(socksPort), 'https': 'socks5h://127.0.0.1:' + str(socksPort)}
|
proxies = {'http': 'socks5://127.0.0.1:' + str(socksPort), 'https': 'socks5://127.0.0.1:' + str(socksPort)}
|
||||||
headers = {'user-agent': 'PyOnionr'}
|
headers = {'user-agent': 'PyOnionr'}
|
||||||
url = 'http://' + peer + '/public/?action=' + self.urlencode(action)
|
url = 'http://' + peer + '/public/?action=' + self.urlencode(action)
|
||||||
if data != None:
|
if data != None:
|
||||||
|
@ -84,7 +84,7 @@ class Core:
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def removeAddress(self, address):
|
def removeAddress(self, address):
|
||||||
'''Remove an address from the address database'''
|
'''Remove an address from the address database'''
|
||||||
if self._utils.validateID(address):
|
if self._utils.validateID(address):
|
||||||
@ -115,6 +115,7 @@ class Core:
|
|||||||
knownPeer text,
|
knownPeer text,
|
||||||
speed int,
|
speed int,
|
||||||
success int,
|
success int,
|
||||||
|
DBHash text,
|
||||||
failure int
|
failure int
|
||||||
);
|
);
|
||||||
''')
|
''')
|
||||||
@ -339,7 +340,7 @@ class Core:
|
|||||||
addresses = c.execute('SELECT * FROM adders;')
|
addresses = c.execute('SELECT * FROM adders;')
|
||||||
addressList = []
|
addressList = []
|
||||||
for i in addresses:
|
for i in addresses:
|
||||||
addressList.append(i[2])
|
addressList.append(i[0])
|
||||||
conn.close()
|
conn.close()
|
||||||
return addressList
|
return addressList
|
||||||
|
|
||||||
@ -369,16 +370,15 @@ class Core:
|
|||||||
id text 0
|
id text 0
|
||||||
name text, 1
|
name text, 1
|
||||||
adders text, 2
|
adders text, 2
|
||||||
blockDBHash text, 3
|
forwardKey text, 3
|
||||||
forwardKey text, 4
|
dateSeen not null, 4
|
||||||
dateSeen not null, 5
|
bytesStored int, 5
|
||||||
bytesStored int, 6
|
trust int 6
|
||||||
trust int 7
|
|
||||||
'''
|
'''
|
||||||
conn = sqlite3.connect(self.peerDB)
|
conn = sqlite3.connect(self.peerDB)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
command = (peer,)
|
command = (peer,)
|
||||||
infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'blockDBHash': 3, 'forwardKey': 4, 'dateSeen': 5, 'bytesStored': 6, 'trust': 7}
|
infoNumbers = {'id': 0, 'name': 1, 'adders': 2, 'forwardKey': 3, 'dateSeen': 4, 'bytesStored': 5, 'trust': 6}
|
||||||
info = infoNumbers[info]
|
info = infoNumbers[info]
|
||||||
iterCount = 0
|
iterCount = 0
|
||||||
retVal = ''
|
retVal = ''
|
||||||
@ -406,7 +406,50 @@ class Core:
|
|||||||
c.execute('UPDATE peers SET ' + key + ' = ? WHERE id=?', command)
|
c.execute('UPDATE peers SET ' + key + ' = ? WHERE id=?', command)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
def getAddressInfo(self, address, info):
|
||||||
|
'''
|
||||||
|
Get info about an address from its database entry
|
||||||
|
|
||||||
|
address text, 0
|
||||||
|
type int, 1
|
||||||
|
knownPeer text, 2
|
||||||
|
speed int, 3
|
||||||
|
success int, 4
|
||||||
|
DBHash text, 5
|
||||||
|
failure int 6
|
||||||
|
'''
|
||||||
|
conn = sqlite3.connect(self.addressDB)
|
||||||
|
c = conn.cursor()
|
||||||
|
command = (address,)
|
||||||
|
infoNumbers = {'address': 0, 'type': 1, 'knownPeer': 2, 'speed': 3, 'success': 4, 'DBHash': 5, 'failure': 6}
|
||||||
|
info = infoNumbers[info]
|
||||||
|
iterCount = 0
|
||||||
|
retVal = ''
|
||||||
|
for row in c.execute('SELECT * from adders where address=?;', command):
|
||||||
|
for i in row:
|
||||||
|
if iterCount == info:
|
||||||
|
retVal = i
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
iterCount += 1
|
||||||
|
conn.close()
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setAddressInfo(self, address, key, data):
|
||||||
|
'''
|
||||||
|
Update an address for a key
|
||||||
|
'''
|
||||||
|
conn = sqlite3.connect(self.addressDB)
|
||||||
|
c = conn.cursor()
|
||||||
|
command = (data, address)
|
||||||
|
# TODO: validate key on whitelist
|
||||||
|
if key not in ('address', 'type', 'knownPeer', 'speed', 'success', 'DBHash', 'failure'):
|
||||||
|
raise Exception("Got invalid database key when setting address info")
|
||||||
|
c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def getBlockList(self, unsaved=False):
|
def getBlockList(self, unsaved=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user