force ipv4 when resolving a url

-log violating ip addresses
This commit is contained in:
Jack Robison 2019-10-08 13:31:06 -04:00
parent 077281a77a
commit 5cd0828dd3
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 3 additions and 2 deletions

View file

@ -161,7 +161,7 @@ class KademliaPeer:
if self.tcp_port is not None and not 1 <= self.tcp_port <= 65535:
raise ValueError("invalid tcp port")
if not is_valid_ipv4(self.address):
raise ValueError("invalid ip address")
raise ValueError(f"invalid ip address: '{self.address}'")
def update_tcp_port(self, tcp_port: int):
self.tcp_port = tcp_port

View file

@ -192,7 +192,8 @@ async def resolve_host(url: str, port: int, proto: str) -> str:
return (await loop.getaddrinfo(
url, port,
proto=socket.IPPROTO_TCP if proto == 'tcp' else socket.IPPROTO_UDP,
type=socket.SOCK_STREAM if proto == 'tcp' else socket.SOCK_DGRAM
type=socket.SOCK_STREAM if proto == 'tcp' else socket.SOCK_DGRAM,
family=socket.AF_INET
))[0][4][0]