correzioni per kodi su raspberry pi

This commit is contained in:
marco
2024-02-19 20:26:32 +01:00
parent bdc025b87d
commit 559ae1edd2
2 changed files with 22 additions and 17 deletions

View File

@@ -40,13 +40,28 @@ class CipherSuiteAdapter(HTTPAdapter):
self.ssl_ciphers = ssl_ciphers self.ssl_ciphers = ssl_ciphers
super(CipherSuiteAdapter, self).__init__(**kwargs) super(CipherSuiteAdapter, self).__init__(**kwargs)
if override_dns: if override_dns:
# hack[3/3] function that use doh for host name resolution
def override_dns_connection(address, *args, **kwargs):
"""Wrap urllib3's create_connection to resolve the name elsewhere"""
# resolve hostname to an ip address; use your own
# resolver here, as otherwise the system resolver will be used.
host, port = address
hostname = self.getIp(host)
if not hostname:
hostname = host #fallback
logger.debug("Override dns failed, fallback to normal dns resolver")
return connection.original_create_connection((hostname, port), *args, **kwargs)
# hack[2/3] patch urllib3 create connection with custom function # hack[2/3] patch urllib3 create connection with custom function
connection.create_connection = CipherSuiteAdapter.override_dns_connection connection.original_create_connection = connection.create_connection
connection.create_connection = override_dns_connection
def flushDns(domain, **kwargs): def flushDns(domain, **kwargs):
del db['dnscache'][domain] del db['dnscache'][domain]
def getIp(domain): def getIp(self, domain):
cache = db['dnscache'].get(domain, {}) cache = db['dnscache'].get(domain, {})
ip = None ip = None
if type(cache) != dict or (cache.get('datetime') and if type(cache) != dict or (cache.get('datetime') and
@@ -60,7 +75,7 @@ class CipherSuiteAdapter(HTTPAdapter):
# IPv6 address # IPv6 address
if ':' in ip: if ':' in ip:
ip = '[' + ip + ']' ip = '[' + ip + ']'
CipherSuiteAdapter.writeToCache(domain, ip) self.writeToCache(domain, ip)
except Exception: except Exception:
logger.error('Failed to resolve hostname, fallback to normal dns') logger.error('Failed to resolve hostname, fallback to normal dns')
import traceback import traceback
@@ -70,7 +85,7 @@ class CipherSuiteAdapter(HTTPAdapter):
logger.info('Cache DNS: ' + domain + ' = ' + str(ip)) logger.info('Cache DNS: ' + domain + ' = ' + str(ip))
return ip return ip
def writeToCache(domain, ip): def writeToCache(self, domain, ip):
db['dnscache'][domain] = {'ip': ip, 'datetime': current_date} db['dnscache'][domain] = {'ip': ip, 'datetime': current_date}
def init_poolmanager(self, *pool_args, **pool_kwargs): def init_poolmanager(self, *pool_args, **pool_kwargs):
@@ -93,16 +108,6 @@ class CipherSuiteAdapter(HTTPAdapter):
logger.info('Flushing dns cache for ' + domain) logger.info('Flushing dns cache for ' + domain)
CipherSuiteAdapter.flushDns(domain, **kwargs) CipherSuiteAdapter.flushDns(domain, **kwargs)
return self.send(request, flushedDns=True, **kwargs) return self.send(request, flushedDns=True, **kwargs)
except Exception as e:
# hack[3/3] function that use doh for host name resolution logger.error(e)
def override_dns_connection(address, *args, **kwargs): raise e
"""Wrap urllib3's create_connection to resolve the name elsewhere"""
# resolve hostname to an ip address; use your own
# resolver here, as otherwise the system resolver will be used.
host, port = address
hostname = CipherSuiteAdapter.getIp(host)
if not hostname:
hostname = host #fallback
logger.debug("Override dns failed, fallback to normal dns resolver")
return CipherSuiteAdapter.original_create_connection((hostname, port), *args, **kwargs)

0
servers/streamingcommunityws.py Executable file → Normal file
View File