/// <summary> /// 构造函数 /// </summary> static MessageFactory() { chokeMessage = new ChokeMessage(); unchokeMessage = new UnchokeMessage(); interestedMessage = new InterestedMessage(); notInterestedMessage = new NotInterestedMessage(); }
protected virtual void HandleChokeMessage(PeerId id, ChokeMessage message) { id.IsChoking = true; if (!id.SupportsFastPeer) { manager.PieceManager.Picker.CancelRequests(id); } }
/// <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)); } }
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(); } }
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)); }
protected virtual void HandleChoke(ChokeMessage choke, PeerState peer) { peer.AmChoked = true; }
protected virtual void HandleChokeMessage(PeerId id, ChokeMessage message) { id.IsChoking = true; if (!id.SupportsFastPeer) _manager.PieceManager.Picker.CancelRequests(id); }