def check_service(self, info, allow_name_change):
"""Checks the network for a unique service name, modifying the
ServiceInfo passed in if it is not unique."""
# This is kind of funky because of the subtype based tests
# need to make subtypes a first class citizen
service_name = service_type_name(info.name)
if not info.type.endswith(service_name):
raise BadTypeInNameException
instance_name = info.name[:-len(service_name) - 1]
next_instance_number = 2
now = current_time_millis()
next_time = now
i = 0
while i < 3:
# check for a name conflict
while self.cache.current_entry_with_name_and_alias(
info.type, info.name):
if not allow_name_change:
raise NonUniqueNameException
# change the name and look for a conflict
info.name = '%s-%s.%s' % (
instance_name, next_instance_number, info.type)
next_instance_number += 1
service_type_name(info.name)
next_time = now
i = 0
if now < next_time:
self.wait(next_time - now)
now = current_time_millis()
continue
out = DNSOutgoing(_FLAGS_QR_QUERY | _FLAGS_AA)
self.debug = out
out.add_question(DNSQuestion(info.type, _TYPE_PTR, _CLASS_IN))
out.add_authorative_answer(DNSPointer(
info.type, _TYPE_PTR, _CLASS_IN, _DNS_TTL, info.name))
self.send(out)
i += 1
next_time += _CHECK_TIME
评论列表
文章目录