Show More
@@ -477,10 +477,10 b' class DNSIncoming(object):' | |||
|
477 | 477 | self.data = data |
|
478 | 478 | self.questions = [] |
|
479 | 479 | self.answers = [] |
|
480 |
self.num |
|
|
481 |
self.num |
|
|
482 |
self.num |
|
|
483 |
self.num |
|
|
480 | self.numquestions = 0 | |
|
481 | self.numanswers = 0 | |
|
482 | self.numauthorities = 0 | |
|
483 | self.numadditionals = 0 | |
|
484 | 484 | |
|
485 | 485 | self.readHeader() |
|
486 | 486 | self.readQuestions() |
@@ -496,16 +496,16 b' class DNSIncoming(object):' | |||
|
496 | 496 | |
|
497 | 497 | self.id = info[0] |
|
498 | 498 | self.flags = info[1] |
|
499 |
self.num |
|
|
500 |
self.num |
|
|
501 |
self.num |
|
|
502 |
self.num |
|
|
499 | self.numquestions = info[2] | |
|
500 | self.numanswers = info[3] | |
|
501 | self.numauthorities = info[4] | |
|
502 | self.numadditionals = info[5] | |
|
503 | 503 | |
|
504 | 504 | def readQuestions(self): |
|
505 | 505 | """Reads questions section of packet""" |
|
506 | 506 | format = '!HH' |
|
507 | 507 | length = struct.calcsize(format) |
|
508 |
for i in range(0, self.num |
|
|
508 | for i in range(0, self.numquestions): | |
|
509 | 509 | name = self.readName() |
|
510 | 510 | info = struct.unpack(format, |
|
511 | 511 | self.data[self.offset:self.offset + length]) |
@@ -554,7 +554,7 b' class DNSIncoming(object):' | |||
|
554 | 554 | """Reads answers, authorities and additionals section of the packet""" |
|
555 | 555 | format = '!HHiH' |
|
556 | 556 | length = struct.calcsize(format) |
|
557 |
n = self.num |
|
|
557 | n = self.numanswers + self.numAuthorities + self.numadditionals | |
|
558 | 558 | for i in range(0, n): |
|
559 | 559 | domain = self.readName() |
|
560 | 560 | info = struct.unpack(format, |
@@ -990,7 +990,7 b' class ServiceBrowser(threading.Thread):' | |||
|
990 | 990 | self.type = type |
|
991 | 991 | self.listener = listener |
|
992 | 992 | self.services = {} |
|
993 |
self.next |
|
|
993 | self.nexttime = currentTimeMillis() | |
|
994 | 994 | self.delay = _BROWSER_TIME |
|
995 | 995 | self.list = [] |
|
996 | 996 | |
@@ -1024,8 +1024,8 b' class ServiceBrowser(threading.Thread):' | |||
|
1024 | 1024 | self.list.append(callback) |
|
1025 | 1025 | |
|
1026 | 1026 | expires = record.getExpirationTime(75) |
|
1027 |
if expires < self.next |
|
|
1028 |
self.next |
|
|
1027 | if expires < self.nexttime: | |
|
1028 | self.nexttime = expires | |
|
1029 | 1029 | |
|
1030 | 1030 | def cancel(self): |
|
1031 | 1031 | self.done = 1 |
@@ -1035,20 +1035,20 b' class ServiceBrowser(threading.Thread):' | |||
|
1035 | 1035 | while True: |
|
1036 | 1036 | event = None |
|
1037 | 1037 | now = currentTimeMillis() |
|
1038 |
if len(self.list) == 0 and self.next |
|
|
1039 |
self.zeroconf.wait(self.next |
|
|
1038 | if len(self.list) == 0 and self.nexttime > now: | |
|
1039 | self.zeroconf.wait(self.nexttime - now) | |
|
1040 | 1040 | if globals()['_GLOBAL_DONE'] or self.done: |
|
1041 | 1041 | return |
|
1042 | 1042 | now = currentTimeMillis() |
|
1043 | 1043 | |
|
1044 |
if self.next |
|
|
1044 | if self.nexttime <= now: | |
|
1045 | 1045 | out = DNSOutgoing(_FLAGS_QR_QUERY) |
|
1046 | 1046 | out.addQuestion(DNSQuestion(self.type, _TYPE_PTR, _CLASS_IN)) |
|
1047 | 1047 | for record in self.services.values(): |
|
1048 | 1048 | if not record.isExpired(now): |
|
1049 | 1049 | out.addAnswerAtTime(record, now) |
|
1050 | 1050 | self.zeroconf.send(out) |
|
1051 |
self.next |
|
|
1051 | self.nexttime = now + self.delay | |
|
1052 | 1052 | self.delay = min(20 * 1000, self.delay * 2) |
|
1053 | 1053 | |
|
1054 | 1054 | if len(self.list) > 0: |
@@ -1394,11 +1394,11 b' class Zeroconf(object):' | |||
|
1394 | 1394 | else: |
|
1395 | 1395 | self.servicetypes[info.type] = 1 |
|
1396 | 1396 | now = currentTimeMillis() |
|
1397 |
next |
|
|
1397 | nexttime = now | |
|
1398 | 1398 | i = 0 |
|
1399 | 1399 | while i < 3: |
|
1400 |
if now < next |
|
|
1401 |
self.wait(next |
|
|
1400 | if now < nexttime: | |
|
1401 | self.wait(nexttime - now) | |
|
1402 | 1402 | now = currentTimeMillis() |
|
1403 | 1403 | continue |
|
1404 | 1404 | out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA) |
@@ -1418,7 +1418,7 b' class Zeroconf(object):' | |||
|
1418 | 1418 | _CLASS_IN, ttl, info.address), 0) |
|
1419 | 1419 | self.send(out) |
|
1420 | 1420 | i += 1 |
|
1421 |
next |
|
|
1421 | nexttime += _REGISTER_TIME | |
|
1422 | 1422 | |
|
1423 | 1423 | def unregisterService(self, info): |
|
1424 | 1424 | """Unregister a service.""" |
@@ -1431,11 +1431,11 b' class Zeroconf(object):' | |||
|
1431 | 1431 | except KeyError: |
|
1432 | 1432 | pass |
|
1433 | 1433 | now = currentTimeMillis() |
|
1434 |
next |
|
|
1434 | nexttime = now | |
|
1435 | 1435 | i = 0 |
|
1436 | 1436 | while i < 3: |
|
1437 |
if now < next |
|
|
1438 |
self.wait(next |
|
|
1437 | if now < nexttime: | |
|
1438 | self.wait(nexttime - now) | |
|
1439 | 1439 | now = currentTimeMillis() |
|
1440 | 1440 | continue |
|
1441 | 1441 | out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA) |
@@ -1453,17 +1453,17 b' class Zeroconf(object):' | |||
|
1453 | 1453 | _CLASS_IN, 0, info.address), 0) |
|
1454 | 1454 | self.send(out) |
|
1455 | 1455 | i += 1 |
|
1456 |
next |
|
|
1456 | nexttime += _UNREGISTER_TIME | |
|
1457 | 1457 | |
|
1458 | 1458 | def unregisterAllServices(self): |
|
1459 | 1459 | """Unregister all registered services.""" |
|
1460 | 1460 | if len(self.services) > 0: |
|
1461 | 1461 | now = currentTimeMillis() |
|
1462 |
next |
|
|
1462 | nexttime = now | |
|
1463 | 1463 | i = 0 |
|
1464 | 1464 | while i < 3: |
|
1465 |
if now < next |
|
|
1466 |
self.wait(next |
|
|
1465 | if now < nexttime: | |
|
1466 | self.wait(nexttime - now) | |
|
1467 | 1467 | now = currentTimeMillis() |
|
1468 | 1468 | continue |
|
1469 | 1469 | out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA) |
@@ -1482,13 +1482,13 b' class Zeroconf(object):' | |||
|
1482 | 1482 | _CLASS_IN, 0, info.address), 0) |
|
1483 | 1483 | self.send(out) |
|
1484 | 1484 | i += 1 |
|
1485 |
next |
|
|
1485 | nexttime += _UNREGISTER_TIME | |
|
1486 | 1486 | |
|
1487 | 1487 | def checkService(self, info): |
|
1488 | 1488 | """Checks the network for a unique service name, modifying the |
|
1489 | 1489 | ServiceInfo passed in if it is not unique.""" |
|
1490 | 1490 | now = currentTimeMillis() |
|
1491 |
next |
|
|
1491 | nexttime = now | |
|
1492 | 1492 | i = 0 |
|
1493 | 1493 | while i < 3: |
|
1494 | 1494 | for record in self.cache.entriesWithName(info.type): |
@@ -1500,8 +1500,8 b' class Zeroconf(object):' | |||
|
1500 | 1500 | self.checkService(info) |
|
1501 | 1501 | return |
|
1502 | 1502 | raise NonUniqueNameException |
|
1503 |
if now < next |
|
|
1504 |
self.wait(next |
|
|
1503 | if now < nexttime: | |
|
1504 | self.wait(nexttime - now) | |
|
1505 | 1505 | now = currentTimeMillis() |
|
1506 | 1506 | continue |
|
1507 | 1507 | out = DNSOutgoing(_FLAGS_QR_QUERY | _FLAGS_AA) |
@@ -1511,7 +1511,7 b' class Zeroconf(object):' | |||
|
1511 | 1511 | _CLASS_IN, _DNS_TTL, info.name)) |
|
1512 | 1512 | self.send(out) |
|
1513 | 1513 | i += 1 |
|
1514 |
next |
|
|
1514 | nexttime += _CHECK_TIME | |
|
1515 | 1515 | |
|
1516 | 1516 | def addListener(self, listener, question): |
|
1517 | 1517 | """Adds a listener for a given question. The listener will have |
General Comments 0
You need to be logged in to leave comments.
Login now