def queryLocation(self, my_ipp): # Try to convert the IP address into a human-readable location name. # This might be slightly more complicated than it really needs to be. CHECK(local.use_locations) ad = Ad().setRawIPPort(my_ipp) my_ip = ad.getTextIP() # Set my local ip in the state # self.state.local_ip = my_ip # self.state.saveState() skip = False for ip,loc in self.location.items(): if ip == my_ip: skip = True elif loc: # Forget old entries del self.location[ip] # If we already had an entry for this IP, then don't start # another lookup. if skip: return # A location of None indicates that a lookup is in progress self.location[my_ip] = None def cb(hostname): # Use local_config to transform this hostname into a # human-readable location loc = local.hostnameToLocation(hostname) # If we got a location, save it, otherwise dump the # dictionary entry if loc: self.location[my_ip] = loc else: del self.location[my_ip] # Maybe send an info update if self.osm: self.osm.updateMyInfo() # Start lookup ipToHostname(ad).addCallback(cb)
def queryLocation(self, my_ipp): # Try to convert the IP address into a human-readable location name. # This might be slightly more complicated than it really needs to be. CHECK(local.use_locations) ad = Ad().setRawIPPort(my_ipp) my_ip = ad.getTextIP() # Set my local ip in the state # self.state.local_ip = my_ip # self.state.saveState() skip = False for ip, loc in self.location.items(): if ip == my_ip: skip = True elif loc: # Forget old entries del self.location[ip] # If we already had an entry for this IP, then don't start # another lookup. if skip: return # A location of None indicates that a lookup is in progress self.location[my_ip] = None def cb(hostname): # Use local_config to transform this hostname into a # human-readable location loc = local.hostnameToLocation(hostname) # If we got a location, save it, otherwise dump the # dictionary entry if loc: self.location[my_ip] = loc else: del self.location[my_ip] # Maybe send an info update if self.osm: self.osm.updateMyInfo() # Start lookup ipToHostname(ad).addCallback(cb)
def advanceQueue(self): # Only continue if we have a queue, and spare capacity if not (self.dnsq and self.limiter > 0): return self.limiter -= 1 ip, ent = self.dnsq.popleft() def cb(hostname): for ipp in ent.waiting_ipps: self.signOn(ipp, hostname) ent.waiting_ipps.clear() if hostname is None: del self.cache[ip] else: ent.hostname = hostname self.limiter += 1 self.advanceQueue() LOG.debug("Querying %s" % Ad().setRawIP(ip).getTextIP()) ipToHostname(Ad().setRawIP(ip)).addCallback(cb)
def advanceQueue(self): # Only continue if we have a queue, and spare capacity if not (self.dnsq and self.limiter > 0): return self.limiter -= 1 ip, ent = self.dnsq.popleft() def cb(hostname): for ipp in ent.waiting_ipps: self.signOn(ipp, hostname) ent.waiting_ipps.clear() if hostname is None: del self.cache[ip] else: ent.hostname = hostname self.limiter += 1 self.advanceQueue() LOG.debug("Querying %s" % Ad().setRawIP(ip).getTextIP()) ipToHostname(Ad().setRawIP(ip)).addCallback(cb)