2019-06-13 06:58:17 +00:00
|
|
|
'''
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
Determine if our node is able to use Tor based on the status of a communicator instance
|
|
|
|
and the result of pinging onion http servers
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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/>.
|
|
|
|
'''
|
|
|
|
import logger
|
|
|
|
from utils import netutils
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import localcommand, epoch
|
2019-06-13 06:58:17 +00:00
|
|
|
def net_check(comm_inst):
|
|
|
|
'''Check if we are connected to the internet or not when we can't connect to any peers'''
|
2019-06-14 07:05:58 +00:00
|
|
|
rec = False # for detecting if we have received incoming connections recently
|
2019-06-23 17:41:07 +00:00
|
|
|
c = comm_inst._core
|
2019-06-13 06:58:17 +00:00
|
|
|
if len(comm_inst.onlinePeers) == 0:
|
2019-06-14 07:05:58 +00:00
|
|
|
try:
|
2019-06-25 23:07:35 +00:00
|
|
|
if (epoch.get_epoch() - int(localcommand.local_command(c, '/lastconnect'))) <= 60:
|
2019-06-14 07:05:58 +00:00
|
|
|
comm_inst.isOnline = True
|
|
|
|
rec = True
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2019-06-23 17:41:07 +00:00
|
|
|
if not rec and not netutils.checkNetwork(c._utils, torPort=comm_inst.proxyPort):
|
2019-06-13 06:58:17 +00:00
|
|
|
if not comm_inst.shutdown:
|
|
|
|
logger.warn('Network check failed, are you connected to the Internet, and is Tor working?')
|
|
|
|
comm_inst.isOnline = False
|
|
|
|
else:
|
|
|
|
comm_inst.isOnline = True
|
|
|
|
comm_inst.decrementThreadCount('net_check')
|