From b9beef3cce6f642869824ae8752bd085e71ff8ce Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 23 Mar 2019 21:56:46 -0500 Subject: [PATCH] direct connections closer to working --- onionr/communicator.py | 12 ++++++------ onionr/communicatorutils/servicecreator.py | 17 +++++++++++++++++ onionr/onionrservices/__init__.py | 3 +-- onionr/onionrservices/bootstrapservice.py | 3 +-- onionr/static-data/default_config.json | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 onionr/communicatorutils/servicecreator.py diff --git a/onionr/communicator.py b/onionr/communicator.py index e4a513d6..670e08fa 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -108,7 +108,12 @@ class OnionrCommunicatorDaemon: OnionrCommunicatorTimers(self, self.uploadBlock, 10, requiresPeer=True, maxThreads=1) OnionrCommunicatorTimers(self, self.daemonCommands, 6, maxThreads=1) OnionrCommunicatorTimers(self, self.detectAPICrash, 30, maxThreads=1) - OnionrCommunicatorTimers(self, servicecreator.service_creator, 5, maxThreads=10, myArgs=(self,)) + if config.get('general.socket_servers', False): + self.services = onionrservices.OnionrServices(self._core) + self.active_services = [] + OnionrCommunicatorTimers(self, servicecreator.service_creator, 5, maxThreads=10, myArgs=(self,)) + else: + self.services = None deniableBlockTimer = OnionrCommunicatorTimers(self, self.daemonTools.insertDeniableBlock, 180, requiresPeer=True, maxThreads=1) netCheckTimer = OnionrCommunicatorTimers(self, self.daemonTools.netCheck, 600) @@ -127,11 +132,6 @@ class OnionrCommunicatorDaemon: blockCleanupTimer.count = (blockCleanupTimer.frequency - 5) #forwardSecrecyTimer.count = (forwardSecrecyTimer.frequency - 990) - if config.get('general.socket_servers'): - self.services = onionrservices.OnionrServices(self._core) - else: - self.services = None - # Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking try: while not self.shutdown: diff --git a/onionr/communicatorutils/servicecreator.py b/onionr/communicatorutils/servicecreator.py new file mode 100644 index 00000000..4914547a --- /dev/null +++ b/onionr/communicatorutils/servicecreator.py @@ -0,0 +1,17 @@ +import communicator, onionrblockapi +def service_creator(daemon): + assert isinstance(daemon, communicator.OnionrCommunicatorDaemon) + core = daemon._core + utils = core._utils + + # Find socket connection blocks + con_blocks = core.getBlocksByType('con') + for b in con_blocks: + if not b in daemon.active_services: + bl = onionrblockapi.Block(b, core=core, decrypt=True) + bs = utils.bytesToStr(bl.bcontent) + '.onion' + if utils.validatePubKey(bl.signer) and utils.validateID(bs): + daemon.active_services.append(b) + daemon.services.create_server(bl.signer, bs) + + daemon.decrementThreadCount('service_creator') \ No newline at end of file diff --git a/onionr/onionrservices/__init__.py b/onionr/onionrservices/__init__.py index 7194ea22..3f0e81e5 100644 --- a/onionr/onionrservices/__init__.py +++ b/onionr/onionrservices/__init__.py @@ -17,9 +17,8 @@ class OnionrServices: BOOTSTRAP_TRIES = 10 TRY_WAIT = 3 for x in range(BOOTSTRAP_TRIES): - if self._core._utils.doGetRequest('http://' + address + '/ping') == 'pong!': + if self._core._utils.doGetRequest('http://' + address + '/ping', port=self._core.config.get('tor.socksport')) == 'pong!': connectionserver.ConnectionServer(peer, address, core_inst=self._core) - return True else: time.sleep(TRY_WAIT) else: diff --git a/onionr/onionrservices/bootstrapservice.py b/onionr/onionrservices/bootstrapservice.py index 5dafe0f3..33c4e8b4 100644 --- a/onionr/onionrservices/bootstrapservice.py +++ b/onionr/onionrservices/bootstrapservice.py @@ -55,8 +55,7 @@ def bootstrap_client_service(peer, core_inst=None, bootstrap_timeout=300): controller.authenticate(core_inst.config.get('tor.controlpassword')) # Create the v3 onion service #response = controller.create_ephemeral_hidden_service({80: bootstrap_port}, await_publication = True, key_content = 'ED25519-V3') - response = controller.create_ephemeral_hidden_service(80, key_type = 'NEW', await_publication = True) - + response = controller.create_ephemeral_hidden_service({80: bootstrap_port}, key_type = 'NEW', await_publication = True) core_inst.insertBlock(response.service_id, header='con', sign=True, encryptType='asym', asymPeer=peer, disableForward=True, expire=(core_inst._utils.getEpoch() + bootstrap_timeout)) diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 86261502..2b9d47df 100755 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -4,7 +4,7 @@ "display_header" : false, "minimum_block_pow": 4, "minimum_send_pow": 4, - "socket_servers": false, + "socket_servers": true, "security_level": 0, "max_block_age": 2678400, "bypass_tor_check": false,