Browse Source

Removed netcontroller

Removed etc (moving most to onionrutils)
Small refactoring
newtransport
Kevin F 4 months ago
parent
commit
cedd01c98f
  1. 2
      run-onionr-node.py
  2. 4
      src/__init__.py
  3. 2
      src/apiservers/private/__init__.py
  4. 1
      src/blockdb/__init__.py
  5. 2
      src/coredb/keydb/addkeys.py
  6. 59
      src/coredb/keydb/listkeys.py
  7. 45
      src/coredb/keydb/removekeys.py
  8. 65
      src/coredb/keydb/userinfo.py
  9. 9
      src/etc/README.md
  10. 0
      src/etc/__init__.py
  11. 38
      src/etc/humanreadabletime.py
  12. 2
      src/httpapi/miscclientapi/endpoints.py
  13. 11
      src/netcontroller/__init__.py
  14. 13
      src/onionrcommands/daemonlaunch/__init__.py
  15. 2
      src/onionrcommands/onionrstatistics.py
  16. 2
      src/onionrcommands/pubkeymanager.py
  17. 4
      src/onionrcommands/restartonionr.py
  18. 2
      src/onionrcommands/version.py
  19. 22
      src/onionrcrypto/generate.py
  20. 8
      src/onionrsetup/setupconfig.py
  21. 2
      src/onionrusers/onionrusers.py
  22. 2
      src/onionrutils/basicrequests.py
  23. 0
      src/onionrutils/cleanup/__init__.py
  24. 0
      src/onionrutils/dependencycheck.py
  25. 0
      src/onionrutils/getopenport.py
  26. 49
      src/onionrutils/mnemonickeys.py
  27. 2
      src/onionrutils/validatemetadata.py
  28. 0
      src/onionrutils/waitforsetvar.py
  29. 0
      src/onionrvalues.py
  30. 4
      src/utils/hastor.py
  31. 2
      src/utils/logoheader.py
  32. 2
      tests/test_cleanup.py
  33. 4
      tests/test_getopenport.py
  34. 2
      tests/test_onionrvalues.py
  35. 2
      tests/test_waitforsetvars.py

2
run-onionr-node.py

@ -15,7 +15,7 @@ import sys @@ -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

4
src/__init__.py

@ -48,7 +48,7 @@ if __name__ == "__main__": ran_as_script = True @@ -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 @@ -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

2
src/apiservers/private/__init__.py

@ -13,7 +13,7 @@ import httpapi @@ -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

1
src/blockdb/__init__.py

@ -6,7 +6,6 @@ from utils import identifyhome @@ -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)

2
src/coredb/keydb/addkeys.py

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

59
src/coredb/keydb/listkeys.py

@ -1,36 +1,37 @@ @@ -1,36 +1,37 @@
'''
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/>.
'''
"""
Onionr - Private P2P Communication
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): @@ -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

45
src/coredb/keydb/removekeys.py

@ -1,38 +1,37 @@ @@ -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)

65
src/coredb/keydb/userinfo.py

@ -1,37 +1,38 @@ @@ -1,37 +1,38 @@
'''
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/>.
'''
"""
Onionr - Private P2P Communication
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
id text 0
name text, 1
adders text, 2
dateSeen not null, 3
trust int 4
hashID text 5
'''
"""
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
"""
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): @@ -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()

9
src/etc/README.md

@ -1,9 +0,0 @@ @@ -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

0
src/etc/__init__.py

38
src/etc/humanreadabletime.py

@ -1,38 +0,0 @@ @@ -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()

2
src/httpapi/miscclientapi/endpoints.py

@ -17,7 +17,7 @@ import onionrcrypto @@ -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

11
src/netcontroller/__init__.py

@ -1,11 +0,0 @@ @@ -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

13
src/onionrcommands/daemonlaunch/__init__.py

@ -24,9 +24,9 @@ from onionrplugins import onionrevents as events @@ -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(): @@ -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()

2
src/onionrcommands/onionrstatistics.py

@ -9,7 +9,7 @@ from utils import sizeutils, getconsolewidth, identifyhome @@ -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

2
src/onionrcommands/pubkeymanager.py

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

4
src/onionrcommands/restartonionr.py

@ -9,8 +9,8 @@ import subprocess # nosec @@ -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

2
src/onionrcommands/version.py

@ -4,7 +4,7 @@ Command to show version info @@ -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

22
src/onionrcrypto/generate.py

@ -8,20 +8,20 @@ import nacl.pwhash @@ -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/>.
"""

8
src/onionrsetup/setupconfig.py

@ -9,8 +9,8 @@ import ujson as json @@ -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(): @@ -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)

2
src/onionrusers/onionrusers.py

@ -14,7 +14,7 @@ import nacl.exceptions @@ -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

2
src/onionrutils/basicrequests.py

@ -7,7 +7,7 @@ from urllib.parse import urlparse @@ -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

0
src/etc/cleanup/__init__.py → src/onionrutils/cleanup/__init__.py

0
src/etc/dependencycheck.py → src/onionrutils/dependencycheck.py

0
src/netcontroller/getopenport.py → src/onionrutils/getopenport.py

49
src/onionrutils/mnemonickeys.py

@ -1,45 +1,46 @@ @@ -1,45 +1,46 @@
'''
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/>.
'''
"""
Onionr - Private P2P Communication
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
if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE:
pub = base64.b32decode(pub)
return DELIMITER.join(niceware.bytes_to_passphrase(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:

2
src/onionrutils/validatemetadata.py

@ -6,7 +6,7 @@ from json import JSONDecodeError @@ -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
"""

0
src/etc/waitforsetvar.py → src/onionrutils/waitforsetvar.py

0
src/etc/onionrvalues.py → src/onionrvalues.py

4
src/utils/hastor.py

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

2
src/utils/logoheader.py

@ -1,7 +1,7 @@ @@ -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

2
tests/test_cleanup.py

@ -10,7 +10,7 @@ import unittest, json @@ -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

4
tests/test_getopenport.py

@ -7,11 +7,11 @@ import unittest, uuid @@ -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()

2
tests/test_onionrvalues.py

@ -9,7 +9,7 @@ print("Test directory:", TEST_DIR) @@ -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):

2
tests/test_waitforsetvars.py

@ -9,7 +9,7 @@ from utils import createdirs @@ -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)

Loading…
Cancel
Save