Onionr/src/utils/gettransports.py

57 lines
1.6 KiB
Python
Raw Normal View History

2020-01-31 00:34:47 +00:00
"""Onionr - Private P2P Communication.
return a list of strings of the user's transport addresses for the main
Onionr protocol
"""
2019-12-22 19:42:10 +00:00
from gevent import time
import filepaths
2020-01-31 00:34:47 +00:00
"""
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-07-18 17:40:48 +00:00
2020-04-15 03:40:31 +00:00
files = []
2019-07-20 06:02:30 +00:00
2019-12-22 19:42:10 +00:00
2020-04-15 03:40:31 +00:00
class _GetTor:
def __init__(self):
self.tor_hs = None
def get(self):
if self.tor_hs is None:
try:
with open(filepaths.tor_hs_address_file, 'r') as transport_file:
self.tor_hs = transport_file.read().strip()
if not self.tor_hs:
self.tor_hs = None
except FileNotFoundError:
pass
return self.tor_hs
_tor_getter = _GetTor()
2019-07-20 06:02:30 +00:00
def get():
2020-04-15 03:40:31 +00:00
transports = [_tor_getter.get()]
2019-12-22 19:42:10 +00:00
for file in files:
try:
with open(file, 'r') as transport_file:
transports.append(transport_file.read().strip())
except FileNotFoundError:
pass
2019-07-24 16:32:23 +00:00
else:
2019-12-22 19:42:10 +00:00
break
else:
time.sleep(1)
return list(transports)