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__))
sys.path.append(script_dir + '/src/')
from etc import onionrvalues
import onionrvalues
sub_script = script_dir + '/' + onionrvalues.SCRIPT_NAME

View File

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

View File

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

View File

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

View File

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

View File

@ -1,36 +1,37 @@
'''
Onionr - Private P2P Communication
"""
Onionr - Private P2P Communication
get lists for user keys or transport addresses
'''
'''
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/>.
'''
get lists for user keys
"""
import sqlite3
import logger
from onionrutils import epoch
from etc import onionrvalues
import onionrvalues
from .. import dbfiles
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):
'''
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
trust sets the minimum trust to list
'''
randomOrder determines if the list should be in a random order
trust sets the minimum trust to list
"""
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor()
@ -45,18 +46,18 @@ def list_pub_keys(randomOrder=True, getPow=False, trust=0):
else:
payload = 'SELECT * FROM peers WHERE trust >= ?;'
peerList = []
peer_list = []
for i in c.execute(payload, (trust,)):
try:
if len(i[0]) != 0:
if getPow:
peerList.append(i[0] + '-' + i[1])
peer_list.append(i[0] + '-' + i[1])
else:
peerList.append(i[0])
peer_list.append(i[0])
except TypeError:
pass
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
'''
'''
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/>.
'''
Remove a transport address but don't ban them
"""
import sqlite3
from onionrplugins import onionrevents as events
from onionrutils import stringvalidators
from onionrutils import mnemonickeys
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:
'''
Remove a user from the user database
'''
"""Remove a user from the user database"""
pubkey = mnemonickeys.get_base32(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()
t = (pubkey,)
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
'''
'''
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/>.
'''
get or set information about a user id
"""
import sqlite3
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):
'''
Get info about a peer from their database entry
"""
Get info about a peer from their database entry
id text 0
name text, 1
adders text, 2
dateSeen not null, 3
trust int 4
hashID text 5
'''
id text 0
name text, 1
adders text, 2
dateSeen not null, 3
trust int 4
hashID text 5
"""
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor()
@ -54,9 +55,9 @@ def get_user_info(peer, info):
return retVal
def set_peer_info(peer, key, data):
'''
"""
Update a peer for a key
'''
"""
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
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
from onionrutils import mnemonickeys
from onionrutils import bytesconverter
from etc import onionrvalues
import onionrvalues
from utils import reconstructhash
"""
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 utils import identifyhome
import filepaths
from etc import onionrvalues, cleanup
import onionrvalues
from onionrutils import cleanup
from onionrcrypto import getourkeypair
from utils import hastor
import runtests
from httpapi import daemoneventsapi
from .. import version
@ -87,15 +87,6 @@ def daemon():
sys.exit(0)
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
shared_state = toomanyobjs.TooMany()

View File

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

View File

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

View File

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

View File

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

View File

@ -8,20 +8,20 @@ import nacl.pwhash
import onionrexceptions
from onionrutils import bytesconverter
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 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.
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/>.
You should have received a copy of the GNU General Public License
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 logger
import netcontroller
from etc import onionrvalues
import onionrvalues
from onionrutils import getopenport
from logger.settings import *
from utils import readstatic
"""
@ -81,10 +81,10 @@ def setup_config():
if type(config.get('client.webpassword')) is type(None):
config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
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)
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)
if type(config.get('client.api_version')) is type(None):
config.set('client.api_version', onionrvalues.API_VERSION, savefile=True)

View File

@ -14,7 +14,7 @@ import nacl.exceptions
from coredb import keydb, dbfiles
import onionrcrypto
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
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 logger, onionrexceptions
from etc import onionrvalues
import onionrvalues
from . import localcommand
'''
This program is free software: you can redistribute it and/or modify

View File

@ -1,34 +1,35 @@
'''
Onionr - Private P2P Communication
"""
Onionr - Private P2P Communication
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/>.
'''
convert a base32 string (intended for ed25519 user ids) to pgp word list
"""
import base64
import niceware
import unpaddedbase32
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 = '-'
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 == '':
pub = onionrcrypto.pub_key
@ -39,7 +40,7 @@ def get_human_readable_ID(pub=''):
#return niceware.bytes_to_passphrase(pub).replace(' ', DELIMITER)
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
try:

View File

@ -6,7 +6,7 @@ from json import JSONDecodeError
import ujson as json
import logger, onionrexceptions
from etc import onionrvalues
import onionrvalues
from . import stringvalidators, epoch, bytesconverter
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
from . import readstatic
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.'):
if onionrvalues.DEVELOPMENT_MODE:
return

View File

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

View File

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

View File

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

View File

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