forked from LBRYCommunity/lbry-sdk
Merge branch 'mirgee-check_connection_bypass_dns'
This commit is contained in:
commit
b9e03a7f13
2 changed files with 20 additions and 7 deletions
|
@ -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)
|
||||||
|
|
|
@ -94,18 +94,30 @@ 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):
|
||||||
"""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."""
|
||||||
try:
|
|
||||||
log.debug('Checking connection to %s:%s', server, port)
|
log.debug('Checking connection to %s:%s', server, port)
|
||||||
host = socket.gethostbyname(server)
|
try:
|
||||||
s = socket.create_connection((host, port), 2)
|
server = socket.gethostbyname(server)
|
||||||
|
socket.create_connection((server, port), timeout)
|
||||||
|
log.debug('Connection successful')
|
||||||
|
return True
|
||||||
|
except (socket.gaierror, socket.herror) as ex:
|
||||||
|
log.warning("Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
|
||||||
|
server, port)
|
||||||
|
try:
|
||||||
|
server = "8.8.8.8"
|
||||||
|
port = 53
|
||||||
|
socket.create_connection((server, port), timeout)
|
||||||
log.debug('Connection successful')
|
log.debug('Connection successful')
|
||||||
return True
|
return True
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.info(
|
log.error("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",
|
server, port)
|
||||||
server, port, exc_info=True)
|
return False
|
||||||
|
except Exception as ex:
|
||||||
|
log.error("Failed to connect to %s:%s. Maybe the internet connection is not working",
|
||||||
|
server, port)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue