progress in removing core

master
Kevin Froman 2019-07-24 11:32:23 -05:00
parent a74f2c5051
commit 274505a51f
10 changed files with 28 additions and 30 deletions

View File

@ -34,7 +34,11 @@ class PublicAPI:
self.i2pEnabled = config.get('i2p.host', False) self.i2pEnabled = config.get('i2p.host', False)
self.hideBlocks = [] # Blocks to be denied sharing self.hideBlocks = [] # Blocks to be denied sharing
self.host = apiutils.setbindip.set_bind_IP(filepaths.public_API_host_file) self.host = apiutils.setbindip.set_bind_IP(filepaths.public_API_host_file)
self.torAdder = gettransports.get()[0] transports = []
while len(transports) == 0:
transports = gettransports.get()
time.sleep(0.3)
self.torAdder = transports[0]
self.bindPort = config.get('client.public.port') self.bindPort = config.get('client.public.port')
self.lastRequest = 0 self.lastRequest = 0
self.hitCount = 0 # total rec requests to public api since server started self.hitCount = 0 # total rec requests to public api since server started

View File

@ -39,12 +39,11 @@ class OnionrCommunicatorDaemon:
def __init__(self, onionrInst, proxyPort, developmentMode=config.get('general.dev_mode', False)): def __init__(self, onionrInst, proxyPort, developmentMode=config.get('general.dev_mode', False)):
onionrInst.communicatorInst = self onionrInst.communicatorInst = self
# configure logger and stuff # configure logger and stuff
onionr.Onionr.setupConfig('data/', self = self) onionr.Onionr.setupConfig(onionrInst)
self.onionrInst = onionrInst self.onionrInst = onionrInst
self.config = config self.config = config
self.storage_counter = storagecounter.StorageCounter() self.storage_counter = storagecounter.StorageCounter()
self.proxyPort = proxyPort self.proxyPort = proxyPort
self.hsAddress = gettransports.get()[0]
self.isOnline = True # Assume we're connected to the internet self.isOnline = True # Assume we're connected to the internet
# list of timer instances # list of timer instances

View File

@ -25,6 +25,6 @@ def add_bootstrap_list_to_peer_list(comm_inst, peerList):
Add the bootstrap list to the peer list (no duplicates) Add the bootstrap list to the peer list (no duplicates)
''' '''
for i in bootstrap_peers: for i in bootstrap_peers:
if i not in peerList and i not in comm_inst.offlinePeers and i != gettransports.get()[0] and len(str(i).strip()) > 0: if i not in peerList and i not in comm_inst.offlinePeers and not i in gettransports.get() and len(str(i).strip()) > 0:
peerList.append(i) peerList.append(i)
keydb.addkeys.add_address(i) keydb.addkeys.add_address(i)

View File

@ -19,7 +19,7 @@
''' '''
import time, sys, secrets import time, sys, secrets
import onionrexceptions, logger, onionrpeers import onionrexceptions, logger, onionrpeers
from utils import networkmerger from utils import networkmerger, gettransports
from onionrutils import stringvalidators, epoch from onionrutils import stringvalidators, epoch
from communicator import peeraction, bootstrappeers from communicator import peeraction, bootstrappeers
from coredb import keydb from coredb import keydb
@ -27,6 +27,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
config = comm_inst.config config = comm_inst.config
retData = False retData = False
tried = comm_inst.offlinePeers tried = comm_inst.offlinePeers
transports = gettransports.get()
if peer != '': if peer != '':
if stringvalidators.validate_transport(peer): if stringvalidators.validate_transport(peer):
peerList = [peer] peerList = [peer]

View File

@ -26,6 +26,8 @@ def lookup_new_peer_transports_with_communicator(comm_inst):
logger.info('Looking up new addresses...') logger.info('Looking up new addresses...')
tryAmount = 1 tryAmount = 1
newPeers = [] newPeers = []
if len(transports) == 0:
transports = list(gettransports.get())
for i in range(tryAmount): for i in range(tryAmount):
# Download new peer address list from random online peers # Download new peer address list from random online peers
if len(newPeers) > 10000: if len(newPeers) > 10000:

View File

@ -65,7 +65,7 @@ def add_address(address):
if type(address) is None or len(address) == 0: if type(address) is None or len(address) == 0:
return False return False
if stringvalidators.validate_transport(address): if stringvalidators.validate_transport(address):
if address == gettransports.get()[0]: if address in gettransports.get():
return False return False
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30) conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
c = conn.cursor() c = conn.cursor()

View File

@ -31,6 +31,8 @@ class PublicAPISecurity:
def validate_request(): def validate_request():
'''Validate request has the correct hostname''' '''Validate request has the correct hostname'''
# If high security level, deny requests to public (HS should be disabled anyway for Tor, but might not be for I2P) # If high security level, deny requests to public (HS should be disabled anyway for Tor, but might not be for I2P)
if len(transports) == 0:
transports = list(gettransports.get())
if public_api.config.get('general.security_level', default=1) > 0: if public_api.config.get('general.security_level', default=1) > 0:
abort(403) abort(403)
if request.host not in transports: if request.host not in transports:

View File

@ -76,7 +76,7 @@ class Onionr:
self.dataDir += '/' self.dataDir += '/'
# Load global configuration data # Load global configuration data
data_exists = Onionr.setupConfig(self.dataDir, self) data_exists = Onionr.setupConfig(self)
if netcontroller.tor_binary() is None: if netcontroller.tor_binary() is None:
logger.error('Tor is not installed', terminal=True) logger.error('Tor is not installed', terminal=True)
@ -149,8 +149,8 @@ class Onionr:
def exitSigterm(self, signum, frame): def exitSigterm(self, signum, frame):
self.killed = True self.killed = True
def setupConfig(dataDir, self = None): def setupConfig(self):
return setupconfig.setup_config(dataDir, self) return setupconfig.setup_config(self)
def cmdHeader(self): def cmdHeader(self):
if len(sys.argv) >= 3: if len(sys.argv) >= 3:

View File

@ -21,10 +21,7 @@ import os, json
import config, logger import config, logger
from logger.settings import * from logger.settings import *
def setup_config(dataDir, o_inst = None): def setup_config(o_inst = None):
data_exists = os.path.exists(dataDir)
if not data_exists:
os.mkdir(dataDir)
config.reload() config.reload()
if not os.path.exists(config._configfile): if not os.path.exists(config._configfile):
@ -32,10 +29,6 @@ def setup_config(dataDir, o_inst = None):
# this is the default config, it will be overwritten if a config file already exists. Else, it saves it # this is the default config, it will be overwritten if a config file already exists. Else, it saves it
with open('static-data/default_config.json', 'r') as configReadIn: with open('static-data/default_config.json', 'r') as configReadIn:
config.set_config(json.loads(configReadIn.read())) config.set_config(json.loads(configReadIn.read()))
else:
# the default config file doesn't exist, try hardcoded config
logger.warn('Default configuration file does not exist, switching to hardcoded fallback configuration!')
config.set_config({'dev_mode': True, 'log': {'file': {'output': True, 'path': dataDir + 'output.log'}, 'console': {'output': True, 'color': True}}})
config.save() config.save()
@ -85,5 +78,3 @@ def setup_config(dataDir, o_inst = None):
set_level(map[verbosity]) set_level(map[verbosity])
else: else:
logger.warn('Verbosity level %s is not valid, using default verbosity.' % verbosity) logger.warn('Verbosity level %s is not valid, using default verbosity.' % verbosity)
return data_exists

View File

@ -4,15 +4,14 @@ files = [filepaths.tor_hs_address_file]
def get(): def get():
transports = [] transports = []
while len(transports) == 0: for file in files:
for file in files: try:
try: with open(file, 'r') as transport_file:
with open(file, 'r') as transport_file: transports.append(transport_file.read().strip())
transports.append(transport_file.read().strip()) except FileNotFoundError:
except FileNotFoundError: pass
transports.append('')
else:
break
else: else:
time.sleep(1) break
else:
time.sleep(1)
return list(transports) return list(transports)