bug fixes for direct connnections

This commit is contained in:
Kevin Froman 2019-03-25 18:46:25 -05:00
parent dfbb0a512c
commit d3f57fe3e7
4 changed files with 23 additions and 22 deletions

View File

@ -39,7 +39,7 @@ class FDSafeHandler(WSGIHandler):
except Timeout as ex: except Timeout as ex:
raise raise
def setBindIP(filePath, writeOut=True): def setBindIP(filePath=''):
'''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)''' '''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)'''
if config.get('general.random_bind_ip', True): if config.get('general.random_bind_ip', True):
hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))] hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))]
@ -55,7 +55,7 @@ def setBindIP(filePath, writeOut=True):
s.close() s.close()
else: else:
data = '127.0.0.1' data = '127.0.0.1'
if writeOut: if filePath != '':
with open(filePath, 'w') as bindFile: with open(filePath, 'w') as bindFile:
bindFile.write(data) bindFile.write(data)
return data return data

View File

@ -111,7 +111,7 @@ class OnionrCommunicatorDaemon:
if config.get('general.socket_servers', False): if config.get('general.socket_servers', False):
self.services = onionrservices.OnionrServices(self._core) self.services = onionrservices.OnionrServices(self._core)
self.active_services = [] self.active_services = []
OnionrCommunicatorTimers(self, servicecreator.service_creator, 5, maxThreads=10, myArgs=(self,)) OnionrCommunicatorTimers(self, servicecreator.service_creator, 5, maxThreads=50, myArgs=(self,))
else: else:
self.services = None self.services = None
deniableBlockTimer = OnionrCommunicatorTimers(self, self.daemonTools.insertDeniableBlock, 180, requiresPeer=True, maxThreads=1) deniableBlockTimer = OnionrCommunicatorTimers(self, self.daemonTools.insertDeniableBlock, 180, requiresPeer=True, maxThreads=1)

View File

@ -17,10 +17,10 @@
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 time import time, threading, uuid
from gevent.pywsgi import WSGIServer, WSGIHandler from gevent.pywsgi import WSGIServer, WSGIHandler
from stem.control import Controller from stem.control import Controller
from flask import Flask from flask import Flask, Response
import core import core
from netcontroller import getOpenPort from netcontroller import getOpenPort
@ -40,6 +40,7 @@ def bootstrap_client_service(peer, core_inst=None, bootstrap_timeout=300):
bootstrap_address = '' bootstrap_address = ''
shutdown = False shutdown = False
bs_id = str(uuid.uuid4())
@bootstrap_app.route('/ping') @bootstrap_app.route('/ping')
def get_ping(): def get_ping():
@ -47,25 +48,28 @@ def bootstrap_client_service(peer, core_inst=None, bootstrap_timeout=300):
@bootstrap_app.route('/bs/<address>', methods=['POST']) @bootstrap_app.route('/bs/<address>', methods=['POST'])
def get_bootstrap(address): def get_bootstrap(address):
if core_inst._utils.validateID(address): if core_inst._utils.validateID(address + '.onion'):
# Set the bootstrap address then close the server # Set the bootstrap address then close the server
bootstrap_address = address bootstrap_address = address + '.onion'
shutdown = True core_inst.keyStore.put(bs_id, bootstrap_address)
return "success" http_server.stop()
return Response("success")
else:
return Response("")
with Controller.from_port(port=core_inst.config.get('tor.controlPort')) as controller: with Controller.from_port(port=core_inst.config.get('tor.controlPort')) as controller:
# Connect to the Tor process for Onionr # Connect to the Tor process for Onionr
controller.authenticate(core_inst.config.get('tor.controlpassword')) controller.authenticate(core_inst.config.get('tor.controlpassword'))
# Create the v3 onion service # Create the v3 onion service
response = controller.create_ephemeral_hidden_service({80: bootstrap_port}, key_type = 'NEW', await_publication = True) 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', core_inst.insertBlock(response.service_id, header='con', sign=True, encryptType='asym',
asymPeer=peer, disableForward=True, expire=(core_inst._utils.getEpoch() + bootstrap_timeout)) asymPeer=peer, disableForward=True, expire=(core_inst._utils.getEpoch() + bootstrap_timeout))
# Run the bootstrap server # Run the bootstrap server
threading.Thread(target=http_server.serve_forever).start() try:
http_server.serve_forever()
except TypeError:
pass
# This line reached when server is shutdown by being bootstrapped # This line reached when server is shutdown by being bootstrapped
while not shutdown and not core_inst.killSockets:
time.sleep(1)
# Now that the bootstrap server has received a server, return the address # Now that the bootstrap server has received a server, return the address
return bootstrap_address return core_inst.keyStore.get(bs_id)

View File

@ -23,7 +23,7 @@ from stem.control import Controller
from flask import Flask from flask import Flask
import core, logger import core, logger
from netcontroller import getOpenPort from netcontroller import getOpenPort
from api import setBindIP import api
class ConnectionServer: class ConnectionServer:
def __init__(self, peer, address, core_inst=None): def __init__(self, peer, address, core_inst=None):
@ -38,9 +38,8 @@ class ConnectionServer:
socks = core_inst.config.get('tor.socksport') # Load config for Tor socks port for proxy socks = core_inst.config.get('tor.socksport') # Load config for Tor socks port for proxy
service_app = Flask(__name__) # Setup Flask app for server. service_app = Flask(__name__) # Setup Flask app for server.
service_port = getOpenPort() service_port = getOpenPort()
service_ip = setBindIP() service_ip = api.setBindIP()
http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None) http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None)
# TODO define basic endpoints useful for direct connections like stats # TODO define basic endpoints useful for direct connections like stats
# TODO load endpoints from plugins # TODO load endpoints from plugins
@ -52,10 +51,8 @@ class ConnectionServer:
# Connect to the Tor process for Onionr # Connect to the Tor process for Onionr
controller.authenticate(core_inst.config.get('tor.controlpassword')) controller.authenticate(core_inst.config.get('tor.controlpassword'))
# Create the v3 onion service # Create the v3 onion service
response = controller.create_ephemeral_hidden_service({80: service_port}, await_publication = True, key_type='NEW') response = controller.create_ephemeral_hidden_service({80: service_port}, await_publication = True, key_type='NEW', key_content = 'ED25519-V3')
self.core_inst._utils.doPostRequest('http://' + address + '/bs/' + response.service_id, port=socks) self.core_inst._utils.doPostRequest('http://' + address + '/bs/' + response.service_id, port=socks)
logger.info('hosting on ' + response.service_id) logger.info('hosting on ' + response.service_id)
threading.Thread(target=http_server.serve_forever).start() http_server.serve_forever()
while not self.core_inst.killSockets:
time.sleep(1)
http_server.stop() http_server.stop()