def Return_Fastest_Node(): x = Configuration() Node_Dictionary = Tools().Read_From_Json(directory=x.UserFolder + "/" + x.NodeFolder + "/" + x.NodeFile) Send_initial = 999.0 Receive_initial = 999.0 Fastest_Combination = {} for Node, Stats in Node_Dictionary.items(): try: Send = Stats["Send"] Receive = Stats["Receive"] float except TypeError: Send = 999.0 Receive = 999.0 if Send_initial > Send: Send_initial = Send Fastest_Combination["Send"] = Node if Receive_initial > Receive: Receive_initial = Receive Fastest_Combination["Receive"] = Node return Fastest_Combination
def Test_Nodes(self): try: Node_Dictionary = Tools().Read_From_Json( directory=self.NodeFile_Dir) except: self.Build_Directory() Node_Dictionary = Tools().Read_From_Json( directory=self.NodeFile_Dir) for Node, Value in Node_Dictionary.items(): if config.RunTime == False: break config.Node = Node IOTA = Iota(Node, self.PublicSeed) IOTA_Instance = IOTA_Module(Seed=self.PublicSeed, IOTA_Instance=IOTA) Burner_Address = IOTA_Instance.Generate_Address() Temp_Dictionary = {} try: start = time.time() Hash = IOTA_Instance.Send(ReceiverAddress=Burner_Address, Message="Test", Test_Node=True) end = time.time() delta_Send = end - start except: delta_Send = "Error" Temp_Dictionary["Send"] = delta_Send if config.RunTime == False: break try: start = time.time() Output = IOTA_Instance.Receive(Start=1, Test_Node=True) end = time.time() delta_Receive = end - start except: delta_Receive = "Error" Temp_Dictionary["Receive"] = delta_Receive Node_Dictionary[Node] = Temp_Dictionary Tools().Write_To_Json(directory=self.NodeFile_Dir, Dictionary=Node_Dictionary) if config.RunTime == False: break return self
def Return_Optimal_Node(): def Return_Rank(Ranked, Plain): Ranking = {} z = 1 for i in Ranked: for x in Plain: if i == x[0]: if len(x) == 3: temp = {} temp["Node"] = x[2] temp["PoW"] = x[1] Ranking[z] = temp else: temp = {} temp["Node"] = x[1] temp["PoW"] = False Ranking[z] = temp z = z + 1 return Ranking Node_Dictionary = Tools().JSON_Manipulation( File_Directory=UserProfile().Node) Node_Send = [] Node_Read = [] Temp_Send = [] Temp_Read = [] for node, measurements in Node_Dictionary.items(): try: PoW = measurements["Send_PoW"] except KeyError: Pow = "Error" try: No_PoW = measurements["Send_No_PoW"] except KeyError: No_PoW = "Error" try: Read = measurements["Read"] except KeyError: Read = "Error" #Checking Dead Nodes if PoW == "Error": PoW = 9999 if No_PoW == "Error": No_PoW = 9999 if Read == "Error": Read = 9999 # PoW vs Non PoW if PoW < No_PoW: Use_PoW = True Comparison = PoW elif PoW > No_PoW: Use_PoW = False Comparison = No_PoW else: Comparison = 9999 PoW = False if Comparison != 9999: Node_Send.append([Comparison, Use_PoW, node]) Temp_Send.append(Comparison) if Read != 9999: Node_Read.append([Read, node]) Temp_Read.append(Read) Temp_Send.sort() Temp_Read.sort() Ranked_Sending = Return_Rank(Temp_Send, Node_Send) Ranked_Receiving = Return_Rank(Temp_Read, Node_Read) return [Ranked_Sending, Ranked_Receiving]