def joinTheData(param): if param == '': return "the node is not valid" try: param = int(param) except: return "the join node data value, is not valid" server = dhtServerManager.GetServerByDataValue(param) if server == None: dhtServer4 = DHTServer() dhtServer4.DHTNodeDataValue = DHTNodeDataValue(param) dhtServerManager.AssignHostAndPort(dhtServer4) socketAddress4 = dhtServer4.GetDHTSocketAddress() serverLovestValue = dhtServerManager.GetTheServerWithTheLowestDataValue( ) msg = DHTMessage(DHTMessageType.Join) msg.Argument = dhtServer4.Host msg.Tag = str(dhtServer4.Port) msg.Nodevalue = str(param) return dhtServerManager.SendRequestTo(serverLovestValue, msg) else: return 'chord table already has this node'
def AddShortcutToNode(nodeValue, shortcutNodeValue): if (not nodeValue) or nodeValue == '': return "the node to add the shortcut to, is not valid" if (not shortcutNodeValue) or shortcutNodeValue == '': return "the shortcut node to add the shortcut to, is not valid" try: nodeValue = int(nodeValue) except: return "the node data value for the node to add the shortcut to, is not valid" try: shortcutNodeValue = int(shortcutNodeValue) except: return "the shortcut node data value, is not valid" server = dhtServerManager.GetServerByDataValue(nodeValue) if server == None: return "the node to add the shortcut to, was not found" shortcutserver = dhtServerManager.GetServerByDataValue(shortcutNodeValue) if shortcutserver == None: return "the node is supposed to be added as a shortcut, was not found" msg = DHTMessage(DHTMessageType.Shortcut) msg.Argument = shortcutserver.Host msg.Tag = str(shortcutserver.Port) return dhtServerManager.SendRequestTo(server, msg)