reduced config reloads by a lot

This commit is contained in:
Kevin Froman 2019-06-16 01:06:32 -05:00
parent 7cb5f212ec
commit c07901ec06
14 changed files with 33 additions and 26 deletions

View File

@ -35,7 +35,6 @@ OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers
config.reload()
class OnionrCommunicatorDaemon:
def __init__(self, onionrInst, proxyPort, developmentMode=config.get('general.dev_mode', False)):
config.reload()
onionrInst.communicatorInst = self
# configure logger and stuff
onionr.Onionr.setupConfig('data/', self = self)

View File

@ -115,7 +115,6 @@ def reload():
'''
Reloads the configuration data in memory from the file
'''
check()
try:
with open(get_config_file(), 'r', encoding="utf8") as configfile:

View File

@ -21,7 +21,7 @@ import subprocess, os, sys, time, signal, base64, socket
from shutil import which
import logger, config
from onionrblockapi import Block
config.reload()
def getOpenPort():
# taken from (but modified) https://stackoverflow.com/a/2838309 by https://stackoverflow.com/users/133374/albert ccy-by-sa-3 https://creativecommons.org/licenses/by-sa/3.0/
# changes from source: import moved to top of file, bind specifically to localhost
@ -65,10 +65,6 @@ class NetController:
else:
self.torBinary = 'tor'
config.reload()
return
def generateTorrc(self):
'''
Generate a torrc file for our tor instance

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Anonymous Storage Network
Onionr - Private P2P Communication
This file handles maintenence of a blacklist database, for blocks and peers
'''

View File

@ -22,10 +22,10 @@ import nacl.signing, nacl.encoding, nacl.public, nacl.hash, nacl.pwhash, nacl.ut
import logger, onionrproofs
import onionrexceptions, keymanager, core
import config
config.reload()
class OnionrCrypto:
def __init__(self, coreInstance):
config.reload()
self._core = coreInstance
self._keyFile = self._core.dataDir + 'keys.txt'
self.pubKey = None

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Microblogging Platform & Social network
Onionr - Private P2P Communication
This file deals with configuration management.
'''

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Anonymous Storage Network
Onionr - Private P2P Communication
This file contains both the PeerProfiles class for network profiling of Onionr nodes
'''
@ -19,6 +19,7 @@
'''
import sqlite3
import core, config, logger
config.reload()
class PeerProfiles:
'''
PeerProfiles
@ -91,7 +92,6 @@ def peerCleanup(coreInst):
raise TypeError('coreInst must be instance of core.Core')
logger.info('Cleaning peers...')
config.reload()
adders = getScoreSortedPeerList(coreInst)
adders.reverse()

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Microblogging Platform & Social network
Onionr - Private P2P Communication
This file deals with the object that is passed with each event
'''

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Microblogging Platform & Social network
Onionr - Private P2P Communication
This file deals with management of modules/plugins.
'''
@ -27,6 +27,7 @@ if not dataDir.endswith('/'):
_pluginsfolder = dataDir + 'plugins/'
_instances = dict()
config.reload()
def reload(onionr = None, stop_event = True):
'''
@ -211,8 +212,6 @@ def get_enabled_plugins():
check()
config.reload()
return list(config.get('plugins.enabled', list()))
def is_enabled(name):
@ -253,8 +252,6 @@ def check():
Checks to make sure files exist
'''
config.reload()
if not config.is_set('plugins'):
logger.debug('Generating plugin configuration data...')
config.set('plugins', {'enabled': []}, True)

View File

@ -20,6 +20,8 @@
import multiprocessing, nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, sys, json
import core, onionrutils, config, logger, onionrblockapi
config.reload()
def getDifficultyModifier(coreOrUtilsInst=None):
'''Accepts a core or utils instance returns
the difficulty modifier for block storage based
@ -82,7 +84,6 @@ def hashMeetsDifficulty(h):
'''
Return bool for a hash string to see if it meets pow difficulty defined in config
'''
config.reload()
hashDifficulty = getHashDifficulty(h)
try:
expected = int(config.get('general.minimum_block_pow'))
@ -100,7 +101,6 @@ class DataPOW:
self.data = data
self.threadCount = threadCount
self.rounds = 0
config.reload()
if forceDifficulty == 0:
dataLen = sys.getsizeof(data)

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Anonymous Storage Network
Onionr - Private P2P Communication
This file handles block storage, providing an abstraction for storing blocks between file system and database
'''

View File

@ -34,7 +34,7 @@ if sys.version_info < (3, 6):
except ModuleNotFoundError:
logger.fatal('On Python 3 versions prior to 3.6.x, you need the sha3 module')
sys.exit(1)
config.reload()
class OnionrUtils:
'''
Various useful functions for validating things, etc functions, connectivity
@ -47,7 +47,6 @@ class OnionrUtils:
self.avoidDupe = [] # list used to prevent duplicate requests per peer for certain actions
self.peerProcessing = {} # dict of current peer actions: peer, actionList
self.storageCounter = storagecounter.StorageCounter(self._core) # used to keep track of how much data onionr is using on disk
config.reload() # onionr config
return
def getTimeBypassToken(self):
@ -85,7 +84,6 @@ class OnionrUtils:
'''
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.
'''
config.reload()
self.getTimeBypassToken()
# TODO: URL encode parameters, just as an extra measure. May not be needed, but should be added regardless.
hostname = ''

View File

@ -1,3 +1,22 @@
'''
Onionr - Private P2P Communication
Initialize Onionr configuration
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import os, json
import config, logger
@ -6,7 +25,6 @@ def setup_config(dataDir, o_inst = None):
if not data_exists:
os.mkdir(dataDir)
config.reload()
if not os.path.exists(config._configfile):
if os.path.exists('static-data/default_config.json'):

View File

@ -1,5 +1,5 @@
'''
Onionr - P2P Microblogging Platform & Social network.
Onionr - Private P2P Communication
Keeps track of how much disk space we're using
'''