Detect onion services in protocol in the same way as everythere

This commit is contained in:
Lee Miller 2022-08-30 15:27:54 +03:00
parent 72fc95b806
commit 99be6bbf73
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -101,7 +101,7 @@ MAX_VALID_STREAM = 2**63 - 1
def encodeHost(host): def encodeHost(host):
"""Encode a given host to be used in low-level socket operations""" """Encode a given host to be used in low-level socket operations"""
if host.find('.onion') > -1: if host.endswith('.onion'):
return b'\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode( return b'\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
host.split(".")[0], True) host.split(".")[0], True)
elif host.find(':') == -1: elif host.find(':') == -1:
@ -112,7 +112,7 @@ def encodeHost(host):
def networkType(host): def networkType(host):
"""Determine if a host is IPv4, IPv6 or an onion address""" """Determine if a host is IPv4, IPv6 or an onion address"""
if host.find('.onion') > -1: if host.endswith('.onion'):
return 'onion' return 'onion'
elif host.find(':') == -1: elif host.find(':') == -1:
return 'IPv4' return 'IPv4'