Removed netcontroller

Removed etc (moving most to onionrutils)
Small refactoring
This commit is contained in:
Kevin F 2022-02-06 19:18:53 -06:00
parent df686b3995
commit cedd01c98f
35 changed files with 143 additions and 213 deletions

View File

@ -15,7 +15,7 @@ import sys
script_dir = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(script_dir + '/src/') sys.path.append(script_dir + '/src/')
from etc import onionrvalues import onionrvalues
sub_script = script_dir + '/' + onionrvalues.SCRIPT_NAME sub_script = script_dir + '/' + onionrvalues.SCRIPT_NAME

View File

@ -48,7 +48,7 @@ if __name__ == "__main__": ran_as_script = True
# Import standard libraries # Import standard libraries
try: try:
from etc import dependencycheck # noqa from onionrutils import dependencycheck # noqa
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
print('Missing requirement: ' + str(e) + ' installed') print('Missing requirement: ' + str(e) + ' installed')
sys.exit(1) sys.exit(1)
@ -60,7 +60,7 @@ from filenuke import nuke # noqa
# Onionr imports # Onionr imports
# For different Onionr related constants such as versions # For different Onionr related constants such as versions
from etc import onionrvalues # noqa import onionrvalues # noqa
import onionrexceptions # noqa import onionrexceptions # noqa
import onionrsetup as setup # noqa import onionrsetup as setup # noqa

View File

@ -13,7 +13,7 @@ import httpapi
from filepaths import private_API_host_file from filepaths import private_API_host_file
import logger import logger
from etc import waitforsetvar from onionrutils import waitforsetvar
from . import register_private_blueprints from . import register_private_blueprints
import config import config

View File

@ -6,7 +6,6 @@ from utils import identifyhome
block_db_path = identifyhome.identify_home() + 'blockdata' block_db_path = identifyhome.identify_home() + 'blockdata'
def store_vdf_block(block: Block): def store_vdf_block(block: Block):
db.set(block_db_path, block.id, block.raw) db.set(block_db_path, block.id, block.raw)

View File

@ -7,7 +7,7 @@ from onionrutils import stringvalidators
from . import listkeys from . import listkeys
from .. import dbfiles from .. import dbfiles
import onionrcrypto import onionrcrypto
from etc import onionrvalues import onionrvalues
""" """
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

View File

@ -1,36 +1,37 @@
''' """
Onionr - Private P2P Communication Onionr - Private P2P Communication
get lists for user keys or transport addresses get lists for user keys
''' """
'''
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 sqlite3 import sqlite3
import logger import logger
from onionrutils import epoch from onionrutils import epoch
from etc import onionrvalues import onionrvalues
from .. import dbfiles from .. import dbfiles
from . import userinfo from . import userinfo
"""
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/>.
"""
def list_pub_keys(randomOrder=True, getPow=False, trust=0): def list_pub_keys(randomOrder=True, getPow=False, trust=0):
''' """
Return a list of public keys (misleading function name) Return a list of public keys (misleading function name)
randomOrder determines if the list should be in a random order randomOrder determines if the list should be in a random order
trust sets the minimum trust to list trust sets the minimum trust to list
''' """
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor() c = conn.cursor()
@ -45,18 +46,18 @@ def list_pub_keys(randomOrder=True, getPow=False, trust=0):
else: else:
payload = 'SELECT * FROM peers WHERE trust >= ?;' payload = 'SELECT * FROM peers WHERE trust >= ?;'
peerList = [] peer_list = []
for i in c.execute(payload, (trust,)): for i in c.execute(payload, (trust,)):
try: try:
if len(i[0]) != 0: if len(i[0]) != 0:
if getPow: if getPow:
peerList.append(i[0] + '-' + i[1]) peer_list.append(i[0] + '-' + i[1])
else: else:
peerList.append(i[0]) peer_list.append(i[0])
except TypeError: except TypeError:
pass pass
conn.close() conn.close()
return peerList return peer_list

View File

@ -1,38 +1,37 @@
''' """
Onionr - Private P2P Communication Onionr - Private P2P Communication
Remove a transport address but don't ban them Remove a transport address but don't ban them
''' """
'''
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 sqlite3 import sqlite3
from onionrplugins import onionrevents as events from onionrplugins import onionrevents as events
from onionrutils import stringvalidators from onionrutils import stringvalidators
from onionrutils import mnemonickeys from onionrutils import mnemonickeys
from .. import dbfiles from .. import dbfiles
from etc import onionrvalues import onionrvalues
"""
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/>.
"""
def remove_user(pubkey: str)->bool: def remove_user(pubkey: str)->bool:
''' """Remove a user from the user database"""
Remove a user from the user database
'''
pubkey = mnemonickeys.get_base32(pubkey) pubkey = mnemonickeys.get_base32(pubkey)
if stringvalidators.validate_pub_key(pubkey): if stringvalidators.validate_pub_key(pubkey):
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) conn = sqlite3.connect(
dbfiles.user_id_info_db,
timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor() c = conn.cursor()
t = (pubkey,) t = (pubkey,)
c.execute('Delete from peers where id=?;', t) c.execute('Delete from peers where id=?;', t)

View File

@ -1,37 +1,38 @@
''' """
Onionr - Private P2P Communication Onionr - Private P2P Communication
get or set information about a user id get or set information about a user id
''' """
'''
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 sqlite3 import sqlite3
from .. import dbfiles from .. import dbfiles
from etc import onionrvalues import onionrvalues
"""
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/>.
"""
def get_user_info(peer, info): def get_user_info(peer, info):
''' """
Get info about a peer from their database entry Get info about a peer from their database entry
id text 0 id text 0
name text, 1 name text, 1
adders text, 2 adders text, 2
dateSeen not null, 3 dateSeen not null, 3
trust int 4 trust int 4
hashID text 5 hashID text 5
''' """
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor() c = conn.cursor()
@ -54,9 +55,9 @@ def get_user_info(peer, info):
return retVal return retVal
def set_peer_info(peer, key, data): def set_peer_info(peer, key, data):
''' """
Update a peer for a key Update a peer for a key
''' """
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor() c = conn.cursor()

View File

@ -1,9 +0,0 @@
# etc
Files that don't really fit anywhere else, but aren't used very frequently.
## Files
humanreadabletime.py: take integer seconds and return a human readable time string
onionrvalues.py: spec values for onionr blocks and other things

View File

View File

@ -1,38 +0,0 @@
'''
Onionr - Private P2P Communication
human_readable_time takes integer seconds and returns a human readable string
'''
'''
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/>.
'''
def human_readable_time(seconds):
build = ''
units = {
'year' : 31557600,
'month' : (31557600 / 12),
'day' : 86400,
'hour' : 3600,
'minute' : 60,
'second' : 1
}
for unit in units:
amnt_unit = int(seconds / units[unit])
if amnt_unit >= 1:
seconds -= amnt_unit * units[unit]
build += '%s %s' % (amnt_unit, unit) + ('s' if amnt_unit != 1 else '') + ' '
return build.strip()

View File

@ -17,7 +17,7 @@ import onionrcrypto
import config import config
from onionrutils import mnemonickeys from onionrutils import mnemonickeys
from onionrutils import bytesconverter from onionrutils import bytesconverter
from etc import onionrvalues import onionrvalues
from utils import reconstructhash from utils import reconstructhash
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -1,11 +0,0 @@
from . import getopenport
from .getopenport import get_open_port
import os
from shutil import which
def tor_binary():
"""Return tor binary path or none if not exists"""
tor_path = './tor'
if not os.path.exists(tor_path):
tor_path = which('tor')
return tor_path

View File

@ -24,9 +24,9 @@ from onionrplugins import onionrevents as events
from onionrutils import localcommand from onionrutils import localcommand
from utils import identifyhome from utils import identifyhome
import filepaths import filepaths
from etc import onionrvalues, cleanup import onionrvalues
from onionrutils import cleanup
from onionrcrypto import getourkeypair from onionrcrypto import getourkeypair
from utils import hastor
import runtests import runtests
from httpapi import daemoneventsapi from httpapi import daemoneventsapi
from .. import version from .. import version
@ -87,15 +87,6 @@ def daemon():
sys.exit(0) sys.exit(0)
signal.signal(signal.SIGTERM, _handle_sig_term) signal.signal(signal.SIGTERM, _handle_sig_term)
# Determine if Onionr is in offline mode.
# When offline, Onionr can only use LAN and disk transport
offline_mode = config.get('general.offline_mode', False)
if not hastor.has_tor():
offline_mode = True
logger.error("Tor is not present in system path or Onionr directory",
terminal=True)
# Create shared objects # Create shared objects
shared_state = toomanyobjs.TooMany() shared_state = toomanyobjs.TooMany()

View File

@ -9,7 +9,7 @@ from utils import sizeutils, getconsolewidth, identifyhome
from coredb import keydb from coredb import keydb
import onionrcrypto import onionrcrypto
import config import config
from etc import onionrvalues import onionrvalues
from filepaths import lock_file from filepaths import lock_file
import psutil import psutil

View File

@ -14,7 +14,7 @@ from onionrutils import stringvalidators, bytesconverter
import config import config
import keymanager import keymanager
import onionrcrypto import onionrcrypto
from etc import onionrvalues import onionrvalues
""" """
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

View File

@ -9,8 +9,8 @@ import subprocess # nosec
from psutil import Process from psutil import Process
from etc import onionrvalues import onionrvalues
from etc import cleanup from onionrutils import cleanup
from onionrutils import localcommand from onionrutils import localcommand
import logger import logger
import filepaths import filepaths

View File

@ -4,7 +4,7 @@ Command to show version info
""" """
import platform import platform
from utils import identifyhome from utils import identifyhome
from etc import onionrvalues import onionrvalues
import logger import logger
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -8,20 +8,20 @@ import nacl.pwhash
import onionrexceptions import onionrexceptions
from onionrutils import bytesconverter from onionrutils import bytesconverter
from etc import onionrvalues import onionrvalues
""" """
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
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
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/>.
""" """

View File

@ -9,8 +9,8 @@ import ujson as json
import config import config
import logger import logger
import netcontroller import onionrvalues
from etc import onionrvalues from onionrutils import getopenport
from logger.settings import * from logger.settings import *
from utils import readstatic from utils import readstatic
""" """
@ -81,10 +81,10 @@ def setup_config():
if type(config.get('client.webpassword')) is type(None): if type(config.get('client.webpassword')) is type(None):
config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True) config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
if type(config.get('client.client.port')) is type(None): if type(config.get('client.client.port')) is type(None):
randomPort = netcontroller.getopenport.get_open_port() randomPort = getopenport.get_open_port()
config.set('client.client.port', randomPort, savefile=True) config.set('client.client.port', randomPort, savefile=True)
if type(config.get('client.public.port')) is type(None): if type(config.get('client.public.port')) is type(None):
randomPort = netcontroller.getopenport.get_open_port() randomPort = getopenport.get_open_port()
config.set('client.public.port', randomPort, savefile=True) config.set('client.public.port', randomPort, savefile=True)
if type(config.get('client.api_version')) is type(None): if type(config.get('client.api_version')) is type(None):
config.set('client.api_version', onionrvalues.API_VERSION, savefile=True) config.set('client.api_version', onionrvalues.API_VERSION, savefile=True)

View File

@ -14,7 +14,7 @@ import nacl.exceptions
from coredb import keydb, dbfiles from coredb import keydb, dbfiles
import onionrcrypto import onionrcrypto
from onionrcrypto import getourkeypair from onionrcrypto import getourkeypair
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT from onionrvalues import DATABASE_LOCK_TIMEOUT
""" """
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

View File

@ -7,7 +7,7 @@ from urllib.parse import urlparse
import requests, streamedrequests import requests, streamedrequests
import logger, onionrexceptions import logger, onionrexceptions
from etc import onionrvalues import onionrvalues
from . import localcommand from . import localcommand
''' '''
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -1,45 +1,46 @@
''' """
Onionr - Private P2P Communication Onionr - Private P2P Communication
convert a base32 string (intended for ed25519 user ids) to pgp word list convert a base32 string (intended for ed25519 user ids) to pgp word list
''' """
'''
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 base64 import base64
import niceware import niceware
import unpaddedbase32 import unpaddedbase32
import onionrcrypto import onionrcrypto
from etc import onionrvalues import onionrvalues
"""
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/>.
"""
DELIMITER = '-' DELIMITER = '-'
def get_human_readable_ID(pub=''): def get_human_readable_ID(pub=''):
'''gets a human readable ID from a public key''' """gets a human readable ID from a public key"""
if pub == '': if pub == '':
pub = onionrcrypto.pub_key pub = onionrcrypto.pub_key
if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE: if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE:
pub = base64.b32decode(pub) pub = base64.b32decode(pub)
return DELIMITER.join(niceware.bytes_to_passphrase(pub)) return DELIMITER.join(niceware.bytes_to_passphrase(pub))
#return niceware.bytes_to_passphrase(pub).replace(' ', DELIMITER) #return niceware.bytes_to_passphrase(pub).replace(' ', DELIMITER)
def get_base32(words): def get_base32(words):
'''converts mnemonic to base32''' """converts mnemonic to base32"""
if DELIMITER not in words and not type(words) in (type(list), type(tuple)): return words if DELIMITER not in words and not type(words) in (type(list), type(tuple)): return words
try: try:

View File

@ -6,7 +6,7 @@ from json import JSONDecodeError
import ujson as json import ujson as json
import logger, onionrexceptions import logger, onionrexceptions
from etc import onionrvalues import onionrvalues
from . import stringvalidators, epoch, bytesconverter from . import stringvalidators, epoch, bytesconverter
import config, filepaths, onionrcrypto import config, filepaths, onionrcrypto
""" """

View File

@ -1,4 +0,0 @@
import netcontroller
def has_tor():
return netcontroller.tor_binary() is not None

View File

@ -1,7 +1,7 @@
import sys, os import sys, os
from . import readstatic from . import readstatic
import logger import logger
from etc import onionrvalues import onionrvalues
def header(message = logger.colors.fg.pink + logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink + ' has started.'): def header(message = logger.colors.fg.pink + logger.colors.bold + 'Onionr' + logger.colors.reset + logger.colors.fg.pink + ' has started.'):
if onionrvalues.DEVELOPMENT_MODE: if onionrvalues.DEVELOPMENT_MODE:
return return

View File

@ -10,7 +10,7 @@ import unittest, json
from utils import identifyhome, createdirs from utils import identifyhome, createdirs
createdirs.create_dirs() createdirs.create_dirs()
from etc.cleanup import delete_run_files from onionrutils.cleanup import delete_run_files
import filepaths import filepaths

View File

@ -7,11 +7,11 @@ import unittest, uuid
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
import netcontroller from onionrutils import getopenport
class GetOpenPortTest(unittest.TestCase): class GetOpenPortTest(unittest.TestCase):
def test_open_port(self): def test_open_port(self):
open_port = int(netcontroller.get_open_port()) open_port = int(getopenport.get_open_port())
self.assertGreaterEqual(open_port, 1024) self.assertGreaterEqual(open_port, 1024)
unittest.main() unittest.main()

View File

@ -9,7 +9,7 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import identifyhome, createdirs from utils import identifyhome, createdirs
from etc import onionrvalues import onionrvalues
class TestOnionrValues(unittest.TestCase): class TestOnionrValues(unittest.TestCase):
def test_api_version(self): def test_api_version(self):

View File

@ -9,7 +9,7 @@ from utils import createdirs
createdirs.create_dirs() createdirs.create_dirs()
from onionrcrypto import getourkeypair from onionrcrypto import getourkeypair
getourkeypair.get_keypair() getourkeypair.get_keypair()
from etc import waitforsetvar from onionrutils import waitforsetvar
def set_test_var_delay(obj, delay=0): def set_test_var_delay(obj, delay=0):
if delay > 0: time.sleep(delay) if delay > 0: time.sleep(delay)