Esempio n. 1
0
        public string GetContentId(LoadRespData resp)
        {
            var cmd = string.Format("GETCID checksum={0} infohash={1} developer={2} affiliant={3} zoneid={4}", resp.CheckSum, resp.InfoHash, 0, 0, 0);

            SendMessage(cmd);
            bool   exit  = false;
            int    cwait = 0;
            string res   = string.Empty;

            try
            {
                while (!exit)
                {
                    Thread.Sleep(24);
                    cwait += 24;
                    if (cwait >= 1000)
                    {
                        break;
                    }
                    lock (_messagePool)
                    {
                        if (!_messagePool.Any())
                        {
                            continue;
                        }
                        foreach (var msg in _messagePool)
                        {
                            if (msg.Text.Substring(0, 2) == "##")
                            {
                                exit = true;
                                res  = msg.Text.Substring(2);
                            }
                        }
                        _messagePool.Clear();
                    }
                }
            }
            catch (Exception)
            {
            }
            return(res);
        }
Esempio n. 2
0
        public static TSMessage Construct(string msg)
        {
            var tsmsg = new TSMessage {
                Text = msg
            };
            var amsg = msg.Split(" ".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            tsmsg.Type = amsg[0];
            if (tsmsg.Type == TorrentStream.MSG_HELLOTS)
            {
                if (amsg.Count() == 2)
                {
                    tsmsg.Parameters = new Dictionary <string, string>();
                    var aprms = amsg[1].Split("=".ToCharArray(), StringSplitOptions.None);
                    tsmsg.Parameters.Add(aprms[0], aprms[1]);
                }
            }
            else if (tsmsg.Type == TorrentStream.MSG_START)
            {
                tsmsg.Parameters = new Dictionary <string, string> {
                    { "url", amsg[1].Split("=".ToCharArray())[1].Replace("%3A", ":") }
                };
                for (int i = 2; i < amsg.Length; i++)
                {
                    var prm = amsg[i].Split("=".ToCharArray());
                    tsmsg.Parameters.Add(prm[0], prm[1]);
                }
            }
            else if (tsmsg.Type == TorrentStream.MSG_LOADRESP)
            {
                tsmsg.Parameters = new Dictionary <string, string>();
                DataContractJsonSerializer serial = new DataContractJsonSerializer(typeof(LoadRespData));
                var          data = msg.Split(" ".ToArray(), 3);
                MemoryStream ms   = new MemoryStream(Encoding.UTF8.GetBytes(data[2]));
                LoadRespData resp = (LoadRespData)serial.ReadObject(ms);
                tsmsg.Parameters.Add("key", data[1]);
                tsmsg.InnerData = resp;
            }
            return(tsmsg);
        }
Esempio n. 3
0
        public LoadRespData ReadTorrent(string file, SourceType source)
        {
            if (source == SourceType.Torrent)
            {
                if (string.IsNullOrEmpty(file))
                {
                    P2pProxyApp.Log.Write("Не верная ссылка на торрент", TypeMessage.Error);
                    throw new Exception("Не верная ссылка на торрент");
                }
                file = new Uri(file).ToString();
            }
            Random rand = new Random(DateTime.Now.Millisecond);
            string req  = String.Format("LOADASYNC {2} {0} {1}", source.ToString().ToUpper(), file, rand.Next(100000, 200000));

            if (source != SourceType.ContentId)
            {
                req = req + " 0 0 0";
            }
            req = req.Replace("CONTENTID", "PID");
            //SendMessage("LOADASYNC 126500 PID 1ccf192064ee2d95e91a79f91c6097273d582827");
            SendMessage(req.Replace("CONTENTID", "PID"));
            int          cwait = 0;
            bool         exit  = false;
            LoadRespData files = null;

            try
            {
                while (!exit)
                {
                    Thread.Sleep(24);
                    cwait += 24;
                    if (cwait >= 1000)
                    {
                        break;
                    }
                    lock (_messagePool)
                    {
                        if (!_messagePool.Any())
                        {
                            continue;
                        }
                        foreach (var msg in _messagePool)
                        {
                            if (msg.Type == MSG_LOADRESP)
                            {
                                exit = true;
                                var data = (msg.InnerData as LoadRespData);
                                if (data == null)
                                {
                                    break;
                                }
                                files = msg.InnerData as LoadRespData;
                                break;
                                //resp.files.AddRange(new String[(msg.InnerData as LoadRespData).Files.Count]);
                                //foreach (var f in (msg.InnerData as LoadRespData).Files)
                                //    resp.files[(int)f[1]] = f[0].ToString();
                            }
                        }
                        _messagePool.Clear();
                    }
                }
            }
            catch (Exception)
            {
            }

            return(files);
        }
Esempio n. 4
0
        public string GetContentId(LoadRespData resp)
        {
            var cmd = string.Format("GETCID checksum={0} infohash={1} developer={2} affiliant={3} zoneid={4}", resp.CheckSum, resp.InfoHash, 0, 0, 0);
            SendMessage(cmd);
            bool exit = false;
            int cwait = 0;
            string res = string.Empty;
            try
            {
                while (!exit)
                {
                    Thread.Sleep(24);
                    cwait += 24;
                    if (cwait >= 1000)
                        break;
                    lock (_messagePool)
                    {
                        if (!_messagePool.Any())
                            continue;
                        foreach (var msg in _messagePool)
                        {
                            if (msg.Text.Substring(0, 2) == "##")
                            {
                                exit = true;
                                res = msg.Text.Substring(2);
                            }
                        }
                        _messagePool.Clear();
                    }

                }
            }
            catch (Exception)
            {
            }
            return res;
        }