protected virtual async Task ReceiveScrape(UdpClient client, ScrapeMessage scrapeMessage, IPEndPoint remotePeer) { BEncodedDictionary val = Handle(getCollection(scrapeMessage), remotePeer.Address, true); UdpTrackerMessage m; byte[] data; if (val.ContainsKey(TrackerRequest.FailureKey)) { m = new ErrorMessage(scrapeMessage.TransactionId, val[TrackerRequest.FailureKey].ToString()); } else { var scrapes = new List <ScrapeDetails> (); foreach (KeyValuePair <BEncodedString, BEncodedValue> keypair in val) { var dict = (BEncodedDictionary)keypair.Value; int seeds = 0; int leeches = 0; int complete = 0; foreach (KeyValuePair <BEncodedString, BEncodedValue> keypair2 in dict) { switch (keypair2.Key.Text) { case "complete": //The current number of connected seeds seeds = Convert.ToInt32(keypair2.Value.ToString()); break; case "downloaded": //The total number of completed downloads complete = Convert.ToInt32(keypair2.Value.ToString()); break; case "incomplete": leeches = Convert.ToInt32(keypair2.Value.ToString()); break; } } var sd = new ScrapeDetails(seeds, leeches, complete); scrapes.Add(sd); if (scrapes.Count == 74)//protocole do not support to send more than 74 scrape at once... { m = new ScrapeResponseMessage(scrapeMessage.TransactionId, scrapes); data = m.Encode(); await client.SendAsync(data, data.Length, remotePeer); scrapes.Clear(); } } m = new ScrapeResponseMessage(scrapeMessage.TransactionId, scrapes); } data = m.Encode(); await client.SendAsync(data, data.Length, remotePeer); }
protected virtual void ReceiveScrape(ScrapeMessage scrapeMessage) { BEncodedDictionary val = Handle(getCollection(scrapeMessage), endpoint.Address, true); UdpTrackerMessage m; byte[] data; if (val.ContainsKey(RequestParameters.FailureKey)) { m = new ErrorMessage(scrapeMessage.TransactionId, val[RequestParameters.FailureKey].ToString()); } else { List <ScrapeDetails> scrapes = new List <ScrapeDetails>(); foreach (KeyValuePair <BEncodedString, BEncodedValue> keypair in val) { BEncodedDictionary dict = (BEncodedDictionary)keypair.Value; int seeds = 0; int leeches = 0; int complete = 0; foreach (KeyValuePair <BEncodedString, BEncodedValue> keypair2 in dict) { switch (keypair2.Key.Text) { case "complete": //The current number of connected seeds seeds = Convert.ToInt32(keypair2.Value.ToString()); break; case "downloaded": //The total number of completed downloads complete = Convert.ToInt32(keypair2.Value.ToString()); break; case "incomplete": leeches = Convert.ToInt32(keypair2.Value.ToString()); break; } } ScrapeDetails sd = new ScrapeDetails(seeds, leeches, complete); scrapes.Add(sd); if (scrapes.Count == 74)//protocole do not support to send more than 74 scrape at once... { m = new ScrapeResponseMessage(scrapeMessage.TransactionId, scrapes); data = m.Encode(); #if NETSTANDARD1_5 listener.SendAsync(data, data.Length, endpoint); #else listener.Send(data, data.Length, endpoint); #endif scrapes.Clear(); } } m = new ScrapeResponseMessage(scrapeMessage.TransactionId, scrapes); } data = m.Encode(); #if NETSTANDARD1_5 listener.SendAsync(data, data.Length, endpoint); #else listener.Send(data, data.Length, endpoint); #endif }