def register_service(self, info, ttl=_DNS_TTL, allow_name_change=False):
"""Registers service information to the network with a default TTL
of 60 seconds. Zeroconf will then respond to requests for
information for that service. The name of the service may be
changed if needed to make it unique on the network."""
self.check_service(info, allow_name_change)
self.services[info.name.lower()] = info
if info.type in self.servicetypes:
self.servicetypes[info.type] += 1
else:
self.servicetypes[info.type] = 1
now = current_time_millis()
next_time = now
i = 0
while i < 3:
if now < next_time:
self.wait(next_time - now)
now = current_time_millis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.add_answer_at_time(
DNSPointer(info.type, _TYPE_PTR, _CLASS_IN, ttl, info.name), 0)
out.add_answer_at_time(
DNSService(info.name, _TYPE_SRV, _CLASS_IN,
ttl, info.priority, info.weight, info.port,
info.server), 0)
out.add_answer_at_time(
DNSText(info.name, _TYPE_TXT, _CLASS_IN, ttl, info.text), 0)
if info.address:
out.add_answer_at_time(
DNSAddress(info.server, _TYPE_A, _CLASS_IN,
ttl, info.address), 0)
self.send(out)
i += 1
next_time += _REGISTER_TIME
评论列表
文章目录