Onionr/onionr/onionrservices/__init__.py

31 lines
1005 B
Python
Raw Normal View History

2019-03-19 05:09:53 +00:00
import time
import stem
import core
2019-03-19 05:09:53 +00:00
from . import connectionserver, bootstrapservice
class OnionrServices:
def __init__(self, onionr_core):
assert isinstance(onionr_core, core.Core)
self._core = onionr_core
self.servers = {}
self.clients = {}
2019-03-19 05:09:53 +00:00
self.shutdown = False
return
2019-03-19 05:09:53 +00:00
def create_server(self, peer, address):
assert self._core._utils.validateID(address)
BOOTSTRAP_TRIES = 10
TRY_WAIT = 3
for x in range(BOOTSTRAP_TRIES):
if self._core._utils.doGetRequest('http://' + address + '/ping') == 'pong!':
connectionserver.ConnectionServer(peer, address, core_inst=self._core)
return True
else:
time.sleep(TRY_WAIT)
else:
return False
def create_client(self, peer):
# Create ephemeral onion service to bootstrap connection
address = bootstrapservice.bootstrap_client_service(peer)
return address