Changeset 1615
- Timestamp:
- 11/07/08 14:46:28 (2 months ago)
- Files:
-
- branches/0.4.7/lib/cxcore/cxcore/cxnetlink.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.4.7/lib/cxcore/cxcore/cxnetlink.py
r1612 r1615 37 37 import traceback 38 38 import time 39 import random 39 40 40 41 from cxnet.common import hline … … 240 241 svc = zeroconf.ServiceInfo(domain, host) 241 242 243 pool = { 244 "reachable": [], 245 "stale": [], 246 } 247 242 248 for i in self.server.cache.entriesWithName(host): 243 249 if (i.clazz == zeroconf._CLASS_IN) and (i.type == zeroconf._TYPE_A): 244 svc.address = inet_ntoa(i.address) 250 if pool.has_key(i.state): 251 pool[i.state].append(i) 245 252 elif (i.clazz == zeroconf._CLASS_IN) and (i.type == zeroconf._TYPE_SRV): 246 253 svc.port = i.port … … 248 255 svc.setText(i.text) 249 256 250 if (not svc.address) and (zeroconf._TYPE_A in types): 257 print "DEBUG", pool 258 if len(pool["reachable"]) > 0: 259 rec = random.choice(pool["reachable"]) 260 elif len(pool["stale"]) > 0: 261 rec = random.choice(pool["stale"]) 262 else: 263 rec = None 264 265 if (not rec) and (zeroconf._TYPE_A in types): 251 266 raise mDNS_HostNotFound() 252 267 … … 257 272 raise mDNS_TextNotFound() 258 273 259 return ((svc.getAddress(),svc.getPort()),svc.getProperties()) 274 print ((inet_ntoa(rec.address),svc.getPort()),svc.getProperties(),rec) 275 return ((inet_ntoa(rec.address),svc.getPort()),svc.getProperties(),rec) 260 276 261 277 … … 309 325 CX_FLAGS_MORE_FRAGMENTS = 0x004 310 326 327 CX_MSG_TRACK = 0x001 328 311 329 class cxmsg(Structure): 312 330 ''' … … 393 411 self.reasm_buffer = {} 394 412 self.finish_buffer = {} 413 self.watch = {} 395 414 396 415 # encryption … … 416 435 try: 417 436 (bytes,(address,port)) = self.sock.recvfrom_into(self.recv_buffer) 437 if self.watch.has_key((address,port)): 438 self.watch[(address,port)].state = "reachable" 439 del self.watch[(address,port)] 440 418 441 # python < 2.5 419 442 except: … … 498 521 499 522 500 def send(self,host,packet): 523 def watchdog(self,host): 524 if self.watch.has_key(host): 525 self.watch[host].state = "stale" 526 del self.watch[host] 527 528 def send(self,host,packet,flags=0,data=None): 501 529 ''' 502 530 Encrypt and send a packet … … 514 542 (c,a) = self.encrypt(c) 515 543 msg.header.alg_len = a 544 545 if flags & CX_MSG_TRACK and data: 546 self.watch[host] = data 547 Timer(2,self.watchdog,(host,)).start() 516 548 517 549 offset = 0
