Merge branch 'master' of gitlab.com:beardog/Onionr
This commit is contained in:
commit
3c1fd87fd4
@ -4,6 +4,36 @@
|
|||||||
This file contains both the OnionrCommunicate class for communcating with peers
|
This file contains both the OnionrCommunicate class for communcating with peers
|
||||||
and code to operate as a daemon, getting commands from the command queue database (see core.Core.daemonQueue)
|
and code to operate as a daemon, getting commands from the command queue database (see core.Core.daemonQueue)
|
||||||
'''
|
'''
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
import config
|
||||||
|
import logger
|
||||||
|
import onionrpeers
|
||||||
|
import onionrplugins as plugins
|
||||||
|
from . import onlinepeers, uploadqueue
|
||||||
|
from communicatorutils import servicecreator
|
||||||
|
from communicatorutils import onionrcommunicatortimers
|
||||||
|
from communicatorutils import downloadblocks
|
||||||
|
from communicatorutils import lookupblocks
|
||||||
|
from communicatorutils import lookupadders
|
||||||
|
from communicatorutils import connectnewpeers
|
||||||
|
from communicatorutils import uploadblocks
|
||||||
|
from communicatorutils import daemonqueuehandler
|
||||||
|
from communicatorutils import announcenode, deniableinserts
|
||||||
|
from communicatorutils import cooldownpeer
|
||||||
|
from communicatorutils import housekeeping
|
||||||
|
from communicatorutils import netcheck
|
||||||
|
from onionrutils import localcommand
|
||||||
|
from onionrutils import epoch
|
||||||
|
from etc import humanreadabletime
|
||||||
|
import onionrservices
|
||||||
|
import filepaths
|
||||||
|
from onionrblocks import storagecounter
|
||||||
|
from coredb import daemonqueue
|
||||||
|
from coredb import dbfiles
|
||||||
|
from netcontroller import NetController
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -18,32 +48,15 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import sys, os, time
|
|
||||||
|
|
||||||
import config, logger
|
|
||||||
import onionrexceptions, onionrpeers
|
|
||||||
from onionrblocks import onionrblockapi as block
|
|
||||||
from onionrplugins import onionrevents as events
|
|
||||||
import onionrplugins as plugins
|
|
||||||
from . import onlinepeers, uploadqueue
|
|
||||||
from communicatorutils import servicecreator, onionrcommunicatortimers
|
|
||||||
from communicatorutils import downloadblocks, lookupblocks, lookupadders
|
|
||||||
from communicatorutils import servicecreator, connectnewpeers
|
|
||||||
from communicatorutils import uploadblocks
|
|
||||||
from communicatorutils import daemonqueuehandler, announcenode, deniableinserts
|
|
||||||
from communicatorutils import cooldownpeer, housekeeping, netcheck
|
|
||||||
from onionrutils import localcommand, epoch
|
|
||||||
from etc import humanreadabletime
|
|
||||||
import onionrservices, filepaths
|
|
||||||
from onionrblocks import storagecounter
|
|
||||||
from coredb import daemonqueue, dbfiles
|
|
||||||
from utils import gettransports
|
|
||||||
from netcontroller import NetController
|
|
||||||
OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers
|
OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers
|
||||||
|
|
||||||
config.reload()
|
config.reload()
|
||||||
class OnionrCommunicatorDaemon:
|
class OnionrCommunicatorDaemon:
|
||||||
def __init__(self, shared_state, developmentMode=config.get('general.dev_mode', False)):
|
def __init__(self, shared_state, developmentMode=None):
|
||||||
|
if developmentMode is None:
|
||||||
|
developmentMode = config.get('general.dev_mode', False)
|
||||||
|
|
||||||
# configure logger and stuff
|
# configure logger and stuff
|
||||||
self.config = config
|
self.config = config
|
||||||
self.storage_counter = storagecounter.StorageCounter()
|
self.storage_counter = storagecounter.StorageCounter()
|
||||||
@ -69,8 +82,10 @@ class OnionrCommunicatorDaemon:
|
|||||||
self.offlinePeers = []
|
self.offlinePeers = []
|
||||||
self.cooldownPeer = {}
|
self.cooldownPeer = {}
|
||||||
self.connectTimes = {}
|
self.connectTimes = {}
|
||||||
self.peerProfiles = [] # list of peer's profiles (onionrpeers.PeerProfile instances)
|
# list of peer's profiles (onionrpeers.PeerProfile instances)
|
||||||
self.newPeers = [] # Peers merged to us. Don't add to db until we know they're reachable
|
self.peerProfiles = []
|
||||||
|
# Peers merged to us. Don't add to db until we know they're reachable
|
||||||
|
self.newPeers = []
|
||||||
self.announceProgress = {}
|
self.announceProgress = {}
|
||||||
self.announceCache = {}
|
self.announceCache = {}
|
||||||
|
|
||||||
@ -182,6 +197,12 @@ class OnionrCommunicatorDaemon:
|
|||||||
if config.get('general.use_bootstrap', True):
|
if config.get('general.use_bootstrap', True):
|
||||||
bootstrappeers.add_bootstrap_list_to_peer_list(self, [], db_only=True)
|
bootstrappeers.add_bootstrap_list_to_peer_list(self, [], db_only=True)
|
||||||
|
|
||||||
|
if not config.get('onboarding.done', True):
|
||||||
|
logger.info('First run detected. Run openhome to get setup.', terminal=True)
|
||||||
|
|
||||||
|
while not config.get('onboarding.done', True):
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
||||||
try:
|
try:
|
||||||
while not self.shutdown:
|
while not self.shutdown:
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
import os, json, logger
|
import os, json, logger
|
||||||
import filepaths
|
import filepaths
|
||||||
|
|
||||||
|
from . import onboarding
|
||||||
|
|
||||||
_configfile = filepaths.config_file
|
_configfile = filepaths.config_file
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
|
@ -4,9 +4,12 @@
|
|||||||
Setup config from onboarding choices
|
Setup config from onboarding choices
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from filepaths import onboarding_mark_file
|
from filepaths import onboarding_mark_file
|
||||||
import onionrtypes
|
from onionrtypes import JSONSerializable
|
||||||
|
from onionrtypes import OnboardingConfig
|
||||||
|
import config
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -23,8 +26,29 @@ import onionrtypes
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def set_config_from_onboarding(config_settings: onionrtypes.OnboardingConfig):
|
def _get_val_or_none(json: dict, key: str) -> Union[None, JSONSerializable]:
|
||||||
return
|
try:
|
||||||
|
return json['configInfo'][key]
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def set_config_from_onboarding(config_settings: OnboardingConfig):
|
||||||
|
|
||||||
|
network_security_level = 0
|
||||||
|
theme = "dark"
|
||||||
|
|
||||||
|
if _get_val_or_none(config_settings, 'stateTarget') == True:
|
||||||
|
config.set('general.security_level', 1)
|
||||||
|
|
||||||
|
if _get_val_or_none(config_settings, 'useDark') == False:
|
||||||
|
config.set('ui.theme', 'light')
|
||||||
|
|
||||||
|
config.set('general.store_plaintext_blocks',
|
||||||
|
_get_val_or_none(config_settings, 'plainContrib'))
|
||||||
|
|
||||||
|
|
||||||
|
config.set('onboarding.done', True, savefile=True)
|
||||||
|
|
||||||
def set_onboarding_finished():
|
def set_onboarding_finished():
|
||||||
"""Create the onboarding completed setting file"""
|
"""Create the onboarding completed setting file"""
|
||||||
|
@ -140,3 +140,7 @@ class PrivateEndpoints:
|
|||||||
@private_endpoints_bp.route('/gettorsocks')
|
@private_endpoints_bp.route('/gettorsocks')
|
||||||
def get_tor_socks():
|
def get_tor_socks():
|
||||||
return Response(str(client_api._too_many.get(NetController).socksPort))
|
return Response(str(client_api._too_many.get(NetController).socksPort))
|
||||||
|
|
||||||
|
@private_endpoints_bp.route('/setonboarding', methods=['POST'])
|
||||||
|
def set_onboarding():
|
||||||
|
return Response(config.onboarding.set_config_from_onboarding(request.get_json()))
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
import os, time, sys, platform, sqlite3, signal
|
import os, time, sys, platform, sqlite3, signal
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from gevent import time
|
||||||
|
|
||||||
import toomanyobjs
|
import toomanyobjs
|
||||||
|
|
||||||
@ -104,6 +105,7 @@ def daemon():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
events.event('init', threaded = False)
|
events.event('init', threaded = False)
|
||||||
events.event('daemon_start')
|
events.event('daemon_start')
|
||||||
communicator.startCommunicator(shared_state)
|
communicator.startCommunicator(shared_state)
|
||||||
|
@ -8,3 +8,5 @@ DeterministicKeyPassphrase = NewType('DeterministicKeyPassphrase', str)
|
|||||||
BlockHash = NewType('BlockHash', str)
|
BlockHash = NewType('BlockHash', str)
|
||||||
|
|
||||||
OnboardingConfig = NewType('OnboardingConfig', str)
|
OnboardingConfig = NewType('OnboardingConfig', str)
|
||||||
|
|
||||||
|
JSONSerializable = NewType('JSONSerializable', str)
|
||||||
|
@ -73,5 +73,9 @@
|
|||||||
"timers": {
|
"timers": {
|
||||||
"lookupBlocks": 25,
|
"lookupBlocks": 25,
|
||||||
"getBlocks": 10
|
"getBlocks": 10
|
||||||
|
},
|
||||||
|
|
||||||
|
"onboarding": {
|
||||||
|
"done": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ function sendConfig(configInfo){
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({configInfo})
|
body: JSON.stringify({configInfo})
|
||||||
}).then(function(data) {
|
}).then(function(data) {
|
||||||
|
window.location.href = window.location.origin + '/' + window.location.hash
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ document.getElementById('onboardingForm').onsubmit = function(e){
|
|||||||
submitInfo.deterministic = getCheckValue('useDeterministic')
|
submitInfo.deterministic = getCheckValue('useDeterministic')
|
||||||
submitInfo.mail = getCheckValue('useMail')
|
submitInfo.mail = getCheckValue('useMail')
|
||||||
submitInfo.circles = getCheckValue('useCircles')
|
submitInfo.circles = getCheckValue('useCircles')
|
||||||
|
submitInfo.useDark = getCheckValue('useDarkTheme')
|
||||||
|
|
||||||
if (submitInfo.donate){
|
if (submitInfo.donate){
|
||||||
openDonateModal(submitInfo)
|
openDonateModal(submitInfo)
|
||||||
|
@ -41,3 +41,16 @@ restartBtn.onclick = function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fetch('/config/get/onboarding.done', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
"token": webpass
|
||||||
|
}})
|
||||||
|
.then((resp) => resp.text()) // Transform the data into text
|
||||||
|
.then(function(data) {
|
||||||
|
if (data === 'false'){
|
||||||
|
window.location.href = window.location.pathname = "/onboarding/" + window.location.hash
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user