Exemple #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 static MessageFactory()
 {
     chokeMessage         = new ChokeMessage();
     unchokeMessage       = new UnchokeMessage();
     interestedMessage    = new InterestedMessage();
     notInterestedMessage = new NotInterestedMessage();
 }
Exemple #2
0
 protected virtual void HandleChokeMessage(PeerId id, ChokeMessage message)
 {
     id.IsChoking = true;
     if (!id.SupportsFastPeer)
     {
         manager.PieceManager.Picker.CancelRequests(id);
     }
 }
Exemple #3
0
        /// <summary>
        /// Processes the received message.
        /// </summary>
        /// <param name="message">The message.</param>
        private void ProcessRecievedMessage(ChokeMessage message)
        {
            message.CannotBeNull();

            if (this.HandshakeState == HandshakeState.SendAndReceived)
            {
                this.EnqueueDownloadMessage(message);
            }
            else
            {
                this.OnCommunicationErrorOccurred(this, new PeerCommunicationErrorEventArgs("Invalid message sequence.", true));
            }
        }
Exemple #4
0
        public void ChokeMessage_TryDecode()
        {
            ChokeMessage message;
            int          offset = 0;
            bool         isIncomplete;

            byte[] data = "0000000100".ToByteArray();

            if (ChokeMessage.TryDecode(data, ref offset, data.Length, out message, out isIncomplete))
            {
                Assert.AreEqual(5, message.Length);
                Assert.AreEqual(false, isIncomplete);
                Assert.AreEqual(data.Length, offset);
                CollectionAssert.AreEqual(data, message.Encode());
            }
            else
            {
                Assert.Fail();
            }
        }
Exemple #5
0
 void peer_ChokeMessageReceived(object sender, ChokeMessage e)
 {
     ShowMessage("{0}:Received {1}", sender, e);
 }
        public void ChokeEncoding()
        {
            int length = new ChokeMessage().Encode(buffer, offset);

            Assert.AreEqual("00-00-00-01-00", BitConverter.ToString(buffer, offset, length));
        }
 public void ChokeEncoding()
 {
     var length = new ChokeMessage().Encode(_buffer, Offset);
     Assert.AreEqual("00-00-00-01-00", BitConverter.ToString(_buffer, Offset, length));
 }
Exemple #8
0
 protected virtual void HandleChoke(ChokeMessage choke, PeerState peer)
 {
     peer.AmChoked = true;
 }
Exemple #9
0
 protected virtual void HandleChokeMessage(PeerId id, ChokeMessage message)
 {
     id.IsChoking = true;
     if (!id.SupportsFastPeer)
         _manager.PieceManager.Picker.CancelRequests(id);
 }