public void BitfieldCorrupt() { bool[] data = new bool[] { true, false, false, true, false, true, false, true, false, true, false, true, false, false, false, true }; byte[] encoded = new BitfieldMessage(new BitField(data)).Encode(); PeerMessage.DecodeMessage(encoded, 0, encoded.Length, testRig.Manager); }
//Deliberately broken to work around bugs in azureus public void BitfieldCorrupt() { var data = new[] {true, false, false, true, false, true, false, true, false, true, false, true, false, false, false, true}; var encoded = new BitfieldMessage(new BitField(data)).Encode(); Assert.Throws<MessageException>(() => PeerMessage.DecodeMessage(encoded, 0, encoded.Length, testRig.Manager)); }
public void BitFieldEncoding() { bool[] data = new bool[] { true, false, false, true, false, true, false, true, false, true, false, true, false, false, false, true, true, true, false, false, false, true, false, true, false, false, true, false, true, false, true, true, false, false, true, false, false, true, true, false }; byte[] encoded = new BitfieldMessage(new BitField(data)).Encode(); BitfieldMessage m = (BitfieldMessage)PeerMessage.DecodeMessage(encoded, 0, encoded.Length, testRig.Manager); Assert.AreEqual(data.Length, m.BitField.Length, "#1"); for (int i = 0; i < data.Length; i++) Assert.AreEqual(data[i], m.BitField[i], "#2." + i); }
public override void Tick(int counter) { base.Tick(counter); if (unchoker.Complete) { PeerMessage bitfieldMessage = new BitfieldMessage(Manager.Bitfield); PeerMessage haveAllMessage = new HaveAllMessage(); foreach (var peer in Manager.Peers.ConnectedPeers) { var message = peer.SupportsFastPeer && Manager.Complete ? haveAllMessage : bitfieldMessage; peer.Enqueue(message); } Manager.Mode = new DownloadMode(Manager); } }
public void BitFieldEncoding() { var data = new[] { true, false, false, true, false, true, false, true, false, true, false, true, false, false, false, true, true, true, false, false, false, true, false, true, false, false, true, false, true, false, true, true, false, false, true, false, false, true, true, false }; var encoded = new BitfieldMessage(new BitField(data)).Encode(); var m = (BitfieldMessage) PeerMessage.DecodeMessage(encoded, 0, encoded.Length, testRig.Manager); Assert.Equal(data.Length, m.BitField.Length); for (var i = 0; i < data.Length; i++) Assert.Equal(data[i], m.BitField[i]); }
protected virtual void HandleBitfieldMessage(PeerId id, BitfieldMessage message) { id.BitField = message.BitField; id.Peer.IsSeeder = (id.BitField.AllTrue); SetAmInterestedStatus(id, manager.PieceManager.IsInteresting(id)); }
private void PeerHandshakeReceived(bool succeeded, int count, object state) { PeerId id = (PeerId)state; string reason = null; bool cleanUp = false; PeerMessage msg; try { // If the connection is closed, just return if (!succeeded) { CleanupSocket(id, "Handshaking failed"); return; } // Decode the handshake and handle it id.Decryptor.Decrypt(id.recieveBuffer.Array, id.recieveBuffer.Offset, count); msg = new HandshakeMessage(); msg.Decode(id.recieveBuffer, 0, count); msg.Handle(id); Logger.Log(id.Connection, "ConnectionManager - Handshake recieved"); if (id.SupportsFastPeer && ClientEngine.SupportsFastPeer) { if (id.TorrentManager.Bitfield.AllFalse || id.TorrentManager.IsInitialSeeding) msg = new HaveNoneMessage(); else if (id.TorrentManager.Bitfield.AllTrue) msg = new HaveAllMessage(); else msg = new BitfieldMessage(id.TorrentManager.Bitfield); } else if (id.TorrentManager.IsInitialSeeding) { BitField btfld = new BitField(id.TorrentManager.Bitfield.Length); btfld.SetAll(false); msg = new BitfieldMessage(btfld); } else { msg = new BitfieldMessage(id.TorrentManager.Bitfield); } if (id.SupportsLTMessages && ClientEngine.SupportsExtended) { MessageBundle bundle = new MessageBundle(); bundle.Messages.Add(new ExtendedHandshakeMessage()); bundle.Messages.Add(msg); msg = bundle; } //ClientEngine.BufferManager.FreeBuffer(ref id.recieveBuffer); SendMessage(id, msg, this.bitfieldSentCallback); } catch (TorrentException) { Logger.Log(id.Connection, "ConnectionManager - Couldn't decode the message"); reason = "Couldn't decode handshake"; cleanUp = true; return; } finally { if (cleanUp) CleanupSocket(id, reason); } }