public static Decode ( BEncodedList peers ) : MonoTorrentCollection |
||
peers | BEncodedList | |
return | MonoTorrentCollection |
public void DecodeCompact() { byte[] bytes = new byte[peers.Count * 6]; for (int i = 0; i < peers.Count; i++) { peers[i].CompactPeer(bytes.AsSpan(i * 6, 6)); } VerifyDecodedPeers(Peer.Decode(bytes)); }
public void DecodeCompact() { byte[] bytes = new byte[peers.Count * 6]; for (int i = 0; i < peers.Count; i++) { peers[i].CompactPeer(bytes, i * 6); } VerifyDecodedPeers(Peer.Decode((BEncodedString)bytes)); }
public void CorruptDictionary() { BEncodedList l = new BEncodedList(); BEncodedDictionary d = new BEncodedDictionary(); l.Add(d); IList <Peer> decoded = Peer.Decode(l); Assert.AreEqual(0, decoded.Count, "#1"); }
public void CompactPeer() { string peerId = "12345abcde12345abcde"; Uri uri = new Uri("ipv4://192.168.0.5:12345"); Peer p = new Peer(peerId, uri); byte[] compact = p.CompactPeer(); Peer peer = Peer.Decode(compact)[0]; Assert.AreEqual(p.ConnectionUri, peer.ConnectionUri, "#1"); }
public void CompactPeerTest() { string peerId = "12345abcde12345abcde"; Uri uri = new Uri("tcp://192.168.0.5:12345"); Peer p = new Peer(peerId, uri); byte[] compact = p.CompactPeer(); Peer peer = Peer.Decode((BEncoding.BEncodedString)compact)[0]; Assert.AreEqual(p.ConnectionUri, peer.ConnectionUri); }
public void DecodeList() { // List of String BEncodedList list = new BEncodedList(); foreach (Peer p in peers) { list.Add((BEncodedString)p.CompactPeer()); } VerifyDecodedPeers(Peer.Decode(list)); }
public void CorruptString() { IList <Peer> p = Peer.Decode("1234"); Assert.AreEqual(0, p.Count, "#1"); byte[] b = { 255, 255, 255, 255, 255, 255 }; p = Peer.Decode(b); Assert.AreEqual(1, p.Count, "#2"); b = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; p = Peer.Decode(b); Assert.AreEqual(1, p.Count, "#3"); }
public void DecodePeerId() { var peerId = new BEncodedString(Enumerable.Repeat((byte)255, 20).ToArray()); var dict = new BEncodedDictionary(); dict.Add("ip", (BEncodedString)"1237.1.2.3"); dict.Add("port", (BEncodedNumber)12345); dict["peer id"] = peerId; var peer = Peer.Decode(new BEncodedList { dict }).Single(); Assert.AreEqual(peerId, peer.PeerId, "#1"); }
public void DecodeDictionary() { BEncodedList list = new BEncodedList(); foreach (Peer p in peers) { BEncodedDictionary dict = new BEncodedDictionary(); dict.Add("ip", (BEncodedString)p.ConnectionUri.Host); dict.Add("port", (BEncodedNumber)p.ConnectionUri.Port); dict.Add("peer id", (BEncodedString)p.PeerId); list.Add(dict); } VerifyDecodedPeers(Peer.Decode(list)); }
public void CorruptList() { BEncodedList list = new BEncodedList(); for (int i = 0; i < peers.Count; i++) { list.Add((BEncodedString)peers[i].CompactPeer()); } list.Insert(2, new BEncodedNumber(5)); VerifyDecodedPeers(Peer.Decode(list)); list.Clear(); list.Add(new BEncodedString(new byte[3])); IList <Peer> decoded = Peer.Decode(list); Assert.AreEqual(0, decoded.Count, "#1"); }
protected virtual void HandlePeerExchangeMessage(PeerId id, PeerExchangeMessage message) { // Ignore peer exchange messages on private torrents if (id.TorrentManager.Torrent.IsPrivate || !id.TorrentManager.Settings.EnablePeerExchange) { return; } // If we already have lots of peers, don't process the messages anymore. if ((Manager.Peers.Available + Manager.OpenConnections) >= manager.Settings.MaxConnections) { return; } IList <Peer> peers = Peer.Decode((BEncodedString)message.Added); int count = id.TorrentManager.AddPeersCore(peers); id.TorrentManager.RaisePeersFound(new PeerExchangePeersAdded(id.TorrentManager, count, peers.Count, id)); }