use lbry.io to check for an internet connection
This commit is contained in:
parent
640db41555
commit
6b7d575e95
5 changed files with 31 additions and 39 deletions
|
@ -1,16 +1,22 @@
|
|||
import base64
|
||||
import datetime
|
||||
import distutils.version
|
||||
import logging
|
||||
import json
|
||||
import random
|
||||
import os
|
||||
import json
|
||||
import socket
|
||||
import yaml
|
||||
import datetime
|
||||
|
||||
from lbrynet.core.cryptoutils import get_lbry_hash_obj
|
||||
|
||||
|
||||
blobhash_length = get_lbry_hash_obj().digest_size * 2 # digest_size is in bytes, and blob hashes are hex encoded
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def generate_id(num=None):
|
||||
h = get_lbry_hash_obj()
|
||||
if num is not None:
|
||||
|
@ -82,3 +88,16 @@ def save_settings(path, settings):
|
|||
|
||||
def today():
|
||||
return datetime.datetime.today()
|
||||
|
||||
|
||||
def check_connection(server="www.lbry.io", port=80):
|
||||
"""Attempts to open a socket to server:port and returns True if successful."""
|
||||
try:
|
||||
host = socket.gethostbyname(server)
|
||||
s = socket.create_connection((host, port), 2)
|
||||
return True
|
||||
except Exception as ex:
|
||||
log.info(
|
||||
"Failed to connect to %s:%s. Maybe the internet connection is not working",
|
||||
server, port, exc_info=True)
|
||||
return False
|
||||
|
|
|
@ -5,7 +5,6 @@ import os
|
|||
import platform
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -130,8 +129,6 @@ OK_CODE = 200
|
|||
# TODO alert if your copy of a lbry file is out of date with the name record
|
||||
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
|
||||
class Parameters(object):
|
||||
def __init__(self, **kwargs):
|
||||
|
@ -599,13 +596,7 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
self._events = analytics.Events(context, base58.b58encode(self.lbryid), self._session_id)
|
||||
|
||||
def _check_network_connection(self):
|
||||
try:
|
||||
host = socket.gethostbyname(REMOTE_SERVER)
|
||||
s = socket.create_connection((host, 80), 2)
|
||||
self.connected_to_internet = True
|
||||
except:
|
||||
log.info("Internet connection not working")
|
||||
self.connected_to_internet = False
|
||||
self.connected_to_internet = utils.check_connection()
|
||||
|
||||
def _check_lbrynet_connection(self):
|
||||
def _log_success():
|
||||
|
|
|
@ -4,7 +4,6 @@ import logging.handlers
|
|||
import os
|
||||
import webbrowser
|
||||
import sys
|
||||
import socket
|
||||
from appdirs import user_data_dir
|
||||
|
||||
from twisted.web import server
|
||||
|
@ -12,6 +11,7 @@ from twisted.internet import reactor, defer
|
|||
from jsonrpc.proxy import JSONRPCProxy
|
||||
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT, \
|
||||
|
@ -30,19 +30,12 @@ lbrynet_log = os.path.join(log_dir, LOG_FILE_NAME)
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||
|
||||
|
||||
def test_internet_connection():
|
||||
try:
|
||||
host = socket.gethostbyname(REMOTE_SERVER)
|
||||
s = socket.create_connection((host, 80), 2)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
return utils.check_connection()
|
||||
|
||||
|
||||
def stop():
|
||||
|
|
|
@ -31,22 +31,17 @@ from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
|||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
||||
from lbrynet.conf import UI_ADDRESS
|
||||
from lbrynet.core import utils
|
||||
|
||||
|
||||
if platform.mac_ver()[0] >= "10.10":
|
||||
from LBRYNotify import LBRYNotify
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
|
||||
def test_internet_connection():
|
||||
try:
|
||||
host = socket.gethostbyname(REMOTE_SERVER)
|
||||
s = socket.create_connection((host, 80), 2)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
return utils.check_connection()
|
||||
|
||||
|
||||
class LBRYDaemonApp(AppKit.NSApplication):
|
||||
|
|
|
@ -18,6 +18,7 @@ try:
|
|||
except ImportError:
|
||||
import win32gui
|
||||
|
||||
from lbrynet.core import utils
|
||||
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
||||
|
@ -36,16 +37,9 @@ log = logging.getLogger(__name__)
|
|||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||
|
||||
REMOTE_SERVER = "www.google.com"
|
||||
|
||||
|
||||
def test_internet_connection():
|
||||
try:
|
||||
host = socket.gethostbyname(REMOTE_SERVER)
|
||||
s = socket.create_connection((host, 80), 2)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
return utils.check_connection()
|
||||
|
||||
|
||||
def non_string_iterable(obj):
|
||||
|
|
Loading…
Reference in a new issue