progress in removing core
This commit is contained in:
parent
a74f2c5051
commit
274505a51f
@ -34,7 +34,11 @@ class PublicAPI:
|
||||
self.i2pEnabled = config.get('i2p.host', False)
|
||||
self.hideBlocks = [] # Blocks to be denied sharing
|
||||
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.lastRequest = 0
|
||||
self.hitCount = 0 # total rec requests to public api since server started
|
||||
|
@ -39,12 +39,11 @@ class OnionrCommunicatorDaemon:
|
||||
def __init__(self, onionrInst, proxyPort, developmentMode=config.get('general.dev_mode', False)):
|
||||
onionrInst.communicatorInst = self
|
||||
# configure logger and stuff
|
||||
onionr.Onionr.setupConfig('data/', self = self)
|
||||
onionr.Onionr.setupConfig(onionrInst)
|
||||
self.onionrInst = onionrInst
|
||||
self.config = config
|
||||
self.storage_counter = storagecounter.StorageCounter()
|
||||
self.proxyPort = proxyPort
|
||||
self.hsAddress = gettransports.get()[0]
|
||||
self.isOnline = True # Assume we're connected to the internet
|
||||
|
||||
# list of timer instances
|
||||
|
@ -25,6 +25,6 @@ def add_bootstrap_list_to_peer_list(comm_inst, peerList):
|
||||
Add the bootstrap list to the peer list (no duplicates)
|
||||
'''
|
||||
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)
|
||||
keydb.addkeys.add_address(i)
|
@ -19,7 +19,7 @@
|
||||
'''
|
||||
import time, sys, secrets
|
||||
import onionrexceptions, logger, onionrpeers
|
||||
from utils import networkmerger
|
||||
from utils import networkmerger, gettransports
|
||||
from onionrutils import stringvalidators, epoch
|
||||
from communicator import peeraction, bootstrappeers
|
||||
from coredb import keydb
|
||||
@ -27,6 +27,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
||||
config = comm_inst.config
|
||||
retData = False
|
||||
tried = comm_inst.offlinePeers
|
||||
transports = gettransports.get()
|
||||
if peer != '':
|
||||
if stringvalidators.validate_transport(peer):
|
||||
peerList = [peer]
|
||||
|
@ -26,6 +26,8 @@ def lookup_new_peer_transports_with_communicator(comm_inst):
|
||||
logger.info('Looking up new addresses...')
|
||||
tryAmount = 1
|
||||
newPeers = []
|
||||
if len(transports) == 0:
|
||||
transports = list(gettransports.get())
|
||||
for i in range(tryAmount):
|
||||
# Download new peer address list from random online peers
|
||||
if len(newPeers) > 10000:
|
||||
|
@ -65,7 +65,7 @@ def add_address(address):
|
||||
if type(address) is None or len(address) == 0:
|
||||
return False
|
||||
if stringvalidators.validate_transport(address):
|
||||
if address == gettransports.get()[0]:
|
||||
if address in gettransports.get():
|
||||
return False
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
@ -31,6 +31,8 @@ class PublicAPISecurity:
|
||||
def validate_request():
|
||||
'''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 len(transports) == 0:
|
||||
transports = list(gettransports.get())
|
||||
if public_api.config.get('general.security_level', default=1) > 0:
|
||||
abort(403)
|
||||
if request.host not in transports:
|
||||
|
@ -76,7 +76,7 @@ class Onionr:
|
||||
self.dataDir += '/'
|
||||
|
||||
# Load global configuration data
|
||||
data_exists = Onionr.setupConfig(self.dataDir, self)
|
||||
data_exists = Onionr.setupConfig(self)
|
||||
|
||||
if netcontroller.tor_binary() is None:
|
||||
logger.error('Tor is not installed', terminal=True)
|
||||
@ -149,8 +149,8 @@ class Onionr:
|
||||
def exitSigterm(self, signum, frame):
|
||||
self.killed = True
|
||||
|
||||
def setupConfig(dataDir, self = None):
|
||||
return setupconfig.setup_config(dataDir, self)
|
||||
def setupConfig(self):
|
||||
return setupconfig.setup_config(self)
|
||||
|
||||
def cmdHeader(self):
|
||||
if len(sys.argv) >= 3:
|
||||
|
@ -21,10 +21,7 @@ import os, json
|
||||
import config, logger
|
||||
from logger.settings import *
|
||||
|
||||
def setup_config(dataDir, o_inst = None):
|
||||
data_exists = os.path.exists(dataDir)
|
||||
if not data_exists:
|
||||
os.mkdir(dataDir)
|
||||
def setup_config(o_inst = None):
|
||||
config.reload()
|
||||
|
||||
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
|
||||
with open('static-data/default_config.json', 'r') as configReadIn:
|
||||
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()
|
||||
|
||||
@ -85,5 +78,3 @@ def setup_config(dataDir, o_inst = None):
|
||||
set_level(map[verbosity])
|
||||
else:
|
||||
logger.warn('Verbosity level %s is not valid, using default verbosity.' % verbosity)
|
||||
|
||||
return data_exists
|
@ -4,13 +4,12 @@ files = [filepaths.tor_hs_address_file]
|
||||
|
||||
def get():
|
||||
transports = []
|
||||
while len(transports) == 0:
|
||||
for file in files:
|
||||
try:
|
||||
with open(file, 'r') as transport_file:
|
||||
transports.append(transport_file.read().strip())
|
||||
except FileNotFoundError:
|
||||
transports.append('')
|
||||
pass
|
||||
else:
|
||||
break
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user