test tor version, use address db for connections, create address db if it doesnt exist, more

master
Kevin Froman 2018-02-22 03:33:30 -06:00
parent af24f16538
commit 155791be03
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
5 changed files with 32 additions and 4 deletions

View File

@ -23,4 +23,5 @@ reset:
rm -f onionr/data/blocks/*.dat | true > /dev/null 2>&1 rm -f onionr/data/blocks/*.dat | true > /dev/null 2>&1
rm -f onionr/data/peers.db | true > /dev/null 2>&1 rm -f onionr/data/peers.db | true > /dev/null 2>&1
rm -f onionr/data/blocks.db | true > /dev/null 2>&1 rm -f onionr/data/blocks.db | true > /dev/null 2>&1
rm -rf onionr/data/address.db | true > /dev/null 2>&1

View File

@ -68,7 +68,7 @@ class OnionrCommunicate:
''' '''
Lookup blocks and merge new ones Lookup blocks and merge new ones
''' '''
peerList = self._core.listPeers() peerList = self._core.listAdders()
blocks = '' blocks = ''
for i in peerList: for i in peerList:
lastDB = self._core.getPeerInfo(i, 'blockDBHash') lastDB = self._core.getPeerInfo(i, 'blockDBHash')
@ -123,7 +123,7 @@ class OnionrCommunicate:
''' '''
Download a block from random order of peers Download a block from random order of peers
''' '''
peerList = self._core.listPeers() peerList = self._core.listAdders()
blocks = '' blocks = ''
for i in peerList: for i in peerList:
hasher = hashlib.sha3_256() hasher = hashlib.sha3_256()

View File

@ -300,6 +300,22 @@ class Core:
conn.close() conn.close()
return return
def listAdders(self, randomOrder=True, i2p=True):
'''
Return a list of addresses
'''
conn = sqlite3.connect(self.addressDB)
c = conn.cursor()
if randomOrder:
addresses = c.execute('SELECT * FROM adders ORDER BY RANDOM();')
else:
addresses = c.execute('SELECT * FROM adders;')
addressList = []
for i in addresses:
addressList.append(i[2])
conn.close()
return addressList
def listPeers(self, randomOrder=True): def listPeers(self, randomOrder=True):
''' '''

View File

@ -69,6 +69,15 @@ HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
except FileNotFoundError: except FileNotFoundError:
logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.") logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.")
sys.exit(1) sys.exit(1)
else:
# Test Tor Version
torVersion = subprocess.Popen([torBinary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in iter(torVersion.stdout.readline, b''):
if 'Tor 0.2.' in line.decode():
logger.warn("Running 0.2.x Tor series, no support for v3 onion peers")
break
torVersion.kill()
# wait for tor to get to 100% bootstrap # wait for tor to get to 100% bootstrap
for line in iter(tor.stdout.readline, b''): for line in iter(tor.stdout.readline, b''):
if 'Bootstrapped 100%: Done' in line.decode(): if 'Bootstrapped 100%: Done' in line.decode():

View File

@ -72,9 +72,11 @@ class Onionr:
os.mkdir('data/') os.mkdir('data/')
os.mkdir('data/blocks/') os.mkdir('data/blocks/')
if not os.path.exists('data/peers.db'): if not os.path.exists(self.onionrCore.peerDB):
self.onionrCore.createPeerDB() self.onionrCore.createPeerDB()
pass pass
if not os.path.exists(self.onionrCore.addressDB):
self.onionrCore.createAddressDB()
# Get configuration # Get configuration
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
@ -90,7 +92,7 @@ class Onionr:
randomPort = random.randint(1024, 65535) randomPort = random.randint(1024, 65535)
if self.onionrUtils.checkPort(randomPort): if self.onionrUtils.checkPort(randomPort):
break break
self.config['CLIENT'] = {'CLIENT HMAC': base64.b64encode(os.urandom(32)).decode('utf-8'), 'PORT': randomPort, 'API VERSION': API_VERSION} self.config['CLIENT'] = {'participate': 'true', 'CLIENT HMAC': base64.b64encode(os.urandom(32)).decode('utf-8'), 'PORT': randomPort, 'API VERSION': API_VERSION}
with open('data/config.ini', 'w') as configfile: with open('data/config.ini', 'w') as configfile:
self.config.write(configfile) self.config.write(configfile)