Beispiel #1
0
 def broadcast(self, node, network):
     for receiver in network.getProcesses():
         newVal = self.getRandomValFromRange()
         newNode = EIGNode(newVal, node.getParents(), (self.round))
         event = ReceiveEvent(self, receiver, newNode, network)
         latency = (random.lognormal(
             0.8, 0.5)) * 10  # See README for latency explanation
         delay = self.skew + latency
         network.addToQueue(event, delay)
Beispiel #2
0
    def sendToAll(self, network):
        # If this is the final round, add a decision event to the queue
        if (self.round == network.getMaxByz() + 1):
            if self.isPrinter():
                print(
                    colored(
                        "adding decision event to queue in round " +
                        str(self.round), 'blue'))
            self.decide(network)
            decisionEvent = DecisionEvent(self, self.decisionVector, network)
            latency = (random.lognormal(
                0.8, 0.5)) * 10  # See README for latency explanation
            delay = self.skew + latency
            network.addToQueue(decisionEvent, delay)
        # Otherwise broadcast and then add timeout event to queue
        else:
            if self.isPrinter():
                print(
                    colored("sending to all round " + str(self.round), 'blue'))
            for node in self.tree.leaves():
                if self.isPrinter():
                    print(
                        colored("i am not in parents of " + str(node),
                                'green'))
                if node.data.val != None:
                    if self.isPrinter():
                        print(
                            colored(
                                "val is not none, broadcasting " + str(node),
                                'green'))
                    newParents = node.data.parents[:]
                    newParents.append(self)
                    newVal = node.data.val
                    newNode = EIGNode(newVal, newParents, self.round)
                    self.broadcast(newNode, network)
                elif node.data.val == None:
                    if self.isPrinter():
                        print(colored("value is none " + str(node), 'red'))

            # add timeout event to queue
            timeoutEvent = TimeoutEvent(self, network)
            network.addToQueue(timeoutEvent, TIMEOUT + self.skew)
            if self.isPrinter():
                print(
                    colored("added timeout to queue round " + str(self.round),
                            'blue'))
                print(colored("timeout event: " + str(timeoutEvent), 'green'))
Beispiel #3
0
 def receive(self, sender, node, network):
     if self.isPrinter():
         print(
             colored(
                 "receiving event from " + str(sender) + " in round " +
                 str(self.round), 'magenta'))
     if len(node.getParents()) != len(set(node.getParents())):
         if network.logger:
             network.log.debug(
                 str(self) + " ignoring node with repeated parents " +
                 str(self.round) + " from " + str(sender))
             network.log.debug(str(node))
     elif self.round == node.round:
         if self.isPrinter():
             print(
                 colored(
                     "rounds correct, adding item to tree " +
                     str(self.round), 'green'))
             # check if tree contains parent node (parent node would not be in the tree if it came in after timeout)
         if self.tree.contains(node.getGrandparentsString()) == False:
             # if parent node is not in the tree, add it with value of None
             print("adding None 1: " + str(node.getGrandparentsString()))
             newParents = node.parents[:-1]
             newVal = None
             newNode = EIGNode(newVal, newParents, self.round - 1)
             self.tree.create_node(node.getGrandparentsString(),
                                   node.getGrandparentsString(),
                                   parent=node.getGreatGrandparentsString(),
                                   data=newNode)
         self.tree.create_node(node.getParentsString(),
                               node.getParentsString(),
                               parent=node.getGrandparentsString(),
                               data=node)
     else:
         if self.isPrinter():
             print(
                 colored(
                     "rounds incorrect, adding None val " + str(self.round),
                     'red'))
         if network.logger:
             network.log.debug(
                 str(self) + " missed input in round " + str(self.round) +
                 " from " + str(sender))
             network.log.debug(str(node))
Beispiel #4
0
 def addMissedNodes(self, network):
     allNodes = []
     for node in self.tree.nodes.values():
         allNodes.append(node)
     for item in allNodes:
         newParents = item.data.getParents()
         if self.tree.depth(item) == self.round:
             for otherNode in network.getProcesses():
                 thisParents = copy.copy(newParents)
                 if self.round == 0:
                     thisParents = []
                 if (otherNode not in thisParents):
                     thisParents.append(otherNode)
                     thisParentsString = listToString(thisParents)
                     if (self.tree.contains(thisParentsString) == False):
                         newVal = None
                         newNode = EIGNode(newVal, thisParents, self.round)
                         self.tree.create_node(thisParentsString,
                                               thisParentsString,
                                               parent=item,
                                               data=newNode)
Beispiel #5
0
 def initializeTree(self):
     tree = Tree()
     node = EIGNode(self.initialValue, [], 0)
     tree.create_node("root", "root", data=node)
     tree.show()
     return tree