Exemple #1
0
        /// <summary>
        /// Handles the Message:
        /// If the MessageType is of any other type than "VoteOK" it ignores the Message.
        /// If it is of the type "VoteOK" the following scenarios may happen:
        /// -   If the sender is not in the VoteReplyList, then that sender is considered dead
        ///     and a reply is send out to the sender to notify it about this. The sender dies.
        /// -   Notifies the vote object that a peer has replied "VoteOK".
        /// </summary>
        /// <param name="message">The Message that is broadcasted.</param>
        /// <returns>
        /// PacketResponse.AcceptAndFinish if all the peers have replied "VoteOK",
        /// PacketResponse.Accept if not.
        /// </returns>
        public PacketResponse HandlePacket(Message message)
        {
            if (message.MessageType != MessageType.VoteOk)
            {
                return(PacketResponse.Decline);
            }

            if (!vote.VoteReplyList.ContainsKey(message.Sender)) //Error in sender - kill'im
            {
                var response = new Message(MessageType.PeerDead, message.Sender)
                {
                    DataAsString = message.Sender.ToString()
                };
                Outbox.SendMessage(response);
            }
            else
            {
                vote.Replied(message.Sender);
            }
            return(vote.IsAcknowledged() ? PacketResponse.AcceptAndFinish : PacketResponse.Accept);
        }