def __init__(self, server_port, peer_forward_port, peer_backward_port, client_forward_port, client_backward_port, master_port) : #create id of server using the hash of IP address and MAC self.HOST = '' # Symbolic name meaning all available interfaces #self.PORT = 9167 # All servers will listen on this port -- to listen to CLIENTS #self.PEER_PORT = 9570 # to listen to PEERS #self.MASTER_PORT = 11500 self.PORT = int(server_port) self.PEER_HOST = "" self.PEER_FORWARD_PORT = int(peer_forward_port) self.PEER_BACKWARD_PORT = int(peer_backward_port) self.CLIENT_FORWARD_PORT = int(client_forward_port) self.CLIENT_BACKWARD_PORT = int(client_backward_port) self.MASTER_PORT= int(master_port) self.MASTER_HOST = "" self.PORT_Mapper = port_mapper.PortMap() self.ip = "" self.nodeid = "" self.A_server = "" # Pastry protocol datastructures :-------- self.leaf = [] # contain Leaf nodes having L/2 closest small and L/2 closest greater nodes self.neighbour = [] # contain neighbours - k closest nodes according to the proximity measure self.routing = [] # routing table connection_type = 1 print "GOING TO INITIALIZE IP ADDRESSSSSSSS" while True : try : if connection_type == 1 : self.ip = ni.ifaddresses('enp1s0')[2][0]['addr'] else : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] if self.ip == "" : continue except : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] finally : break self.socket_obj = {} # just to show to bibhas sir----- # ip_ob = IP.IP() # my_ip = ip_ob.get_my_ip() # self.ip = my_ip #--------------------------------- #self.nodeid = "abc8960" # dummy nodeid self.HOST = self.ip #self.leaf = ["abc4550","cd4562"] #self.neighbour = ["35abce", "f538ab"] #temp = ["NULL"]*16 #print self.routing #self.routing.append(temp) #self.routing.append(temp) #self.routing.append(temp) #self.routing.append(temp) # print self.check_information("3496fe",3) #print "getting list of masters :" #masters_list = get_masters_from_persistence("server 2:LIST_OF_MASTERS") #print "99 ",masters_list #exit() self.register_to_persistence() if self.A_server.find('0') is not -1 : # decide this condition of master selection later print "I am the first peer in the network" else: try: data = Thread(target=self.peer_front_process, args=("REQUEST <ip>" +self.ip + " :0",self.A_server)).start() # Separate thread to accept the incoming connections from tier 2 peers # decoding the received data after the search process done print "Received data :" print data except Exception, errtxt: print errtxt
def __init__(self, server_port, peer_forward_port, peer_backward_port, client_forward_port, client_backward_port, master_port) : #create id of server using the hash of IP address and MAC self.HOST = '' # Symbolic name meaning all available interfaces #self.PORT = 9167 # All servers will listen on this port -- to listen to CLIENTS #self.PEER_PORT = 9570 # to listen to PEERS #self.MASTER_PORT = 11500 self.PORT = int(server_port) self.PEER_HOST = "" self.PEER_FORWARD_PORT = int(peer_forward_port) self.PEER_BACKWARD_PORT = int(peer_backward_port) self.CLIENT_FORWARD_PORT = int(client_forward_port) self.CLIENT_BACKWARD_PORT = int(client_backward_port) self.MASTER_PORT= int(master_port) self.MASTER_HOST = "" self.PORT_Mapper = port_mapper.PortMap() self.ip = "" self.nodeid = "" self.A_server = "" # Pastry protocol datastructures :-------- self.leaf = [] # contain Leaf nodes having L/2 closest small and L/2 closest greater nodes self.neighbour = [] # contain neighbours - k closest nodes according to the proximity measure self.routing = [] # routing table for i in range(0,20): self.routing.append(["NULL"]*20) connection_type = 1 print "GOING TO INITIALIZE IP ADDRESSSSSSSS" while True : try : if connection_type == 1 : self.ip = ni.ifaddresses('enp1s0')[2][0]['addr'] else : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] if self.ip == "" : continue except : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] finally : break self.socket_obj = {} #self.nodeid = "abc8960" # dummy nodeid self.HOST = self.ip #self.leaf = ["abc4550","cd4562"] #self.neighbour = ["35abce", "f538ab"] #temp = ["NULL"]*16 #print self.routing #self.routing.append(temp) #self.routing.append(temp) #self.routing.append(temp) #self.routing.append(temp) # print self.check_information("3496fe",3) #print "getting list of masters :" #masters_list = get_masters_from_persistence("server 2:LIST_OF_MASTERS") #print "99 ",masters_list #exit() self.register_to_persistence() #get_masters_from_persistence("server 2:LIST_OF_MASTERS") if self.A_server is "0" : # decide this condition of master selection later print "I am the first peer in the network" else: try: queue = Queue.Queue() thread_ = threading.Thread(target=self.peer_front_process, args=("REQUEST START<id>" +self.nodeid + ":-1",self.A_server,queue)) thread_.start() # Separate thread to accept the incoming connections from tier 2 peers # decoding the received data after the search process done thread_.join() msg = queue.get() print "Decoding the data : ",msg leaf = msg[msg.rfind('&')+1:msg.rfind('#')] leaf = leaf.strip() self.leaf = leaf.split() print "leaf is : ",self.leaf nei = msg[msg.rfind('$')+1:msg.rfind('@')] nei = nei.split() print "Neighbour is : ", self.neighbour step = msg[msg.rfind('@')+1:] step = int(step) routing = msg[msg.rfind('#')+1:msg.rfind('$')] routing = routing.strip() routing = routing.split('Routing') nodes_on_path = [] #self.routing = [] #for i in range(0,step): # self.routing.append(["NULL"]*20) print "Debugging : ",self.routing for i in range(1,len(routing)): x = routing[i].strip() row = x[:x.rfind('^')].strip() node = x[x.rfind('^')+1:].strip() nodes_on_path.append(node) entries = row.split() for j in range(0,20): self.routing[step][j] = entries[j] # debugging1 #self.routing.append(entries) #print "hey ",i+1 #print node, " ",row," ",entries print "Routing table : " print self.routing print "Updating the leaf set :" for node in nodes_on_path: bisect.insort(self.leaf,node) if(len(self.leaf) > 4): if(self.nodeid > node): self.leaf = self.leaf[1:] else: self.leaf = self.leaf[:-1] print "leaf set after updation :" print self.leaf except Exception, errtxt: print errtxt
def __init__(self, server_port, peer_forward_port, peer_backward_port, master_port) : #create id of server using the hash of IP address and MAC self.HOST = '' # Symbolic name meaning all available interfaces #self.PORT = 9167 # All servers will listen on this port -- to listen to CLIENTS #self.PEER_PORT = 9570 # to listen to PEERS #self.MASTER_PORT = 11500 self.PORT = int(server_port) self.PEER_HOST = "10.0.0.4" self.PEER_FORWARD_PORT = int(peer_forward_port) self.PEER_BACKWARD_PORT = int(peer_backward_port) self.MASTER_PORT= int(master_port) self.MASTER_HOST = "10.0.0.4" self.PORT_Mapper = port_mapper.PortMap() self.ip = "" # Pastry protocol datastructures :-------- self.leaf = [] # contain Leaf nodes having L/2 closest small and L/2 closest greater nodes self.neighbour = [] # contain neighbours - k closest nodes according to the proximity measure self.routing = [] # routing table connection_type = 1 print "GOING TO INITIALIZE IP ADDRESSSSSSSS" while True : try : if connection_type == 1 : self.ip = ni.ifaddresses('enp1s0')[2][0]['addr'] else : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] if self.ip == "" : continue except : self.ip = ni.ifaddresses('eth0')[2][0]['addr'] finally : break self.socket_obj = {} # just to show to bibhas sir----- ip_ob = IP.IP() my_ip = ip_ob.get_my_ip() self.ip = my_ip #--------------------------------- self.HOST = self.ip fHandle = open('master_stub.txt') # write 0 in stub file when starting the network data = fHandle.read() fHandle.close() data = data.strip() #print "getting list of masters :" #masters_list = get_masters_from_persistence("server 2:LIST_OF_MASTERS") #print "99 ",masters_list #exit() # if data == '0' : # decide this condition of master selection later # print "Initiating master" # self.master_node = master_8.Master(self.MASTER_PORT) # else : print "Initiating Server" #self.register_to_persistence() ### to get ip of A server from persistence A_server = try: data = Thread(target=self.peer_front_process, args=("REQUEST <ip>" +self.ip + " :0",A_server)).start() # Separate thread to accept the incoming connections from tier 2 peers except Exception, errtxt: print errtxt