Fix netutils formatting

This commit is contained in:
Kevin Froman 2020-08-12 17:29:53 -05:00
parent 272d7d7f74
commit c9af24392d
2 changed files with 23 additions and 20 deletions

View File

@ -46,7 +46,7 @@ def net_check(comm_inst):
rec = True rec = True
except ValueError: except ValueError:
pass pass
if not rec and not netutils.checkNetwork(torPort=comm_inst.proxyPort): if not rec and not netutils.check_network(torPort=comm_inst.proxyPort):
if not kv.get('shutdown'): if not kv.get('shutdown'):
if not comm_inst.config.get('general.offline_mode', False): if not comm_inst.config.get('general.offline_mode', False):
logger.warn('Network check failed, are you connected to ' + logger.warn('Network check failed, are you connected to ' +

View File

@ -1,9 +1,11 @@
''' """Onionr - Private P2P Communication.
Onionr - P2P Microblogging Platform & Social network
OnionrUtils offers various useful functions to Onionr networking. NetUtils offers various useful functions to Onionr networking.
''' """
''' from onionrutils import basicrequests
from .readstatic import read_static
from onionrcrypto.cryptoutils import random_shuffle
"""
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -16,21 +18,22 @@
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/>.
''' """
from onionrutils import basicrequests
from . import readstatic
from onionrcrypto import cryptoutils
def checkNetwork(torPort=0):
'''Check if we are connected to the internet (through Tor)'''
retData = False
connectURLs = []
try:
connectURLs = cryptoutils.random_shuffle(readstatic.read_static('connect-check.txt').split(','))
for url in connectURLs:
if basicrequests.do_get_request(url, port=torPort, ignoreAPI=True) != False: def check_network(torPort=0) -> bool:
retData = True """Check if we are connected to the internet (through Tor)."""
success = False
connect_urls = []
try:
connect_urls = random_shuffle(
read_static('connect-check.txt').split(','))
for url in connect_urls:
if basicrequests.do_get_request(
url, port=torPort, ignoreAPI=True) is not False:
success = True
break break
except FileNotFoundError: except FileNotFoundError:
pass pass
return retData return success