def __init__(self, bootstrap_address = None):
     QueryServent.__init__(self, bootstrap_address=bootstrap_address)
     # number of transmitted message include flood[_ex], forward, and send_message 
     self.num_tx_message = 0
     # number of received message
     self.num_rx_message = 0
     # expect query message_id
     self.query_message_id = None
     # send the query to the network between 1 and 3 seconds later
     CallLater(uniform(1,3), self.send_query_to_network)
 def on_receive(self, connection_handler, message):
     # log to show the network is still working
     self.log("on_receive() -> %s", message)
     # increase received message by one
     self.num_rx_message += 1
     # create fake download if we sent the query to the network
     if (message.payload_descriptor == GnutellaBodyId.QUERYHIT and 
         message.message_id == self.query_message_id and
         self.search('ABC') == []):
         self.add_single_file(FileInfo(1,"ABC",1))          
     QueryServent.on_receive(self, connection_handler, message)
 def flood_ex(self, message):
     ret = QueryServent.flood_ex(self, message)
     self.num_tx_message += ret
     return ret
 def flood(self, connection_handler, message):
     ret = QueryServent.flood(self, connection_handler, message) 
     self.num_tx_message += ret
     return ret
 def forward(self, message):
     ret = QueryServent.forward(self, message)
     if ret:
         self.num_tx_message += 1
     return ret
 def send_message(self, message, handler):
     self.num_tx_message += 1
     QueryServent.send_message(self, message, handler)