コード例 #1
0
ファイル: Client.cs プロジェクト: Potashev/ClientServer
        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;
            }
        }
コード例 #2
0
ファイル: Neighbour.cs プロジェクト: Potashev/ClientServer
 public bool IsBetterThan(Neighbour otherNeighbour)
 {
     if (this.Priority <= otherNeighbour.Priority)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
ファイル: Neighbour.cs プロジェクト: Potashev/ClientServer
 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);
     }
 }
コード例 #4
0
ファイル: Server.cs プロジェクト: Potashev/ClientServer
        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);
        }
コード例 #5
0
ファイル: Server.cs プロジェクト: Potashev/ClientServer
 void InputNeighbourPriority(out int priority)
 {
     PrintMessage(Neighbour.GetPriorityValueInfo());
     priority = GetInputData(x => (x >= 0), "Приоритет:");
 }