def main(): # Obtain my IP address myip = myIP() node.IPAddr = myip # Grab my port, if provided # If not provided or given a "?" # Choose port at random from 9000 to 9999 args = sys.argv if len(args) > 1 and args[1] != "?": local_port = int(args[1]) else: local_port = random.randint(9000, 9999) # Obtain the destination port/IP, if it exists other_IP = args[2] if len(args) > 2 else None other_port = int(args[3]) if len(args) > 3 else None # Setup my node setup_Node(addr=myip,port=local_port) # If we were provided the info of another node, join it's ring if not other_IP is None and not other_port is None: join_ring(other_IP, other_port) else: no_join() # Start the node services and the console node.startup() console()
def main(): myip = myIP() node.IPAddr = myip args = sys.argv if len(args) > 1 and args[1] != "?": local_port = int(args[1]) else: local_port = random.randint(9000, 9999) other_IP = args[2] if len(args) > 2 else "131.96.49.89" other_port = int(args[3]) if len(args) > 3 else 9000 setup_Node(addr=myip, port=local_port) if not other_IP is None and not other_port is None: join_ring(other_IP, other_port) else: no_join() node.startup() console()
if len(sys.argv) > 2: node_name = sys.argv[2] node_port = int(sys.argv[3]) othernode = node.Node_Info(node_name, node_port) node.join(othernode) print node.thisNode print othernode #f = lambda : node.join(othernode) #t = Thread(target=f) #t.start() else: node.create() #t = Thread(target = node.create) #t.start() node.startup() while True: cmd = raw_input(">>") if cmd[:6] == "get f ": x = int(cmd[6:]) print node.fingerTable[x] elif cmd == 'q' or cmd == 'Q' : node.my_polite_exit() exit() elif cmd == 'g' or cmd == 'G': print "estimate:", node.estimate_ring_density() elif cmd[:4] == "get ": database.get_record(cmd[4:]) elif cmd[:4] == "put ": arg_str = cmd[4:].split(' ',1) database.put_record(arg_str[0],arg_str[1])