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 base64
|
||||||
|
import datetime
|
||||||
import distutils.version
|
import distutils.version
|
||||||
|
import logging
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
import json
|
import socket
|
||||||
import yaml
|
import yaml
|
||||||
import datetime
|
|
||||||
|
|
||||||
from lbrynet.core.cryptoutils import get_lbry_hash_obj
|
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
|
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):
|
def generate_id(num=None):
|
||||||
h = get_lbry_hash_obj()
|
h = get_lbry_hash_obj()
|
||||||
if num is not None:
|
if num is not None:
|
||||||
|
@ -82,3 +88,16 @@ def save_settings(path, settings):
|
||||||
|
|
||||||
def today():
|
def today():
|
||||||
return datetime.datetime.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 platform
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import socket
|
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
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
|
# 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):
|
class Parameters(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
@ -599,13 +596,7 @@ class Daemon(jsonrpc.JSONRPC):
|
||||||
self._events = analytics.Events(context, base58.b58encode(self.lbryid), self._session_id)
|
self._events = analytics.Events(context, base58.b58encode(self.lbryid), self._session_id)
|
||||||
|
|
||||||
def _check_network_connection(self):
|
def _check_network_connection(self):
|
||||||
try:
|
self.connected_to_internet = utils.check_connection()
|
||||||
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
|
|
||||||
|
|
||||||
def _check_lbrynet_connection(self):
|
def _check_lbrynet_connection(self):
|
||||||
def _log_success():
|
def _log_success():
|
||||||
|
|
|
@ -4,7 +4,6 @@ import logging.handlers
|
||||||
import os
|
import os
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import sys
|
import sys
|
||||||
import socket
|
|
||||||
from appdirs import user_data_dir
|
from appdirs import user_data_dir
|
||||||
|
|
||||||
from twisted.web import server
|
from twisted.web import server
|
||||||
|
@ -12,6 +11,7 @@ from twisted.internet import reactor, defer
|
||||||
from jsonrpc.proxy import JSONRPCProxy
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
|
|
||||||
from lbrynet.core import log_support
|
from lbrynet.core import log_support
|
||||||
|
from lbrynet.core import utils
|
||||||
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||||
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_PORT, \
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
REMOTE_SERVER = "www.google.com"
|
|
||||||
|
|
||||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||||
|
|
||||||
|
|
||||||
def test_internet_connection():
|
def test_internet_connection():
|
||||||
try:
|
return utils.check_connection()
|
||||||
host = socket.gethostbyname(REMOTE_SERVER)
|
|
||||||
s = socket.create_connection((host, 80), 2)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
|
|
|
@ -31,22 +31,17 @@ from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||||
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
||||||
from lbrynet.conf import UI_ADDRESS
|
from lbrynet.conf import UI_ADDRESS
|
||||||
|
from lbrynet.core import utils
|
||||||
|
|
||||||
|
|
||||||
if platform.mac_ver()[0] >= "10.10":
|
if platform.mac_ver()[0] >= "10.10":
|
||||||
from LBRYNotify import LBRYNotify
|
from LBRYNotify import LBRYNotify
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
REMOTE_SERVER = "www.google.com"
|
|
||||||
|
|
||||||
|
|
||||||
def test_internet_connection():
|
def test_internet_connection():
|
||||||
try:
|
return utils.check_connection()
|
||||||
host = socket.gethostbyname(REMOTE_SERVER)
|
|
||||||
s = socket.create_connection((host, 80), 2)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class LBRYDaemonApp(AppKit.NSApplication):
|
class LBRYDaemonApp(AppKit.NSApplication):
|
||||||
|
|
|
@ -18,6 +18,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import win32gui
|
import win32gui
|
||||||
|
|
||||||
|
from lbrynet.core import utils
|
||||||
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
from lbrynet.lbrynet_daemon.DaemonServer import DaemonServer
|
||||||
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
from lbrynet.lbrynet_daemon.DaemonRequest import DaemonRequest
|
||||||
from lbrynet.conf import API_PORT, API_INTERFACE, ICON_PATH, APP_NAME
|
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":
|
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||||
|
|
||||||
REMOTE_SERVER = "www.google.com"
|
|
||||||
|
|
||||||
|
|
||||||
def test_internet_connection():
|
def test_internet_connection():
|
||||||
try:
|
return utils.check_connection()
|
||||||
host = socket.gethostbyname(REMOTE_SERVER)
|
|
||||||
s = socket.create_connection((host, 80), 2)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def non_string_iterable(obj):
|
def non_string_iterable(obj):
|
||||||
|
|
Loading…
Reference in a new issue