Пример #1
0
        def helper(L, t):
            """ 
            L is the list and t is 0 for cw and 1 for ccw.
            If L has no elements, finds the closest node by looking
            at all the elements on the table.
            If L has one element, finds the closest node by gossiping 
            on the other existing neighbor
            """
            closestNode = None
            if (len(L)==0):
                if (t==0):
                    closestNode = self.router.closest_successor(self.node) 
                else:
                    closestNode = self.router.closest_predecessor(self.node)
                client = WDHTClient(closestNode.ip, closestNode.port)
                if (t==0):
                    closestNode = client.closest_node_cr(self.node.id)
                else:
                    closestNode = client.closest_node_ccr(self.node.id)
                if closestNode is None:
                    logging.debug("The closest node was None")

                if closestNode.id != self.node.id:
                    self.router.update([closestNode])

            if (len(L)==1):
                neighbors = self.router.neighbor_set.get_neighbors()
                if (t==0):
                    closestNode = self.router.closest_successor(self.node) 
                else:
                    closestNode = self.router.closest_predecessor(self.node)

                if (closestNode.id != self.node.id):
                    client = WDHTClient(closestNode.ip, closestNode.port)
                    cur = client.gossip_neighbors(self.node, neighbors)
                    cur.remove(self.node)
                    self.router.neighbor_set.update(cur)