Merge branch 'check_connection_bypass_dns' of https://github.com/mirgee/lbry into mirgee-check_connection_bypass_dns

This commit is contained in:
Jack Robison 2017-10-31 11:53:35 -04:00
commit 3fd542f702
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
2 changed files with 20 additions and 4 deletions

View file

@ -119,6 +119,7 @@ at anytime.
### Fixed ### Fixed
* Fixed `transaction_list` doc string * Fixed `transaction_list` doc string
* Fixed ([in lbryum](https://github.com/lbryio/lbryum/pull/156)) batched queries responsible for making transaction and tip histories slow * Fixed ([in lbryum](https://github.com/lbryio/lbryum/pull/156)) batched queries responsible for making transaction and tip histories slow
* Fixed daemon refusing to start if DNS cannot resolve lbry.io domain.
### Changed ### Changed
* Bumped `lbryum` requirement to 3.1.8 [see changelog](https://github.com/lbryio/lbryum/blob/master/CHANGELOG.md#318---2017-09-20) * Bumped `lbryum` requirement to 3.1.8 [see changelog](https://github.com/lbryio/lbryum/blob/master/CHANGELOG.md#318---2017-09-20)

View file

@ -94,14 +94,29 @@ def obfuscate(plain):
return base64.b64encode(plain).encode('rot13') return base64.b64encode(plain).encode('rot13')
def check_connection(server="lbry.io", port=80): def check_connection(server="lbry.io", port=80, timeout=2, bypass_dns=False):
"""Attempts to open a socket to server:port and returns True if successful.""" """Attempts to open a socket to server:port and returns True if successful."""
log.debug('Checking connection to %s:%s', server, port)
try: try:
log.debug('Checking connection to %s:%s', server, port) if not bypass_dns:
host = socket.gethostbyname(server) server = socket.gethostbyname(server)
s = socket.create_connection((host, port), 2) socket.create_connection((server, port), timeout)
log.debug('Connection successful') log.debug('Connection successful')
return True return True
except (socket.gaierror, socket.herror) as ex:
log.info("Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
server, port, exc_info=True)
try:
server = "8.8.8.8"
port = 53
socket.create_connection((server, port), timeout)
log.debug('Connection successful')
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
except Exception as ex: except Exception as ex:
log.info( log.info(
"Failed to connect to %s:%s. Maybe the internet connection is not working", "Failed to connect to %s:%s. Maybe the internet connection is not working",