Skip to content

Commit

Permalink
- Make the YR/NS handlers less strict about the 'rest' field. We might
Browse files Browse the repository at this point in the history
  want to stuff additional data there someday.
- Stop reading 'when' from the DNS ipcache.  It's pretty much useless,
  and we always set it to the year 2038.
  • Loading branch information
pmarks-net committed Aug 22, 2011
1 parent fe48dfc commit fd1c4d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dtella/client/main.py
Expand Up @@ -179,15 +179,15 @@ def startConnecting(self):
# Get config from DNS
def dns_cb():
try:
# 2011-08-21: New nodes ignore the value of 'when'.
when, ipps = self.state.dns_ipcache
except ValueError:
pass
else:
random.shuffle(ipps)
age = max(time.time() - when, 0)
for ipp in ipps:
ad = Ad().setRawIPPort(ipp)
self.state.refreshPeer(ad, age)
self.state.refreshPeer(ad, 0)

self.startInitialContact()

Expand Down
12 changes: 8 additions & 4 deletions dtella/common/core.py
Expand Up @@ -934,8 +934,10 @@ def check_cb(src_n, src_ipp, rest):

persist = bool(flags & PERSIST_BIT)

if rest:
raise BadPacketError("Extra data")
# 2011-08-21: allow 'rest' to be non-empty, in case we want to add
# new fields someday.
if len(rest) > 1024:
raise BadPacketError("Too much extra data")

if not (5 <= expire <= 30*60):
raise BadPacketError("Expire time out of range")
Expand Down Expand Up @@ -1414,8 +1416,10 @@ def handlePacket_YR(self, ad, data):
c_nbs, rest = self.decodeNodeList(rest)
u_nbs, rest = self.decodeNodeList(rest)

if rest:
raise BadPacketError("Extra data")
# 2011-08-21: allow 'rest' to be non-empty, in case we want to add
# new fields someday.
if len(rest) > 1024:
raise BadPacketError("Too much extra data")

if not (5 <= expire <= 30*60):
raise BadPacketError("Expire time out of range")
Expand Down
1 change: 1 addition & 0 deletions dtella/common/state.py
Expand Up @@ -190,6 +190,7 @@ def setDNSIPCache(self, data):

CHECK(len(data) % 6 == 4)

# 2011-08-21: New nodes ignore the value of 'when'.
when, = struct.unpack("!I", data[:4])
ipps = [data[i:i+6] for i in range(4, len(data), 6)]

Expand Down

0 comments on commit fd1c4d6

Please sign in to comment.