def _needs_update(self, entry:DatabaseEntry, compare_to:DatabaseEntry): if entry == None: if compare_to == None: self.log("Both entries are None") else: self.log("Entry is None") # Anything is better than nothing return compare_to != None # The logic for needing an update: # - If the max known is lower # - Else if max known is equal: # - If max current is lower # - Else if max current is equal and length of vectors is *longer* if entry != None and compare_to != None: self.log("Entry compare (max, cur): entry ({}, {}), compare_to ({}, {})"\ .format(entry.get_max_known_sqn(), entry.get_max_current_sqn(), compare_to.get_max_known_sqn(), compare_to.get_max_current_sqn())) if entry.get_max_known_sqn() < compare_to.get_max_known_sqn(): self.log("Entry has lower max sqn") return True elif entry.get_max_known_sqn() == compare_to.get_max_known_sqn(): if entry.get_max_current_sqn() == compare_to.get_max_current_sqn(): # A list with LESS entries is more up to date self.log("Entry current max equal") return len(entry.get_vectors()) > len(compare_to.get_vectors()) else: return entry.get_max_current_sqn() < compare_to.get_max_current_sqn() else: self.log("Entry has a higher max seqnum") return False self.log("Compare To entry is None") return False
def _check_entry(entry: DatabaseEntry, imsi, max_known_sqn, vectors): return entry.key() == imsi and\ int(entry.get_max_known_sqn()) == int(max_known_sqn) and\ entry.get_vectors() == vectors