예제 #1
0
 def getRoutingTableXML(self):
     """
     Returns an XML formatted copy of the routing table.
     """
     # first calculate the matrix
     matrix = []
     for dest_tc in self._routingtable.keys():
         for src_tc in self._routingtable[dest_tc].keys():
             for entry in self._routingtable[dest_tc][src_tc]:
                 line = [entry.getSourceTC(), entry.getDestinationTC(), entry.getGWCommunityId(),
                     entry.getGWMemberId(), str(entry.getCosts())]
                 matrix.append(line)
     
     from messagewrapper import getRoutingTableWrapper
     xml = getRoutingTableWrapper().encodeRoutingTable(matrix)
     return xml
예제 #2
0
    def applyRoutingTableFromNode(self, peerId, tableXml):
        """
        Updates the local routing table with the information from the remote peer about its routes.
        """
        from messagewrapper import getRoutingTableWrapper
        matrix = getRoutingTableWrapper().decodeRoutingTable(tableXml)
##        print "RoutingTableManager.apply: Extracted %d entries from Routing Table XML from Peer %s." %(len(matrix), peerId)
        
        # what we  do - we check all available entries with cost 1, whenever their destination tc is the
        # source tc of any of the extracted routes; we add this one
        for dest_tc in self._routingtable.keys():
            for src_tc in self._routingtable[dest_tc].keys():
                for entry in self._routingtable[dest_tc][src_tc]:
                    if entry.getCosts() == 1:
                        for line in matrix:
                            if entry.getDestinationTC() == line[0]:
                                newentry = RoutingTableEntry(None, entry.getSourceTC(), line[1], peerId, 
                                    line[0], int(line[4]) + 1)
                                self.addEntry(newentry)