progress removing onionr.py

master
Kevin Froman 2019-08-04 23:08:56 -05:00
parent 2f9c1de062
commit 705962e9e7
12 changed files with 26 additions and 110 deletions

View File

@ -17,7 +17,7 @@
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, os
import base64, os, time
import flask
from gevent.pywsgi import WSGIServer
from onionrutils import epoch
@ -40,6 +40,7 @@ class PrivateAPI:
This initialization defines all of the API entry points and handlers for the endpoints and errors
This also saves the used host (random localhost IP address) to the data folder in host.txt
'''
time.sleep(0.3)
self.config = config
self.serializer = serializeddata.SerializedData()
self.startTime = epoch.get_epoch()

View File

@ -38,6 +38,7 @@ class PublicAPI:
The new client api server, isolated from the public api
'''
def __init__(self):
time.sleep(1)
app = flask.Flask('PublicAPI')
app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024
self.i2pEnabled = config.get('i2p.host', False)

View File

@ -51,8 +51,7 @@ class OnionrCommunicatorTimers:
if self.makeThread:
for i in range(self.threadAmount):
if self.daemonInstance.threadCounts[self.timerFunction.__name__] >= self.maxThreads:
pass
#logger.debug('%s is currently using the maximum number of threads, not starting another.' % self.timerFunction.__name__, terminal=True)
logger.debug('%s is currently using the maximum number of threads, not starting another.' % self.timerFunction.__name__, terminal=True)
else:
self.daemonInstance.threadCounts[self.timerFunction.__name__] += 1
newThread = threading.Thread(target=self.timerFunction, args=self.args, daemon=True)

View File

@ -21,6 +21,7 @@ from flask import Response, Blueprint, request, send_from_directory, abort
from httpapi import apiutils
import onionrcrypto, config
from netcontroller import NetController
from serializeddata import SerializedData
pub_key = onionrcrypto.pub_key
class PrivateEndpoints:
def __init__(self, client_api):
@ -97,8 +98,9 @@ class PrivateEndpoints:
#return Response("disabled")
while True:
try:
return Response(client_api.serializer.getStats())
except AttributeError:
return Response(client_api._too_many.get(SerializedData).getStats())
except AttributeError as e:
print("damn", e)
pass
@private_endpoints_bp.route('/getuptime')

View File

@ -33,6 +33,7 @@ from etc import onionrvalues, cleanup
from onionrcrypto import getourkeypair
from utils import hastor, logoheader
from . import version
import serializeddata
def _proper_shutdown():
localcommand.local_command('shutdown')
@ -57,6 +58,7 @@ def daemon():
Thread(target=shared_state.get(apiservers.ClientAPI).start, daemon=True).start()
Thread(target=shared_state.get(apiservers.PublicAPI).start, daemon=True).start()
shared_state.get(serializeddata.SerializedData)
shared_state.share_object() # share the parent object to the threads
apiHost = ''

View File

@ -20,12 +20,13 @@
import webbrowser
import logger
from onionrutils import getclientapiserver
def open_home(o_inst):
import config
def open_home():
try:
url = getclientapiserver.get_client_API_server()
except FileNotFoundError:
logger.error('Onionr seems to not be running (could not get api host)', terminal=True)
else:
url = 'http://%s/#%s' % (url, o_inst.config.get('client.webpassword'))
url = 'http://%s/#%s' % (url, config.get('client.webpassword'))
logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True)
webbrowser.open_new_tab(url)

View File

@ -1,4 +1,4 @@
from .. import onionrstatistics, version, daemonlaunch, keyadders
from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface
import onionrexceptions
import onionrevents as events
def get_arguments():
@ -8,7 +8,8 @@ def get_arguments():
('version'): version.version,
('start', 'daemon'): daemonlaunch.start,
('stop', 'kill'): daemonlaunch.kill_daemon,
('add-address', 'addaddress', 'addadder'): keyadders.add_address
('add-address', 'addaddress', 'addadder'): keyadders.add_address,
('openhome', 'gui', 'openweb', 'open-home', 'open-web'): openwebinterface.open_home
}
return args

View File

@ -60,7 +60,7 @@ def call(plugin, event_name, data = None, pluginapi = None):
try:
attribute = 'on_' + str(event_name).lower()
if pluginapi is None:
pluginapi = get_pluginapi()
pluginapi = get_pluginapi(data)
if hasattr(plugin, attribute):
return getattr(plugin, attribute)(pluginapi, data)

View File

@ -21,28 +21,6 @@
import onionrplugins, logger
from onionrutils import localcommand
from coredb import daemonqueue
class DaemonAPI:
def __init__(self, pluginapi):
self.pluginapi = pluginapi
def start(self):
self.pluginapi.get_onionr().daemon()
return
def stop(self):
self.pluginapi.get_onionr().killDaemon()
return
def queue(self, command, data = ''):
return daemonqueue.daemon_queue_add(command, data)
def local_command(self, command):
return localcommand.local_command(command)
def queue_pop(self):
return daemonqueue.daemon_queue()
class PluginAPI:
def __init__(self, pluginapi):
@ -64,7 +42,7 @@ class PluginAPI:
onionrplugins.disable(name)
def event(self, name, data = {}):
events.event(name, data = data, onionr = self.pluginapi.get_onionr())
events.event(name, data = data)
def is_enabled(self, name):
return onionrplugins.is_enabled(name)
@ -85,72 +63,13 @@ class CommandAPI:
def __init__(self, pluginapi):
self.pluginapi = pluginapi
def register(self, names, call = None):
if isinstance(names, str):
names = [names]
for name in names:
self.pluginapi.get_onionr().addCommand(name, call)
def unregister(self, names):
if isinstance(names, str):
names = [names]
for name in names:
self.pluginapi.get_onionr().delCommand(name)
return
def register_help(self, names, description):
if isinstance(names, str):
names = [names]
for name in names:
self.pluginapi.get_onionr().addHelp(name, description)
return
def unregister_help(self, names):
if isinstance(names, str):
names = [names]
for name in names:
self.pluginapi.get_onionr().delHelp(name)
return
def call(self, name):
self.pluginapi.get_onionr().execute(name)
return
def get_commands(self):
return self.pluginapi.get_onionr().getCommands()
class WebAPI:
def __init__(self, pluginapi):
self.pluginapi = pluginapi
def register_callback(self, action, callback, scope = 'public'):
return self.pluginapi.get_onionr().api.setCallback(action, callback, scope = scope)
def unregister_callback(self, action, scope = 'public'):
return self.pluginapi.get_onionr().api.removeCallback(action, scope = scope)
def get_callback(self, action, scope = 'public'):
return self.pluginapi.get_onionr().api.getCallback(action, scope= scope)
def get_callbacks(self, scope = None):
return self.pluginapi.get_onionr().api.getCallbacks(scope = scope)
class SharedAPI:
def __init__(self, data):
self.data = data
self.daemon = DaemonAPI(self)
self.plugins = PluginAPI(self)
self.commands = CommandAPI(self)
self.web = WebAPI(self)
def get_data(self):
return self.data
@ -159,13 +78,4 @@ class SharedAPI:
return self.daemon
def get_pluginapi(self):
return self.plugins
def get_commandapi(self):
return self.commands
def get_webapi(self):
return self.web
def is_development_mode(self):
return self.get_onionr()._developmentMode
return self.plugins

View File

@ -31,7 +31,6 @@ class SerializedData:
etc
}
'''
self._too_many = None
def getStats(self):
'''Return statistics about our node'''

View File

@ -114,6 +114,4 @@ def on_init(api, data = None):
# by simply referencing the variable `pluginapi`.
pluginapi = api
ui = OnionrCLIUI(api)
api.commands.register('interactive', ui.start)
api.commands.register_help('interactive', 'Open the CLI interface')
return

View File

@ -107,6 +107,12 @@ class PlainEncryption:
logger.info("Message has good signature.", terminal=True)
return
def on_decrypt_cmd(api, data=None):
PlainEncryption(api).decrypt()
def on_encrypt_cmd(api, data=None):
PlainEncryption(api).encrypt()
def on_init(api, data = None):
'''
This event is called after Onionr is initialized, but before the command
@ -114,8 +120,4 @@ def on_init(api, data = None):
just the client is running.
'''
pluginapi = api
encrypt = PlainEncryption(pluginapi)
api.commands.register(['encrypt'], encrypt.encrypt)
api.commands.register(['decrypt'], encrypt.decrypt)
return
encrypt = PlainEncryption(pluginapi)