progress removing onionr.py
This commit is contained in:
		
							parent
							
								
									2f9c1de062
								
							
						
					
					
						commit
						705962e9e7
					
				
					 12 changed files with 26 additions and 110 deletions
				
			
		|  | @ -17,7 +17,7 @@ | ||||||
|     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 base64, os | import base64, os, time | ||||||
| import flask | import flask | ||||||
| from gevent.pywsgi import WSGIServer | from gevent.pywsgi import WSGIServer | ||||||
| from onionrutils import epoch | 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 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 |             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.config = config | ||||||
|         self.serializer = serializeddata.SerializedData() |         self.serializer = serializeddata.SerializedData() | ||||||
|         self.startTime = epoch.get_epoch() |         self.startTime = epoch.get_epoch() | ||||||
|  |  | ||||||
|  | @ -38,6 +38,7 @@ class PublicAPI: | ||||||
|         The new client api server, isolated from the public api |         The new client api server, isolated from the public api | ||||||
|     ''' |     ''' | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|  |         time.sleep(1) | ||||||
|         app = flask.Flask('PublicAPI') |         app = flask.Flask('PublicAPI') | ||||||
|         app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 |         app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 | ||||||
|         self.i2pEnabled = config.get('i2p.host', False) |         self.i2pEnabled = config.get('i2p.host', False) | ||||||
|  |  | ||||||
|  | @ -51,8 +51,7 @@ class OnionrCommunicatorTimers: | ||||||
|                 if self.makeThread: |                 if self.makeThread: | ||||||
|                     for i in range(self.threadAmount): |                     for i in range(self.threadAmount): | ||||||
|                         if self.daemonInstance.threadCounts[self.timerFunction.__name__] >= self.maxThreads: |                         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: |                         else: | ||||||
|                             self.daemonInstance.threadCounts[self.timerFunction.__name__] += 1 |                             self.daemonInstance.threadCounts[self.timerFunction.__name__] += 1 | ||||||
|                             newThread = threading.Thread(target=self.timerFunction, args=self.args, daemon=True) |                             newThread = threading.Thread(target=self.timerFunction, args=self.args, daemon=True) | ||||||
|  |  | ||||||
|  | @ -21,6 +21,7 @@ from flask import Response, Blueprint, request, send_from_directory, abort | ||||||
| from httpapi import apiutils | from httpapi import apiutils | ||||||
| import onionrcrypto, config | import onionrcrypto, config | ||||||
| from netcontroller import NetController | from netcontroller import NetController | ||||||
|  | from serializeddata import SerializedData | ||||||
| pub_key = onionrcrypto.pub_key | pub_key = onionrcrypto.pub_key | ||||||
| class PrivateEndpoints: | class PrivateEndpoints: | ||||||
|     def __init__(self, client_api): |     def __init__(self, client_api): | ||||||
|  | @ -97,8 +98,9 @@ class PrivateEndpoints: | ||||||
|             #return Response("disabled") |             #return Response("disabled") | ||||||
|             while True: |             while True: | ||||||
|                 try:     |                 try:     | ||||||
|                     return Response(client_api.serializer.getStats()) |                     return Response(client_api._too_many.get(SerializedData).getStats()) | ||||||
|                 except AttributeError: |                 except AttributeError as e: | ||||||
|  |                     print("damn", e) | ||||||
|                     pass |                     pass | ||||||
|          |          | ||||||
|         @private_endpoints_bp.route('/getuptime') |         @private_endpoints_bp.route('/getuptime') | ||||||
|  |  | ||||||
|  | @ -33,6 +33,7 @@ from etc import onionrvalues, cleanup | ||||||
| from onionrcrypto import getourkeypair | from onionrcrypto import getourkeypair | ||||||
| from utils import hastor, logoheader | from utils import hastor, logoheader | ||||||
| from . import version | from . import version | ||||||
|  | import serializeddata | ||||||
| 
 | 
 | ||||||
| def _proper_shutdown(): | def _proper_shutdown(): | ||||||
|     localcommand.local_command('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.ClientAPI).start, daemon=True).start() | ||||||
|     Thread(target=shared_state.get(apiservers.PublicAPI).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 |     shared_state.share_object() # share the parent object to the threads | ||||||
| 
 | 
 | ||||||
|     apiHost = '' |     apiHost = '' | ||||||
|  |  | ||||||
|  | @ -20,12 +20,13 @@ | ||||||
| import webbrowser | import webbrowser | ||||||
| import logger | import logger | ||||||
| from onionrutils import getclientapiserver | from onionrutils import getclientapiserver | ||||||
| def open_home(o_inst): | import config | ||||||
|  | def open_home(): | ||||||
|     try: |     try: | ||||||
|         url = getclientapiserver.get_client_API_server() |         url = getclientapiserver.get_client_API_server() | ||||||
|     except FileNotFoundError: |     except FileNotFoundError: | ||||||
|         logger.error('Onionr seems to not be running (could not get api host)', terminal=True) |         logger.error('Onionr seems to not be running (could not get api host)', terminal=True) | ||||||
|     else: |     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) |         logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True) | ||||||
|         webbrowser.open_new_tab(url) |         webbrowser.open_new_tab(url) | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| from .. import onionrstatistics, version, daemonlaunch, keyadders | from .. import onionrstatistics, version, daemonlaunch, keyadders, openwebinterface | ||||||
| import onionrexceptions | import onionrexceptions | ||||||
| import onionrevents as events | import onionrevents as events | ||||||
| def get_arguments(): | def get_arguments(): | ||||||
|  | @ -8,7 +8,8 @@ def get_arguments(): | ||||||
|         ('version'): version.version, |         ('version'): version.version, | ||||||
|         ('start', 'daemon'): daemonlaunch.start, |         ('start', 'daemon'): daemonlaunch.start, | ||||||
|         ('stop', 'kill'): daemonlaunch.kill_daemon, |         ('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 |     return args | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ def call(plugin, event_name, data = None, pluginapi = None): | ||||||
|         try: |         try: | ||||||
|             attribute = 'on_' + str(event_name).lower() |             attribute = 'on_' + str(event_name).lower() | ||||||
|             if pluginapi is None: |             if pluginapi is None: | ||||||
|                 pluginapi = get_pluginapi() |                 pluginapi = get_pluginapi(data) | ||||||
|             if hasattr(plugin, attribute): |             if hasattr(plugin, attribute): | ||||||
|                 return getattr(plugin, attribute)(pluginapi, data) |                 return getattr(plugin, attribute)(pluginapi, data) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,28 +21,6 @@ | ||||||
| import onionrplugins, logger | import onionrplugins, logger | ||||||
| from onionrutils import localcommand | from onionrutils import localcommand | ||||||
| from coredb import daemonqueue | 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: | class PluginAPI: | ||||||
|     def __init__(self, pluginapi): |     def __init__(self, pluginapi): | ||||||
|  | @ -64,7 +42,7 @@ class PluginAPI: | ||||||
|         onionrplugins.disable(name) |         onionrplugins.disable(name) | ||||||
| 
 | 
 | ||||||
|     def event(self, name, data = {}): |     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): |     def is_enabled(self, name): | ||||||
|         return onionrplugins.is_enabled(name) |         return onionrplugins.is_enabled(name) | ||||||
|  | @ -85,72 +63,13 @@ class CommandAPI: | ||||||
|     def __init__(self, pluginapi): |     def __init__(self, pluginapi): | ||||||
|         self.pluginapi = 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): |     def call(self, name): | ||||||
|         self.pluginapi.get_onionr().execute(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: | class SharedAPI: | ||||||
|     def __init__(self, data): |     def __init__(self, data): | ||||||
|         self.data = data |         self.data = data | ||||||
| 
 |  | ||||||
|         self.daemon = DaemonAPI(self) |  | ||||||
|         self.plugins = PluginAPI(self) |         self.plugins = PluginAPI(self) | ||||||
|         self.commands = CommandAPI(self) |  | ||||||
|         self.web = WebAPI(self) |  | ||||||
| 
 | 
 | ||||||
|     def get_data(self): |     def get_data(self): | ||||||
|         return self.data |         return self.data | ||||||
|  | @ -160,12 +79,3 @@ class SharedAPI: | ||||||
| 
 | 
 | ||||||
|     def get_pluginapi(self): |     def get_pluginapi(self): | ||||||
|         return self.plugins |         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 |  | ||||||
|  |  | ||||||
|  | @ -31,7 +31,6 @@ class SerializedData: | ||||||
|             etc |             etc | ||||||
|         } |         } | ||||||
|         ''' |         ''' | ||||||
|         self._too_many = None |  | ||||||
|      |      | ||||||
|     def getStats(self): |     def getStats(self): | ||||||
|         '''Return statistics about our node''' |         '''Return statistics about our node''' | ||||||
|  |  | ||||||
|  | @ -114,6 +114,4 @@ def on_init(api, data = None): | ||||||
|     # by simply referencing the variable `pluginapi`. |     # by simply referencing the variable `pluginapi`. | ||||||
|     pluginapi = api |     pluginapi = api | ||||||
|     ui = OnionrCLIUI(api) |     ui = OnionrCLIUI(api) | ||||||
|     api.commands.register('interactive', ui.start) |  | ||||||
|     api.commands.register_help('interactive', 'Open the CLI interface') |  | ||||||
|     return |     return | ||||||
|  |  | ||||||
|  | @ -107,6 +107,12 @@ class PlainEncryption: | ||||||
|                 logger.info("Message has good signature.", terminal=True) |                 logger.info("Message has good signature.", terminal=True) | ||||||
|         return |         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): | def on_init(api, data = None): | ||||||
|     ''' |     ''' | ||||||
|         This event is called after Onionr is initialized, but before the command |         This event is called after Onionr is initialized, but before the command | ||||||
|  | @ -115,7 +121,3 @@ def on_init(api, data = None): | ||||||
|     ''' |     ''' | ||||||
|     pluginapi = api |     pluginapi = api | ||||||
|     encrypt = PlainEncryption(pluginapi) |     encrypt = PlainEncryption(pluginapi) | ||||||
|     api.commands.register(['encrypt'], encrypt.encrypt) |  | ||||||
|     api.commands.register(['decrypt'], encrypt.decrypt) |  | ||||||
|      |  | ||||||
|     return |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue