forked from LBRYCommunity/lbry-sdk
Merge branch 'check_connection_bypass_dns' of https://github.com/mirgee/lbry into mirgee-check_connection_bypass_dns
This commit is contained in:
commit
3fd542f702
2 changed files with 20 additions and 4 deletions
|
@ -119,6 +119,7 @@ at anytime.
|
|||
### Fixed
|
||||
* 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 daemon refusing to start if DNS cannot resolve lbry.io domain.
|
||||
|
||||
### Changed
|
||||
* Bumped `lbryum` requirement to 3.1.8 [see changelog](https://github.com/lbryio/lbryum/blob/master/CHANGELOG.md#318---2017-09-20)
|
||||
|
|
|
@ -94,14 +94,29 @@ def obfuscate(plain):
|
|||
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."""
|
||||
try:
|
||||
log.debug('Checking connection to %s:%s', server, port)
|
||||
host = socket.gethostbyname(server)
|
||||
s = socket.create_connection((host, port), 2)
|
||||
try:
|
||||
if not bypass_dns:
|
||||
server = socket.gethostbyname(server)
|
||||
socket.create_connection((server, port), timeout)
|
||||
log.debug('Connection successful')
|
||||
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:
|
||||
log.info(
|
||||
"Failed to connect to %s:%s. Maybe the internet connection is not working",
|
||||
|
|
Loading…
Reference in a new issue