public void BenNumberEncoding6() { BEncodedNumber a = -123; BEncodedNumber b = BEncodedValue.Decode <BEncodedNumber>(a.Encode()); Assert.Equal(a.Number, b.Number); }
void AddFiles(BEncodedDictionary dict, IEnumerable <TorrentFile> torrentFiles) { long totalSize = _piecelength - 1; var bFiles = new BEncodedList(); foreach (var torrentFile in torrentFiles) { var path = new BEncodedList(); foreach (var split in torrentFile.Path.Split('/')) { path.Add((BEncodedString)split); } var dictionary = new BEncodedDictionary(); dictionary["path"] = path; dictionary["length"] = (BEncodedNumber)torrentFile.Length; bFiles.Add(dictionary); totalSize += torrentFile.Length; } dict[new BEncodedString("torrentFiles")] = bFiles; dict[new BEncodedString("name")] = new BEncodedString("test.torrentFiles"); dict[new BEncodedString("piece length")] = new BEncodedNumber(_piecelength); dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20 * (totalSize / _piecelength)]); }
public AnnouncePeer(NodeId id, NodeId infoHash, BEncodedNumber port, BEncodedString token) : base(id, _queryName, _responseCreator) { Arguments.Add(_infoHashKey, infoHash.BencodedString()); Arguments.Add(_portKey, port); Arguments.Add(_tokenKey, token); }
public AnnouncePeer(NodeId id, NodeId infoHash, BEncodedNumber port, BEncodedString token) : base(id, QueryName, responseCreator) { Parameters.Add(InfoHashKey, infoHash.BencodedString()); Parameters.Add(PortKey, port); Parameters.Add(TokenKey, token); }
public void benNumber_MaxMin([Values(long.MinValue, long.MaxValue)] long value) { var number = new BEncodedNumber(value); var result = BEncodedValue.Decode <BEncodedNumber> (number.Encode()); Assert.AreEqual(result.Number, value); }
public AnnouncePeer(NodeId id, NodeId infoHash, BEncodedNumber port, BEncodedString token) : base(id, QueryName, responseCreator) { Parameters.Add(InfoHashKey, infoHash.BencodedString()); Parameters.Add(PortKey, port); Parameters.Add(TokenKey, token); }
public AnnouncePeer(NodeId id, NodeId infoHash, BEncodedNumber port, BEncodedValue token) : base(id, QueryName) { Parameters.Add(InfoHashKey, BEncodedString.FromMemory(infoHash.AsMemory())); Parameters.Add(PortKey, port); Parameters.Add(TokenKey, token); }
static void AddFiles(BEncodedDictionary dict, TorrentFile[] files, int pieceLength) { long totalSize = pieceLength - 1; var bFiles = new BEncodedList(); for (int i = 0; i < files.Length; i++) { var path = new BEncodedList(); foreach (string s in files[i].Path.Split('/')) { path.Add((BEncodedString)s); } var d = new BEncodedDictionary { ["path"] = path, ["length"] = (BEncodedNumber)files[i].Length }; bFiles.Add(d); totalSize += files[i].Length; } dict[new BEncodedString("files")] = bFiles; dict[new BEncodedString("name")] = new BEncodedString("test.files"); dict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength); dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20 * (totalSize / pieceLength)]); }
private static BEncodedDictionary CreateTorrent(int pieceLength) { var infoDict = new BEncodedDictionary(); infoDict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength); infoDict[new BEncodedString("pieces")] = new BEncodedString(new byte[20 * 15]); infoDict[new BEncodedString("length")] = new BEncodedNumber(15 * 256 * 1024 - 1); infoDict[new BEncodedString("name")] = new BEncodedString("test.files"); var dict = new BEncodedDictionary(); dict[new BEncodedString("info")] = infoDict; var announceTier = new BEncodedList { new BEncodedString("custom://transfers1/announce"), new BEncodedString("custom://transfers2/announce"), new BEncodedString("http://transfers3/announce") }; var announceList = new BEncodedList { announceTier }; dict[new BEncodedString("announce-list")] = announceList; return(dict); }
public void benNumberEncoding() { byte[] data = System.Text.Encoding.UTF8.GetBytes("i12345e"); BEncodedNumber number = 12345; Assert.IsTrue(Toolbox.ByteMatch(data, number.Encode())); }
public void benNumberEncoding6() { BEncodedNumber a = -123; BEncodedNumber b = BEncodedNumber.Decode <BEncodedNumber>(a.Encode()); Assert.AreEqual(a.Number, b.Number, "#1"); }
public void benNumberLengthInBytes() { int number = 1635; BEncodedNumber num = number; Assert.AreEqual(number.ToString().Length + 2, num.LengthInBytes()); }
public void BenNumberEncoding2() { byte[] data = Encoding.UTF8.GetBytes("i0e"); BEncodedNumber number = 0; Assert.Equal(3, number.LengthInBytes()); Assert.True(Toolbox.ByteMatch(data, number.Encode())); }
public void BenNumberEncoding6() { BEncodedNumber actual = -123; var number = BEncodedValue.Decode <BEncodedNumber>(actual.Encode()); Assert.AreEqual(actual.Number, number.Number, "#1"); }
protected void SetLong(BEncodedDictionary dictionary, BEncodedString key, long value) { if (dictionary == InfoDict) { CheckCanEditSecure(); } dictionary [key] = new BEncodedNumber(value); }
private void CheckContent(BEncodedDictionary dict, BEncodedString key, BEncodedNumber value) { CheckContent(dict, key); if (!dict[key].Equals(value)) { throw new TorrentException(string.Format("Invalid FastResume data. The value of '{0}' was '{1}' instead of '{2}'", key, dict[key], value)); } }
private void CheckContent(BEncodedDictionary dict, BEncodedString key, BEncodedNumber value) { CheckContent(dict, key); if (!dict[key].Equals(value)) throw new TorrentException( string.Format("Invalid FastResume data. The value of '{0}' was '{1}' instead of '{2}'", key, dict[key], value)); }
public void benNumberEncoding5() { byte[] data = System.Text.Encoding.UTF8.GetBytes("i-123e"); BEncodedNumber number = -123; Assert.AreEqual(6, number.LengthInBytes()); Assert.IsTrue(Toolbox.ByteMatch(data, number.Encode())); }
public void benNumberEncoding3() { byte[] data = System.Text.Encoding.UTF8.GetBytes("i1230e"); BEncodedNumber number = 1230; Assert.Equal(6, number.LengthInBytes()); Assert.True(Toolbox.ByteMatch(data, number.Encode())); }
public void benNumberEncoding4() { byte[] data = Encoding.UTF8.GetBytes("i-1230e"); BEncodedNumber number = -1230; Assert.AreEqual(7, number.LengthInBytes()); Assert.IsTrue(Toolbox.ByteMatch(data, number.Encode())); }
void CheckContent(BEncodedDictionary dict, BEncodedString key, BEncodedNumber value) { CheckContent(dict, key); if (!dict[key].Equals(value)) { throw new TorrentException( $"Invalid FastResume data. The value of '{key}' was '{dict[key]}' instead of '{value}'"); } }
public void BenNumberEncodingBuffered() { var data = Encoding.UTF8.GetBytes("i12345e"); BEncodedNumber number = 12345; var result = new byte[number.LengthInBytes()]; number.Encode(result, 0); Assert.IsTrue(Toolbox.ByteMatch(data, result)); }
public void benNumberEncodingBuffered() { byte[] data = System.Text.Encoding.UTF8.GetBytes("i12345e"); BEncodedNumber number = 12345; byte[] result = new byte[number.LengthInBytes()]; number.Encode(result, 0); Assert.IsTrue(Toolbox.ByteMatch(data, result)); }
public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker) { this.comparer = comparer; this.trackable = trackable; this.tracker = tracker; complete = new BEncodedNumber(0); downloaded = new BEncodedNumber(0); incomplete = new BEncodedNumber(0); peers = new Dictionary <object, Peer>(); random = new Random(); }
public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker) { _comparer = comparer; _trackable = trackable; _tracker = tracker; _complete = new BEncodedNumber(0); _downloaded = new BEncodedNumber(0); _incomplete = new BEncodedNumber(0); _peers = new Dictionary <object, Peer>(); _random = new Random(); }
public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker) { _comparer = comparer; _trackable = trackable; _tracker = tracker; _complete = new BEncodedNumber(0); _downloaded = new BEncodedNumber(0); _incomplete = new BEncodedNumber(0); _peers = new Dictionary<object, Peer>(); _random = new Random(); }
public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker) { this.comparer = comparer; this.trackable = trackable; this.tracker = tracker; complete = new BEncodedNumber(0); downloaded = new BEncodedNumber(0); incomplete = new BEncodedNumber(0); peers = new Dictionary<object, Peer>(); random = new Random(); }
private BEncodedDictionary GeneratePeersEntry() { BEncodedString encPeerId = new BEncodedString(PeerId); BEncodedString encAddress = new BEncodedString(ClientAddress.Address.ToString()); BEncodedNumber encPort = new BEncodedNumber(ClientAddress.Port); BEncodedDictionary dictionary = new BEncodedDictionary(); dictionary.Add(Tracker.PeerIdKey, encPeerId); dictionary.Add(Tracker.Ip, encAddress); dictionary.Add(Tracker.Port, encPort); return(dictionary); }
BEncodedDictionary GeneratePeersEntry() { BEncodedString encPeerId = PeerId; var encAddress = new BEncodedString(ClientAddress.Address.ToString()); var encPort = new BEncodedNumber(ClientAddress.Port); var dictionary = new BEncodedDictionary { { TrackerServer.PeerIdKey, encPeerId }, { TrackerServer.Ip, encAddress }, { TrackerServer.Port, encPort } }; return(dictionary); }
private void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces[0].Count > 0) { Announce = Announces[0][0]; } if (_getrightHttpSeeds.Count > 0) { var seedlist = new BEncodedList(); seedlist.AddRange(_getrightHttpSeeds.ConvertAll <BEncodedValue>(s => (BEncodedString)s)); torrent["url-list"] = seedlist; } var span = DateTime.Now - new DateTime(1970, 1, 1); torrent["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) { Announce = Announces [0] [0]; } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList(); seedlist.AddRange(getrightHttpSeeds.Cast <BEncodedString>()); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime(1970, 1, 1); torrent ["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) { Announce = Announces [0] [0]; } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList(); seedlist.AddRange(getrightHttpSeeds.ConvertAll <BEncodedValue> (delegate(string s) { return((BEncodedString)s); })); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); torrent ["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
private static BEncodedDictionary CreateTorrent(int pieceLength) { var infoDict = new BEncodedDictionary(); infoDict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength); infoDict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*15]); infoDict[new BEncodedString("length")] = new BEncodedNumber(15*256*1024 - 1); infoDict[new BEncodedString("name")] = new BEncodedString("test.files"); var dict = new BEncodedDictionary(); dict[new BEncodedString("info")] = infoDict; var announceTier = new BEncodedList(); announceTier.Add(new BEncodedString("custom://transfers1/announce")); announceTier.Add(new BEncodedString("custom://transfers2/announce")); announceTier.Add(new BEncodedString("http://transfers3/announce")); var announceList = new BEncodedList(); announceList.Add(announceTier); dict[new BEncodedString("announce-list")] = announceList; return dict; }
BEncodedValue ToFileInfoDict(TorrentFile file) { BEncodedDictionary fileDict = new BEncodedDictionary(); BEncodedList filePath = new BEncodedList(); string [] splittetPath = file.Path.Split(new char [] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in splittetPath) { filePath.Add(new BEncodedString(s)); } fileDict ["length"] = new BEncodedNumber(file.Length); fileDict ["path"] = filePath; if (file.MD5 != null) { fileDict ["md5sum"] = (BEncodedString)file.MD5; } return(fileDict); }
private static BEncodedDictionary GetTorrentData(IFile file) { var infoDict = new BEncodedDictionary(); infoDict[new BEncodedString("piece length")] = new BEncodedNumber(file.PieceLength); infoDict[new BEncodedString("pieces")] = new BEncodedString(Common.StringToBytes(string.Join("", file.Pieces))); infoDict[new BEncodedString("length")] = new BEncodedNumber(file.Size); infoDict[new BEncodedString("name")] = new BEncodedString(file.Name); var dict = new BEncodedDictionary(); dict[new BEncodedString("info")] = infoDict; var announceTier = new BEncodedList(); announceTier.Add(new BEncodedString(string.Format("meshwork://transfers/{0}", file.InfoHash))); var announceList = new BEncodedList(); announceList.Add(announceTier); dict[new BEncodedString("announce-list")] = announceList; return(dict); }
void AddCommonStuff (BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) Announce = Announces [0] [0]; if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList (); seedlist.AddRange (getrightHttpSeeds.Cast<BEncodedString>()); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime (1970, 1, 1); torrent ["creation date"] = new BEncodedNumber ((long) span.TotalSeconds); }
private static void AddMultiFiles(BEncodedDictionary dict, int pieceLength) { BEncodedNumber[] sizes = new BEncodedNumber[] { (int)(pieceLength * 0.44), (int)(pieceLength * 13.25), (int)(pieceLength * 23.68), (int)(pieceLength * 2.05) }; List<BEncodedList> paths = new List<BEncodedList>(); paths.Add(new BEncodedList(new BEncodedString[] { "Dir1", "File1" })); paths.Add(new BEncodedList(new BEncodedString[] { "Dir1", "Dir2", "File2" })); paths.Add(new BEncodedList(new BEncodedString[] { "File3" })); paths.Add(new BEncodedList(new BEncodedString[] { "File4" })); BEncodedList files = new BEncodedList(); for (int i = 0; i < paths.Count; i++) { BEncodedDictionary d = new BEncodedDictionary(); d["path"] = paths[i]; d["length"] = sizes[i]; files.Add(d); } dict[new BEncodedString("files")] = files; dict[new BEncodedString("name")] = new BEncodedString("test.files"); dict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength); dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20 * 40]); }
protected void SetLong(BEncodedDictionary dictionary, BEncodedString key, long value) { if (dictionary == InfoDict) CheckCanEditSecure(); dictionary[key] = new BEncodedNumber(value); }
private static BEncodedDictionary GetTorrentData(IFile file) { BEncodedDictionary infoDict = new BEncodedDictionary(); infoDict[new BEncodedString("piece length")] = new BEncodedNumber(file.PieceLength); infoDict[new BEncodedString("pieces")] = new BEncodedString(Common.StringToBytes(String.Join("", file.Pieces))); infoDict[new BEncodedString("length")] = new BEncodedNumber(file.Size); infoDict[new BEncodedString("name")] = new BEncodedString(file.Name); BEncodedDictionary dict = new BEncodedDictionary(); dict[new BEncodedString("info")] = infoDict; BEncodedList announceTier = new BEncodedList(); announceTier.Add(new BEncodedString(String.Format("meshwork://transfers/{0}", file.InfoHash))); BEncodedList announceList = new BEncodedList(); announceList.Add(announceTier); dict[new BEncodedString("announce-list")] = announceList; return dict; }
private static void AddSingleFile(BEncodedDictionary dict, int pieceLength) { BEncodedNumber[] sizes = new BEncodedNumber[] { (int)(pieceLength * 0.44) + (int)(pieceLength * 13.25)+ (int)(pieceLength * 23.68)+ (int)(pieceLength * 2.05) }; List<BEncodedList> paths = new List<BEncodedList>(); paths.Add(new BEncodedList(new BEncodedString[] { "Dir1", "File1" })); BEncodedList files = new BEncodedList(); for (int i = 0; i < paths.Count; i++) { BEncodedDictionary d = new BEncodedDictionary(); d["path"] = paths[i]; d["length"] = sizes[i]; files.Add(d); } dict[new BEncodedString("files")] = files; dict[new BEncodedString("name")] = new BEncodedString("test.files"); dict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength); dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20 * 40]); dict["url-list"] = (BEncodedString)"http://127.0.0.1:120/announce/File1.exe"; }
private void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces[0].Count > 0) Announce = Announces[0][0]; if (GetrightHttpSeeds.Count > 0) { var seedlist = new BEncodedList(); seedlist.AddRange( GetrightHttpSeeds.ConvertAll<BEncodedValue>(delegate(string s) { return (BEncodedString) s; })); torrent["url-list"] = seedlist; } var span = DateTime.Now - new DateTime(1970, 1, 1); torrent["creation date"] = new BEncodedNumber((long) span.TotalSeconds); }
private BEncodedValue ToFileInfoDict(TorrentFile file) { var fileDict = new BEncodedDictionary(); var filePath = new BEncodedList(); var splittetPath = file.Path.Split(new[] {Path.DirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries); foreach (var s in splittetPath) filePath.Add(new BEncodedString(s)); fileDict["length"] = new BEncodedNumber(file.Length); fileDict["path"] = filePath; if (file.MD5 != null) fileDict["md5sum"] = (BEncodedString) file.MD5; return fileDict; }
private void AddFiles(BEncodedDictionary dict, TorrentFile[] files) { long totalSize = piecelength - 1; var bFiles = new BEncodedList(); for (var i = 0; i < files.Length; i++) { var path = new BEncodedList(); foreach (var s in files[i].Path.Split('/')) path.Add((BEncodedString) s); var d = new BEncodedDictionary(); d["path"] = path; d["length"] = (BEncodedNumber) files[i].Length; bFiles.Add(d); totalSize += files[i].Length; } dict[new BEncodedString("files")] = bFiles; dict[new BEncodedString("name")] = new BEncodedString("test.files"); dict[new BEncodedString("piece length")] = new BEncodedNumber(piecelength); dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*(totalSize/piecelength)]); }
BEncodedValue ToFileInfoDict (TorrentFile file) { BEncodedDictionary fileDict = new BEncodedDictionary (); BEncodedList filePath = new BEncodedList (); string [] splittetPath = file.Path.Split (new char [] { '\\' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in splittetPath) filePath.Add (new BEncodedString (s)); fileDict ["length"] = new BEncodedNumber (file.Length); fileDict ["path"] = filePath; if (file.MD5 != null) fileDict ["md5sum"] = (BEncodedString) file.MD5; return fileDict; }
void AddCommonStuff (BEncodedDictionary torrent) { if (announces.Count > 0 && announces [0].Count > 0) torrent.Add ("announce", new BEncodedString (announces [0] [0])); // If there is more than one tier or the first tier has more than 1 tracker if (announces.Count > 1 || (announces.Count > 0 && announces [0].Count > 1)) { BEncodedList announceList = new BEncodedList (); for (int i = 0; i < this.announces.Count; i++) { BEncodedList tier = new BEncodedList (); for (int j = 0; j < this.announces [i].Count; j++) tier.Add (new BEncodedString (this.announces [i] [j])); announceList.Add (tier); } torrent.Add ("announce-list", announceList); } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList (); seedlist.AddRange (getrightHttpSeeds.ConvertAll<BEncodedValue> (delegate (string s) { return (BEncodedString) s; })); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime (1970, 1, 1); torrent ["creation date"] = new BEncodedNumber ((long) span.TotalSeconds); }