Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 4
0
        private void OnPeerHashMessageWithTracker(object sender, MessageEventArgs e)
        {
            var message = e.Message as PeerHashMessage;

            if (e.SenderAddress.Equals(Address) && message.PeerHash != string.Empty)
            {
                Hash   = message.PeerHash;
                Status = PeerStatus.Connected;

                CommonHelpers.LogPeers(allPeers);

                if (message.NeedResponse == true)
                {
                    var messageToSend = new PeerHashMessage(Hash, false);
                    tracker.SendMessageToPeer(messageToSend, this);
                }
            }
        }