zeroconf_bonjour: switch from DNSServiceQueryRecord to DNSServiceGetAddrInfo for IPv6 compatibility
This commit is contained in:
parent
ff9afe194e
commit
da04f7fe39
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import select
|
import select
|
||||||
import socket
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
|
@ -157,16 +156,16 @@ class Zeroconf:
|
||||||
|
|
||||||
self.queried.append(True)
|
self.queried.append(True)
|
||||||
|
|
||||||
def query_record_callback(self, sdRef, flags, interfaceIndex, errorCode,
|
def getaddrinfo_callback(self, sdRef, flags, interfaceIndex, errorCode,
|
||||||
hosttarget, rrtype, rrclass, rdata, ttl):
|
hosttarget, address, ttl):
|
||||||
if errorCode != pybonjour.kDNSServiceErr_NoError:
|
if errorCode != pybonjour.kDNSServiceErr_NoError:
|
||||||
log.error('Error in query_record_callback: %s', str(errorCode))
|
log.error('Error in getaddrinfo_callback: %s', str(errorCode))
|
||||||
return
|
return
|
||||||
|
|
||||||
fullname, port, txtRecord = self.resolved_contacts[hosttarget]
|
fullname, port, txtRecord = self.resolved_contacts[hosttarget]
|
||||||
|
|
||||||
txt = pybonjour.TXTRecord.parse(txtRecord)
|
txt = pybonjour.TXTRecord.parse(txtRecord)
|
||||||
ip = socket.inet_ntoa(rdata)
|
ip = address[1]
|
||||||
|
|
||||||
name, bare_name, protocol, domain = self._parse_name(fullname)
|
name, bare_name, protocol, domain = self._parse_name(fullname)
|
||||||
|
|
||||||
|
@ -207,20 +206,18 @@ class Zeroconf:
|
||||||
self.resolved_contacts[hosttarget] = (fullname, port, txtRecord)
|
self.resolved_contacts[hosttarget] = (fullname, port, txtRecord)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query_sdRef = None
|
getaddrinfo_sdRef = \
|
||||||
query_sdRef = \
|
pybonjour.DNSServiceGetAddrInfo(
|
||||||
pybonjour.DNSServiceQueryRecord(
|
|
||||||
interfaceIndex=interfaceIndex,
|
interfaceIndex=interfaceIndex,
|
||||||
fullname=hosttarget,
|
hostname=hosttarget,
|
||||||
rrtype=pybonjour.kDNSServiceType_A,
|
callBack=self.getaddrinfo_callback)
|
||||||
callBack=self.query_record_callback)
|
|
||||||
|
|
||||||
while not self.queried:
|
while not self.queried:
|
||||||
ready = select.select([query_sdRef], [], [], resolve_timeout)
|
ready = select.select([getaddrinfo_sdRef], [], [], resolve_timeout)
|
||||||
if query_sdRef not in ready[0]:
|
if getaddrinfo_sdRef not in ready[0]:
|
||||||
log.warning('Query record timed out')
|
log.warning('GetAddrInfo timed out')
|
||||||
break
|
break
|
||||||
pybonjour.DNSServiceProcessResult(query_sdRef)
|
pybonjour.DNSServiceProcessResult(getaddrinfo_sdRef)
|
||||||
else:
|
else:
|
||||||
self.queried.pop()
|
self.queried.pop()
|
||||||
|
|
||||||
|
@ -231,8 +228,8 @@ class Zeroconf:
|
||||||
self.error_CB(_('Error while adding service. %s') % error)
|
self.error_CB(_('Error while adding service. %s') % error)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if query_sdRef:
|
if getaddrinfo_sdRef:
|
||||||
query_sdRef.close()
|
getaddrinfo_sdRef.close()
|
||||||
|
|
||||||
self.resolved.append(True)
|
self.resolved.append(True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue