def process(self, packet, context): stats.inc_ops('requests') start_time = time.time() message = dns.message.from_wire(packet) message.__class__.__str__ = _pprint_message log.debug(message) log.debug(context) for rule in self.ruleset: m = rule.RE.search(str(message.question[0].name)) if m is not None: log.debug('resolving query: %s using : %s ' % (message,rule) ) response = rule.dispatch(message, context=context) # updating stats for this rule being called stats.add(rule.__class__,1) # rules that return none ignored if response is None: continue # updating stats stats.dec_ops('requests') stats.add_avg('response_time_msec', (time.time() - start_time)*1000 ) domain_stats.add( str(message.question[0].name).strip(), 1) # sending rule response back to client return response stats.add('requests_failed',1) raise errors.Error('No matching rule for %s found' % message)
def process(self, packet, context): stats.inc_ops('requests') start_time = time.time() message = dns.message.from_wire(packet) message.__class__.__str__ = _pprint_message log.debug(message) log.debug(context) for rule in self.ruleset: m = rule.RE.search(str(message.question[0].name)) if m is not None: log.debug('resolving query: %s using : %s ' % (message, rule)) response = rule.dispatch(message, context=context) # updating stats for this rule being called stats.add(rule.__class__, 1) # rules that return none ignored if response is None: continue # updating stats stats.dec_ops('requests') stats.add_avg('response_time_msec', (time.time() - start_time) * 1000) domain_stats.add(str(message.question[0].name).strip(), 1) # sending rule response back to client return response stats.add('requests_failed', 1) raise errors.Error('No matching rule for %s found' % message)
def udp_poller(self): while not self.stopping: try: data, addr = self.udp_socket.recvfrom(1024) if not data: self.close() return stats.add('net.packets_received', 1) stats.add('net.bytes_received', len(data)) self.threadpool.submit(self.worker, (data, addr)) except Exception as ex: log.exception(ex)
def worker(self, info): log.debug('starting to process request...') data, addr = info self.active_threads += 1 stats.add_avg('net.active_threads', self.active_threads) try: response = self.onreceive(data, { 'client' : '%s:%s' % (addr), 'server' : '%s:%s' % (self.host, self.port) }) s = self.udp_socket.sendto(response, addr) stats.add('net.packets_sent', 1) stats.add('net.bytes_sent', s) log.debug('finished to process request...') except Exception as e: log.exception(e) self.active_threads -= 1 stats.add_avg('net.active_threads', self.active_threads)
def worker(self, info): log.debug('starting to process request...') data, addr = info self.active_threads += 1 stats.add_avg('net.active_threads', self.active_threads) try: response = self.onreceive( data, { 'client': '%s:%s' % (addr), 'server': '%s:%s' % (self.host, self.port) }) s = self.udp_socket.sendto(response, addr) stats.add('net.packets_sent', 1) stats.add('net.bytes_sent', s) log.debug('finished to process request...') except Exception as e: log.exception(e) self.active_threads -= 1 stats.add_avg('net.active_threads', self.active_threads)