void FindNeighbourForSending() { bool success = false; PrintMessage("Поиск узла отправки пакетов.."); foreach (Neighbour n in Neighbors) { if ((n.IsForSending()) && (!n.IsDied)) { currentNeighbourForSending = n; PrintMessage($"Текущий узел - {currentNeighbourForSending.Priority}"); success = true; sendingAvailable = true; break; } else if ((n.IsBest()) && (n.IsDied) && (checkingInProcess == false)) { PrintMessage("Запуск проверки узлов для восстановления.."); StartCheckingAsync(); } } if (!success) { PrintMessage($"Нет доступных узлов для отправки."); sendingAvailable = false; } }
public bool IsBetterThan(Neighbour otherNeighbour) { if (this.Priority <= otherNeighbour.Priority) { return(true); } else { return(false); } }
public static int CompareUnitsByPriority(Neighbour x, Neighbour y) { if (x.Priority == y.Priority) { return(0); } if (x.Priority < y.Priority) { return(-1); } else { return(1); } }
List <Neighbour> GetNeighboursForClient(TopologyUnit client, List <TopologyUnit> clients) { string clientIp = client.GetIpPort(); int clientId = client.Id; PrintMessage($"Для узла {clientIp} (id = {clientId}):"); List <Neighbour> neibs = new List <Neighbour>(); while (true) { int?id = InputNeighbourId(clients.Count, clientId); if (id == null) { break; } if (id == 0) { string serverIp = GetIpAdress().ToString(); Neighbour NeibServer = new Neighbour(serverIp, 1, AcceptPort); neibs.Add(NeibServer); numberIncomingConnections++; continue; } foreach (TopologyUnit cl in clients) { if (cl.Id == id) { InputNeighbourPriority(out int priority); string ip = cl.GetIp(); int port = cl.AcceptPort; Neighbour n = new Neighbour(ip, priority, port); neibs.Add(n); break; } } } return(neibs); }
void InputNeighbourPriority(out int priority) { PrintMessage(Neighbour.GetPriorityValueInfo()); priority = GetInputData(x => (x >= 0), "Приоритет:"); }