Inheritance: UdpTrackerMessage
コード例 #1
0
 protected override void ReceiveError(ErrorMessage errorMessage)
 {
     if (!IgnoreErrors)
         base.ReceiveError(errorMessage);
 }
コード例 #2
0
ファイル: UdpListener.cs プロジェクト: mrscylla/octotorrent
 protected virtual void ReceiveError(ErrorMessage errorMessage)
 {
     throw new ProtocolException(String.Format("ErrorMessage from :{0}",endpoint.Address));
 }
コード例 #3
0
ファイル: UdpListener.cs プロジェクト: mrscylla/octotorrent
        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();
                        listener.Send(data, data.Length, endpoint);
                        scrapes.Clear();
                    }
                }
                m = new ScrapeResponseMessage(scrapeMessage.TransactionId, scrapes);
            }
            data = m.Encode();
            listener.Send(data, data.Length, endpoint);
        }
コード例 #4
0
ファイル: UdpListener.cs プロジェクト: mrscylla/octotorrent
        //QUICKHACK: format bencoded val and get it back wereas must refactor tracker system to have more generic object...
        protected virtual void ReceiveAnnounce(AnnounceMessage announceMessage)
        {
            UdpTrackerMessage m;
            BEncodedDictionary dict = Handle(getCollection(announceMessage), endpoint.Address, false);
            if (dict.ContainsKey(RequestParameters.FailureKey))
            {
                m = new ErrorMessage(announceMessage.TransactionId, dict[RequestParameters.FailureKey].ToString());
            }
            else
            {
                TimeSpan interval = TimeSpan.Zero;
                int leechers = 0;
                int seeders = 0;
                var peers = new List<Client.Peer>();
                foreach (var keypair in dict)
                {
                    switch (keypair.Key.Text)
                    {
                        case ("complete"):
                            seeders = Convert.ToInt32(keypair.Value.ToString());//same as seeder?
                            break;

                        case ("incomplete"):
                            leechers = Convert.ToInt32(keypair.Value.ToString());//same as leecher?
                            break;

                        case ("interval"):
                            interval = TimeSpan.FromSeconds(int.Parse(keypair.Value.ToString()));
                            break;

                        case ("peers"):
                            if (keypair.Value is BEncodedList)          // Non-compact response
                                peers.AddRange(Client.Peer.Decode((BEncodedList)keypair.Value));
                            else if (keypair.Value is BEncodedString)   // Compact response
                                peers.AddRange(Client.Peer.Decode((BEncodedString)keypair.Value));
                            break;
                    }
                }
                m = new AnnounceResponseMessage(announceMessage.TransactionId, interval, leechers, seeders, peers);
            }
            byte[] data = m.Encode();
            listener.Send(data, data.Length, endpoint);
        }