2019-05-12 14:21:17 +00:00
|
|
|
'''
|
|
|
|
Onionr - P2P Anonymous Storage Network
|
|
|
|
|
|
|
|
Onionr services provide the server component to direct connections
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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/>.
|
|
|
|
'''
|
2019-03-19 05:09:53 +00:00
|
|
|
import time
|
2019-03-18 05:22:31 +00:00
|
|
|
import stem
|
|
|
|
import core
|
2019-03-19 05:09:53 +00:00
|
|
|
from . import connectionserver, bootstrapservice
|
2019-03-23 02:58:09 +00:00
|
|
|
|
2019-03-18 05:22:31 +00:00
|
|
|
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
|
2019-03-18 05:22:31 +00:00
|
|
|
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
|
2019-03-25 03:32:17 +00:00
|
|
|
base_url = 'http://%s/' % (address,)
|
|
|
|
socks = self._core.config.get('tor.socksport')
|
2019-03-19 05:09:53 +00:00
|
|
|
for x in range(BOOTSTRAP_TRIES):
|
2019-03-25 03:32:17 +00:00
|
|
|
if self._core._utils.doGetRequest(base_url + 'ping', port=socks, ignoreAPI=True) == 'pong!':
|
2019-03-19 05:09:53 +00:00
|
|
|
connectionserver.ConnectionServer(peer, address, core_inst=self._core)
|
|
|
|
else:
|
|
|
|
time.sleep(TRY_WAIT)
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-03-18 05:22:31 +00:00
|
|
|
def create_client(self, peer):
|
|
|
|
# Create ephemeral onion service to bootstrap connection
|
|
|
|
address = bootstrapservice.bootstrap_client_service(peer)
|
|
|
|
return address
|