test tor version, use address db for connections, create address db if it doesnt exist, more
This commit is contained in:
parent
af24f16538
commit
155791be03
1
Makefile
1
Makefile
@ -23,4 +23,5 @@ reset:
|
||||
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/blocks.db | true > /dev/null 2>&1
|
||||
rm -rf onionr/data/address.db | true > /dev/null 2>&1
|
||||
|
||||
|
@ -68,7 +68,7 @@ class OnionrCommunicate:
|
||||
'''
|
||||
Lookup blocks and merge new ones
|
||||
'''
|
||||
peerList = self._core.listPeers()
|
||||
peerList = self._core.listAdders()
|
||||
blocks = ''
|
||||
for i in peerList:
|
||||
lastDB = self._core.getPeerInfo(i, 'blockDBHash')
|
||||
@ -123,7 +123,7 @@ class OnionrCommunicate:
|
||||
'''
|
||||
Download a block from random order of peers
|
||||
'''
|
||||
peerList = self._core.listPeers()
|
||||
peerList = self._core.listAdders()
|
||||
blocks = ''
|
||||
for i in peerList:
|
||||
hasher = hashlib.sha3_256()
|
||||
|
@ -300,6 +300,22 @@ class Core:
|
||||
conn.close()
|
||||
|
||||
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):
|
||||
'''
|
||||
|
@ -69,6 +69,15 @@ HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
|
||||
except FileNotFoundError:
|
||||
logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.")
|
||||
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
|
||||
for line in iter(tor.stdout.readline, b''):
|
||||
if 'Bootstrapped 100%: Done' in line.decode():
|
||||
|
@ -72,9 +72,11 @@ class Onionr:
|
||||
os.mkdir('data/')
|
||||
os.mkdir('data/blocks/')
|
||||
|
||||
if not os.path.exists('data/peers.db'):
|
||||
if not os.path.exists(self.onionrCore.peerDB):
|
||||
self.onionrCore.createPeerDB()
|
||||
pass
|
||||
if not os.path.exists(self.onionrCore.addressDB):
|
||||
self.onionrCore.createAddressDB()
|
||||
|
||||
# Get configuration
|
||||
self.config = configparser.ConfigParser()
|
||||
@ -90,7 +92,7 @@ class Onionr:
|
||||
randomPort = random.randint(1024, 65535)
|
||||
if self.onionrUtils.checkPort(randomPort):
|
||||
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:
|
||||
self.config.write(configfile)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user