Preserve peer and port properly

This commit is contained in:
Brian Hill 2018-03-21 16:51:46 -04:00 committed by Brian May
parent 8bfc03b256
commit 9715a1d6f2

View File

@ -168,11 +168,13 @@ class DnsProxy(Handler):
self.tries = 0 self.tries = 0
self.request = request self.request = request
self.peers = {} self.peers = {}
self.to_ns_peer = None
self.to_ns_port = None
if to_nameserver is None: if to_nameserver is None:
self.to_nameserver = None self.to_nameserver = None
else: else:
peer, port = to_nameserver.split("@") self.to_ns_peer, self.to_ns_port = to_nameserver.split("@")
self.to_nameserver = self._addrinfo(peer, port) self.to_nameserver = self._addrinfo(self.to_ns_peer, self.to_ns_port)
self.try_send() self.try_send()
@staticmethod @staticmethod
@ -190,12 +192,11 @@ class DnsProxy(Handler):
if self.to_nameserver is None: if self.to_nameserver is None:
_, peer = resolvconf_random_nameserver() _, peer = resolvconf_random_nameserver()
port = 53 port = 53
family, sockaddr = self._addrinfo(peer, port)
else: else:
_, peer = self.to_nameserver peer = self.to_ns_peer
port = 53 port = int(self.to_ns_port)
family, sockaddr = self.to_nameserver
family, sockaddr = self._addrinfo(peer, port)
sock = socket.socket(family, socket.SOCK_DGRAM) sock = socket.socket(family, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42) sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
sock.connect(sockaddr) sock.connect(sockaddr)