bumped stem version and started work on new dir conn system

This commit is contained in:
Kevin Froman 2019-03-18 00:22:31 -05:00
parent 7048db42bd
commit a87d1bf1e8
7 changed files with 99 additions and 16 deletions

View File

@ -17,12 +17,11 @@
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 subprocess, os, random, sys, time, signal, base64, socket
import subprocess, os, random, sys, logger, time, signal, config, base64, socket from shutil import which
from stem.control import Controller import logger, config
from onionrblockapi import Block from onionrblockapi import Block
from dependencies import secrets from dependencies import secrets
from shutil import which
def getOpenPort(): def getOpenPort():
# taken from (but modified) https://stackoverflow.com/a/2838309 # taken from (but modified) https://stackoverflow.com/a/2838309
@ -69,13 +68,6 @@ class NetController:
self.torBinary = 'tor' self.torBinary = 'tor'
config.reload() config.reload()
'''
if os.path.exists(self.torConfigLocation):
torrc = open(self.torConfigLocation, 'r')
if not str(self.hsPort) in torrc.read():
os.remove(self.torConfigLocation)
torrc.close()
'''
return return

View File

@ -0,0 +1,18 @@
import stem
import core
from . import connectionserver, connectionclient, bootstrapservice
class OnionrServices:
def __init__(self, onionr_core):
assert isinstance(onionr_core, core.Core)
self._core = onionr_core
self.servers = {}
self.clients = {}
return
def create_server(self):
return
def create_client(self, peer):
# Create ephemeral onion service to bootstrap connection
address = bootstrapservice.bootstrap_client_service(peer)
return address

View File

@ -0,0 +1,67 @@
'''
Onionr - P2P Anonymous Storage Network
Bootstrap onion direct connections for the clients
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
from gevent.pywsgi import WSGIServer, WSGIHandler
from stem.control import Controller
from flask import Flask
import core
from netcontroller import getOpenPort
def bootstrap_client_service(peer, core_inst=None):
'''
Bootstrap client services
'''
if core_inst is None:
core_inst = core.Core()
if not core_inst._utils.validatePubKey(peer):
raise ValueError('Peer must be valid base32 ed25519 public key')
http_server = WSGIServer(('127.0.0.1', bootstrap_port), bootstrap_app, log=None)
bootstrap_port = getOpenPort()
bootstrap_app = flask.Flask(__name__)
bootstrap_address = ''
@bootstrap_app.route('/ping')
def get_ping():
return "pong!"
@bootstrap_app.route('/bs/<address>', methods=['POST'])
def get_bootstrap(address):
if core_inst._utils.validateID(address):
# Set the bootstrap address then close the server
bootstrap_address = address
http_server.stop()
with Controller.from_port() as controller:
# Connect to the Tor process for Onionr
controller.authenticate()
# Create the v3 onion service
response = controller.create_ephemeral_hidden_service({80: bootstrap_port}, await_publication = True, key_type='ED25519-V3')
core_inst.insertBlock(response.hostname, header='con', sign=True, encryptType='asym',
asymPeer=peer, disableForward=True)
# Run the bootstrap server
http_server.serve_forever()
# This line reached when server is shutdown by being bootstrapped
# Now that the bootstrap server has received a server, return the address
return bootstrap_address

View File

@ -0,0 +1,4 @@
class ConnectionServer:
def __init__(self):
return

View File

@ -329,7 +329,8 @@ class OnionrUtils:
retVal = True retVal = True
return retVal return retVal
def validateID(self, id): @staticmethod
def validateID(id):
''' '''
Validate if an address is a valid tor or i2p hidden service Validate if an address is a valid tor or i2p hidden service
''' '''
@ -381,7 +382,8 @@ class OnionrUtils:
except: except:
return False return False
def isIntegerString(self, data): @staticmethod
def isIntegerString(data):
'''Check if a string is a valid base10 integer (also returns true if already an int)''' '''Check if a string is a valid base10 integer (also returns true if already an int)'''
try: try:
int(data) int(data)

View File

@ -5,5 +5,5 @@ gevent==1.3.6
defusedxml==0.5.0 defusedxml==0.5.0
Flask==1.0.2 Flask==1.0.2
PySocks==1.6.8 PySocks==1.6.8
stem==1.6.0 stem==1.7.1
deadsimplekv==0.0.1 deadsimplekv==0.0.1

View File

@ -185,8 +185,8 @@ six==1.12.0 \
--hash=sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c \ --hash=sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c \
--hash=sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73 \ --hash=sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73 \
# via pynacl # via pynacl
stem==1.6.0 \ stem==1.7.1 \
--hash=sha256:d7fe1fb13ed5a94d610b5ad77e9f1b3404db0ca0586ded7a34afd323e3b849ed --hash=sha256:c9eaf3116cb60c15995cbd3dec3a5cbc50e9bb6e062c4d6d42201e566f498ca2
urllib3==1.23 \ urllib3==1.23 \
--hash=sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf \ --hash=sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf \
--hash=sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5 --hash=sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5