diff --git a/onionr/communicatorutils/housekeeping.py b/onionr/communicatorutils/housekeeping.py index f9de36b9..e13ca39f 100755 --- a/onionr/communicatorutils/housekeeping.py +++ b/onionr/communicatorutils/housekeeping.py @@ -22,20 +22,24 @@ import logger from onionrusers import onionrusers from onionrutils import epoch from coredb import blockmetadb, dbfiles +import onionrstorage from onionrstorage import removeblock +import onionrblacklist def clean_old_blocks(comm_inst): '''Delete old blocks if our disk allocation is full/near full, and also expired blocks''' - + blacklist = onionrblacklist.OnionrBlackList() # Delete expired blocks for bHash in blockmetadb.expiredblocks.get_expired_blocks(): - comm_inst.blacklist.addToDB(bHash) + blacklist.addToDB(bHash) removeblock.remove_block(bHash) + onionrstorage.deleteBlock(bHash) logger.info('Deleted block: %s' % (bHash,)) while comm_inst.storage_counter.isFull(): oldest = blockmetadb.get_block_list()[0] - comm_inst.blacklist.addToDB(oldest) + blacklist.addToDB(oldest) removeblock.remove_block(oldest) + onionrstorage.deleteBlock(bHash) logger.info('Deleted block: %s' % (oldest,)) comm_inst.decrementThreadCount('clean_old_blocks') diff --git a/onionr/communicatorutils/servicecreator.py b/onionr/communicatorutils/servicecreator.py index 11ec2b2b..6fa15346 100755 --- a/onionr/communicatorutils/servicecreator.py +++ b/onionr/communicatorutils/servicecreator.py @@ -34,6 +34,6 @@ def service_creator(daemon): signer = bytesconverter.bytes_to_str(bl.signer) daemon.active_services.append(b) daemon.active_services.append(signer) - daemon.services.create_server(signer, bs) + daemon.services.create_server(signer, bs, daemon) daemon.decrementThreadCount('service_creator') \ No newline at end of file diff --git a/onionr/dbcreator.py b/onionr/dbcreator.py index a864ff26..50cc4817 100755 --- a/onionr/dbcreator.py +++ b/onionr/dbcreator.py @@ -163,5 +163,21 @@ def createDaemonDB(): conn.commit() conn.close() +def create_blacklist_db(): + if os.path.exists(dbfiles.blacklist_db): + raise FileExistsError("Blacklist db already exists") + conn = sqlite3.connect(dbfiles.blacklist_db, timeout=10) + c = conn.cursor() + # Create table + c.execute('''CREATE TABLE blacklist( + hash text primary key not null, + dataType int, + blacklistDate int, + expire int + ); + ''') + conn.commit() + conn.close() -create_funcs = [createAddressDB, createPeerDB, createBlockDB, createBlockDataDB, createForwardKeyDB, createDaemonDB] \ No newline at end of file + +create_funcs = [createAddressDB, createPeerDB, createBlockDB, createBlockDataDB, createForwardKeyDB, createDaemonDB, create_blacklist_db] \ No newline at end of file diff --git a/onionr/onionr.py b/onionr/onionr.py index d6c8fbc2..fc760d20 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -93,7 +93,7 @@ class Onionr: try: os.mkdir(plugins.get_plugin_data_folder(name)) except Exception as e: - logger.warn('Error enabling plugin: ' + str(e)) + #logger.warn('Error enabling plugin: ' + str(e), terminal=True) plugins.disable(name, onionr = self, stop_event = False) self.communicatorInst = None diff --git a/onionr/onionrblacklist.py b/onionr/onionrblacklist.py index d0702e5e..f40c3e3a 100755 --- a/onionr/onionrblacklist.py +++ b/onionr/onionrblacklist.py @@ -75,13 +75,6 @@ class OnionrBlackList: self._dbExecute("DELETE FROM blacklist WHERE hash = ?", (thing,)) def generateDB(self): - self._dbExecute('''CREATE TABLE blacklist( - hash text primary key not null, - dataType int, - blacklistDate int, - expire int - ); - ''') return def clearDB(self): @@ -102,7 +95,7 @@ class OnionrBlackList: ''' # we hash the data so we can remove data entirely from our node's disk - hashed = bytesconverter.bytes_to_str(crypto.sha3Hash(data)) + hashed = bytesconverter.bytes_to_str(onionrcrypto.hashers.sha3_hash(data)) if len(hashed) > 64: raise Exception("Hashed data is too large") diff --git a/onionr/onionrservices/__init__.py b/onionr/onionrservices/__init__.py index 0d33b973..78ce5f3e 100755 --- a/onionr/onionrservices/__init__.py +++ b/onionr/onionrservices/__init__.py @@ -32,7 +32,7 @@ class OnionrServices: self.shutdown = False return - def create_server(self, peer, address): + def create_server(self, peer, address, comm_inst): ''' When a client wants to connect, contact their bootstrap address and tell them our ephemeral address for our service by creating a new ConnectionServer instance @@ -46,7 +46,7 @@ class OnionrServices: for x in range(BOOTSTRAP_TRIES): if basicrequests.do_get_request(base_url + 'ping', port=socks, ignoreAPI=True) == 'pong!': # if bootstrap sever is online, tell them our service address - connectionserver.ConnectionServer(peer, address) + connectionserver.ConnectionServer(peer, address, comm_inst=comm_inst) else: time.sleep(TRY_WAIT) else: diff --git a/onionr/onionrservices/bootstrapservice.py b/onionr/onionrservices/bootstrapservice.py index 9d77ec9d..cccc6f34 100755 --- a/onionr/onionrservices/bootstrapservice.py +++ b/onionr/onionrservices/bootstrapservice.py @@ -24,7 +24,7 @@ from flask import Flask, Response from netcontroller import get_open_port from . import httpheaders from onionrutils import stringvalidators, epoch - +import config, onionrblocks def bootstrap_client_service(peer, onionr_inst=None, bootstrap_timeout=300): ''' Bootstrap client services @@ -68,12 +68,12 @@ def bootstrap_client_service(peer, onionr_inst=None, bootstrap_timeout=300): else: return Response("") - with Controller.from_port(port=onionr_inst.config.get('tor.controlPort')) as controller: + with Controller.from_port(port=config.get('tor.controlPort')) as controller: # Connect to the Tor process for Onionr - controller.authenticate(onionr_inst.config.get('tor.controlpassword')) + controller.authenticate(config.get('tor.controlpassword')) # Create the v3 onion service response = controller.create_ephemeral_hidden_service({80: bootstrap_port}, key_type = 'NEW', key_content = 'ED25519-V3', await_publication = True) - core_inst.insertBlock(response.service_id, header='con', sign=True, encryptType='asym', + onionrblocks.insert(response.service_id, header='con', sign=True, encryptType='asym', asymPeer=peer, disableForward=True, expire=(epoch.get_epoch() + bootstrap_timeout)) # Run the bootstrap server try: diff --git a/onionr/onionrservices/connectionserver.py b/onionr/onionrservices/connectionserver.py index 237f105f..a62e191a 100755 --- a/onionr/onionrservices/connectionserver.py +++ b/onionr/onionrservices/connectionserver.py @@ -21,24 +21,24 @@ from gevent.pywsgi import WSGIServer from stem.control import Controller from flask import Flask import logger, httpapi -import onionrexceptions +import onionrexceptions, config from netcontroller import get_open_port from httpapi import apiutils from onionrutils import stringvalidators, basicrequests, bytesconverter from . import httpheaders class ConnectionServer: - def __init__(self, peer, address, onionr_inst=None): + def __init__(self, peer, address, comm_inst=None): if not stringvalidators.validate_pub_key(peer): raise ValueError('Peer must be valid base32 ed25519 public key') - socks = onionr_inst.config.get('tor.socksport') # Load config for Tor socks port for proxy + socks = config.get('tor.socksport') # Load config for Tor socks port for proxy service_app = Flask(__name__) # Setup Flask app for server. service_port = get_open_port() service_ip = apiutils.setbindip.set_bind_IP() http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None) - onionr_inst.communicatorInst.service_greenlets.append(http_server) + comm_inst.service_greenlets.append(http_server) # TODO define basic endpoints useful for direct connections like stats @@ -50,7 +50,7 @@ class ConnectionServer: @service_app.route('/close') def shutdown_server(): - onionr_inst.communicatorInst.service_greenlets.remove(http_server) + comm_inst.service_greenlets.remove(http_server) http_server.stop() return Response('goodbye') @@ -60,9 +60,9 @@ class ConnectionServer: resp = httpheaders.set_default_onionr_http_headers(resp) return resp - with Controller.from_port(port=onionr_inst.config.get('tor.controlPort')) as controller: + with Controller.from_port(port=config.get('tor.controlPort')) as controller: # Connect to the Tor process for Onionr - controller.authenticate(onionr_inst.config.get('tor.controlpassword')) + controller.authenticate(config.get('tor.controlpassword')) # Create the v3 onion service for the peer to connect to response = controller.create_ephemeral_hidden_service({80: service_port}, await_publication = True, key_type='NEW', key_content = 'ED25519-V3') diff --git a/onionr/onionrstorage/removeblock.py b/onionr/onionrstorage/removeblock.py index 9aadea51..e5a439c6 100644 --- a/onionr/onionrstorage/removeblock.py +++ b/onionr/onionrstorage/removeblock.py @@ -11,7 +11,7 @@ def remove_block(block): ''' if stringvalidators.validate_hash(block): - conn = sqlite3.connect(dbfiles.block_data_db, timeout=30) + conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30) c = conn.cursor() t = (block,) c.execute('Delete from hashes where hash=?;', t) diff --git a/onionr/static-data/default-plugins/chat/main.py b/onionr/static-data/default-plugins/chat/main.py index fbf00193..d00720a0 100755 --- a/onionr/static-data/default-plugins/chat/main.py +++ b/onionr/static-data/default-plugins/chat/main.py @@ -87,8 +87,7 @@ def on_init(api, data = None): inputted is executed. Could be called when daemon is starting or when just the client is running. ''' - pluginapi = api - chat = chat(pluginapi) + chat = Chat(pluginapi) api.commands.register(['chat'], chat.create) return diff --git a/onionr/static-data/default-plugins/chat/peerserver.py b/onionr/static-data/default-plugins/chat/peerserver.py index 8e40cefe..40a9fa10 100755 --- a/onionr/static-data/default-plugins/chat/peerserver.py +++ b/onionr/static-data/default-plugins/chat/peerserver.py @@ -50,6 +50,7 @@ def sendto(): else: msg = json.dumps(msg) localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg) + print(msg) return Response('success') @direct_blueprint.route('/chat/poll') diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 3fb3b3a8..99d2a19c 100755 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -6,7 +6,7 @@ "minimum_block_pow" : 4, "minimum_send_pow" : 4, "use_subprocess_pow_if_possible" : true, - "socket_servers" : false, + "socket_servers" : true, "security_level" : 0, "hide_created_blocks" : true, "insert_deniable_blocks" : true, diff --git a/test.html b/test.html new file mode 100755 index 00000000..0ce38504 --- /dev/null +++ b/test.html @@ -0,0 +1,14 @@ +
This document has no single point of failure, and knowing you read it is impossible.
+ +After 1.25 years in development, hopefully it will have been worth the wait.