def __init__(self): #Constructor for this object #Initialize various parameters #and open listening sockets #set the nodes IP-Address Resolve.resolve_ip_address(Config.NODE_INTF) #stores ip-addr => entity-reference self.nodes={} #store ip of this machine #this variable is useful in the #download module self.ip_address = Config.NODE_IP_ADDRESS #create the UDP Socket self.soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.soc.bind((Config.ANY_INTF, Config.UDP_LISTEN_PORT)) #path info updated here dynamically self.path_cache={} self.query_cache={} #object to store path-query replies self.path_q_reply={} print 'Host IP:',Config.NODE_IP_ADDRESS print 'Waiting for other hosts...' #first get atleast two hosts self.getFirstTwoHosts() #there is no need of bcast bit from here. self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 0) #there is no need of timeout on this socket. #should wait indefinitely self.soc.settimeout(None) #spawn a new listening thread print 'Spawned listening thread...' thread.start_new_thread(self.listen,()) print 'First two hosts:' print "\n".join(str(x) for x in self.nodes) print 'Neighbours:' for i in self.nodes: print 'via',i,":" for j in self.nodes[i].neighbours: print j, print