示例#1
0
 private void RequestPeerHash()
 {
     if (Status == PeerStatus.NoHashRecieved)
     {
         var message = new PeerHashMessage(VotingsUser.PublicKey, true);
         if (ConnectionMode == ConnectionMode.Direct)
         {
             //проверка на дисконнект
             try
             {
                 Connection.SendObject(message.GetType().Name, message);
             }
             catch
             {
                 Status = PeerStatus.Disconnected;
                 Connect();
             }
         }
         else
         {
             tracker.SendMessageToPeer(message, this);
         }
     }
     else if (Status == PeerStatus.Disconnected)
     {
         Connect();
     }
 }
示例#2
0
        private void OnPeerHashMessageFromTracker(PacketHeader packetHeader, Connection connection, PeerHashMessage incomingObject)
        {
            var messageToSend = new PeerHashMessage(VotingsUser.PublicKey, false);

            try
            {
                Connection.SendObject(messageToSend.GetType().Name, messageToSend);
            }
            catch
            {
                Status = TrackerStatus.Disconnected;
                Connect();
            }
        }
示例#3
0
        private void OnPeerHashMessageDirect(PeerHashMessage message)
        {
            if (message.PeerHash != string.Empty && message.PeerHash != null)
            {
                Hash   = message.PeerHash;
                Status = PeerStatus.Connected;

                CommonHelpers.LogPeers(allPeers);

                //возможно стоит отключить повторную отправку сообщения, чтобы они не дублировались
                if (message.NeedResponse == true)
                {
                    var messageToSend = new PeerHashMessage(VotingsUser.PublicKey, false);
                    Connection.SendObject(messageToSend.GetType().Name, messageToSend);
                }
            }
        }