Example #1
0
        private bool sendEventToTracker(TorrentInfo torrentInfo, string eventType)
        {
            scrapStatsUpdated = false;
            currentTorrent = torrentInfo;
            string urlString = getUrlString(torrentInfo, eventType);
            ValueDictionary dictionary1;
            try
            {
                Uri uri = new Uri(urlString);
                TrackerResponse trackerResponse = MakeWebRequestEx(uri);
                if (trackerResponse != null && trackerResponse.Dict != null)
                {
                    dictionary1 = trackerResponse.Dict;
                    string failure = BEncode.String(dictionary1["failure reason"]);
                    if (failure.Length > 0)
                    {
                        AddLogLine("Tracker Error: " + failure);
                        if (!checkIgnoreFailureReason.Checked)
                        {
                            StopButton_Click(null, null);
                            AddLogLine("Stopped because of tracker error!!!");
                            return false;
                        }
                    }
                    else
                    {
                        foreach (string key in trackerResponse.Dict.Keys)
                        {
                            if (key != "failure reason" && key != "peers")
                            {
                                AddLogLine(key + ": " + BEncode.String(trackerResponse.Dict[key]));
                            }
                        }

                        if (dictionary1.Contains("interval"))
                        {
                            updateInterval(BEncode.String(dictionary1["interval"]));
                        }

                        if (dictionary1.Contains("complete") && dictionary1.Contains("incomplete"))
                        {
                            if (dictionary1.Contains("complete") && dictionary1.Contains("incomplete"))
                            {
                                updateScrapStats(BEncode.String(dictionary1["complete"]), BEncode.String(dictionary1["incomplete"]), "");

                                decimal leechers = BEncode.String(dictionary1["incomplete"]).ParseValidInt(0);
                                if (leechers == 0)
                                {
                                    AddLogLine("Min number of leechers reached... setting upload speed to 0");
                                    updateTextBox(uploadRate, "0");
                                    chkRandUP.Checked = false;
                                }
                            }
                        }

                        if (dictionary1.Contains("peers"))
                        {
                            haveInitialPeers = true;
                            string text4;
                            if (dictionary1["peers"] is ValueString)
                            {
                                text4 = BEncode.String(dictionary1["peers"]);
                                Encoding encoding1 = Encoding.GetEncoding(0x6faf);
                                byte[] buffer1 = encoding1.GetBytes(text4);
                                BinaryReader reader1 = new BinaryReader(new MemoryStream(encoding1.GetBytes(text4)));
                                PeerList list1 = new PeerList();
                                for (int num1 = 0; num1 < buffer1.Length; num1 += 6)
                                {
                                    list1.Add(new Peer(reader1.ReadBytes(4), reader1.ReadInt16()));
                                }

                                reader1.Close();
                                AddLogLine("peers: " + list1);
                            }
                            else if (dictionary1["peers"] is ValueList)
                            {
                                // text4 = "";
                                ValueList list2 = (ValueList)dictionary1["peers"];
                                PeerList list3 = new PeerList();
                                foreach (object obj1 in list2)
                                {
                                    if (obj1 is ValueDictionary)
                                    {
                                        ValueDictionary dictionary2 = (ValueDictionary)obj1;
                                        list3.Add(new Peer(BEncode.String(dictionary2["ip"]), BEncode.String(dictionary2["port"]), BEncode.String(dictionary2["peer id"])));
                                    }
                                }

                                AddLogLine("peers: " + list3);
                            }
                            else
                            {
                                text4 = BEncode.String(dictionary1["peers"]);
                                AddLogLine("peers(x): " + text4);
                            }
                        }
                    }

                    return false;
                }
                else
                {
                    AddLogLine("No connection in sendEventToTracker() !!!");
                    return false;
                }
            }
            catch (Exception ex)
            {
                AddLogLine("Error in sendEventToTracker(): " + ex.Message);
                return false;
            }
        }
Example #2
0
        internal void StartButton_Click(object sender, EventArgs e)
        {
            if (!StartButton.Enabled) return;
            Seeders = -1;
            Leechers = -1;
            if (trackerAddress.Text == "" || shaHash.Text == "" || txtTorrentSize.Text == "")
            {
                MessageBox.Show("Please select valid torrent file!", "RatioMaster.NET " + version + " - ERROR");
                return;
            }

            // Check rem work
            if ((string)cmbStopAfter.SelectedItem == "After time:")
            {
                int res;
                bool bCheck = int.TryParse(txtStopValue.Text, out res);
                if (bCheck == false)
                {
                    MessageBox.Show("Please select valid number for Remaning Work\n\r- 0 - default - never stop\n\r- positive number (greater than 1000)", "RatioMaster.NET " + version + " - ERROR");
                    return;
                }
                else
                {
                    if (res < 1000 && res != 0)
                    {
                        MessageBox.Show("Please select valid number for Remaning Work\n\r- 0 - default - never stop\n\r- positive number (greater than 1000)", "RatioMaster.NET " + version + " - ERROR");
                        return;
                    }
                }
            }

            updateScrapStats("", "", "");
            totalRunningTimeCounter = 0;
            timerValue.Text = "updating...";

            // txtStopValue.Text = res.ToString();
            updateProcessStarted = true;
            seedMode = false;
            requestScrap = checkRequestScrap.Checked;
            updateScrapStats("", "", "");
            StartButton.Enabled = false;
            StartButton.BackColor = SystemColors.Control;
            StopButton.Enabled = true;
            StopButton.BackColor = Color.Silver;
            manualUpdateButton.Enabled = true;
            manualUpdateButton.BackColor = Color.Silver;
            btnDefault.Enabled = false;
            interval.ReadOnly = true;
            fileSize.ReadOnly = true;
            cmbClient.Enabled = false;
            cmbVersion.Enabled = false;
            trackerAddress.ReadOnly = true;
            browseButton.Enabled = false;
            txtStopValue.Enabled = false;
            cmbStopAfter.Enabled = false;
            customPeersNum.Enabled = false;
            customPort.Enabled = false;
            currentClient = TorrentClientFactory.GetClient(GetClientName());
            currentTorrent = getCurrentTorrent();
            currentProxy = getCurrentProxy();
            AddClientInfo();
            OpenTcpListener();
            Thread myThread = new Thread(startProcess);
            myThread.Name = "startProcess() Thread";
            myThread.Start();
            serverUpdateTimer.Start();
            remWork = 0;
            if ((string)cmbStopAfter.SelectedItem == "After time:") RemaningWork.Start();
            requestScrapeFromTracker(currentTorrent);
        }
Example #3
0
        internal void btnDefault_Click(object sender, EventArgs e)
        {
            getnew = false;                
            cmbClient.SelectedItem = DefaultClient;
            cmbVersion.SelectedItem = DefaultClientVersion;

            // custom
            chkNewValues.Checked = true;
            SetCustomValues();
            customPort.Text = "";
            customPeersNum.Text = "";

            // proxy
            comboProxyType.SelectedItem = "None";
            textProxyHost.Text = "";
            textProxyPass.Text = "";
            textProxyPort.Text = "";
            textProxyUser.Text = "";

            // check
            checkRequestScrap.Checked = true;
            checkTCPListen.Checked = true;

            // Options
            TorrentInfo torrent = new TorrentInfo(0, 0);
            int defup = (int)(torrent.uploadRate / 1024);
            int defd = (int)(torrent.downloadRate / 1024);
            uploadRate.Text = defup.ToString();
            downloadRate.Text = defd.ToString();
            fileSize.Text = "0";
            interval.Text = torrent.interval.ToString();

            // Log
            checkLogEnabled.Checked = true;

            // Random speeds
            chkRandUP.Checked = true;
            chkRandDown.Checked = true;
            txtRandUpMin.Text = "1";
            txtRandUpMax.Text = "10";
            txtRandDownMin.Text = "1";
            txtRandDownMax.Text = "10";

            // Random in next update
            checkRandomDownload.Checked = false;
            checkRandomUpload.Checked = false;
            RandomUploadFrom.Text = "10";
            RandomUploadTo.Text = "50";
            RandomDownloadFrom.Text = "10";
            RandomDownloadTo.Text = "100";

            // Other
            txtStopValue.Text = "0";
        }
Example #4
0
        internal void downloadRate_TextChanged(object sender, EventArgs e)
        {
            if (downloadRate.Text == "")
            {
                currentTorrent.downloadRate = 0;
            }
            else
            {
                TorrentInfo torrent = new TorrentInfo(0, 0);
                currentTorrent.downloadRate = downloadRate.Text.ParseValidInt64(torrent.downloadRate / 1024) * 1024;
            }

            AddLogLine("Download rate changed to " + (currentTorrent.downloadRate / 1024));
        }
Example #5
0
        private TorrentInfo getCurrentTorrent()
        {
            Uri trackerUri;
            TorrentInfo torrent = new TorrentInfo(0, 0);
            try
            {
                trackerUri = new Uri(trackerAddress.Text);
            }
            catch (Exception exception1)
            {
                AddLogLine(exception1.Message);
                return torrent;
            }

            torrent.tracker = trackerAddress.Text;
            torrent.trackerUri = trackerUri;
            torrent.hash = shaHash.Text;
            torrent.uploadRate = (Int64)(uploadRate.Text.ParseValidFloat(50) * 1024);

            // uploadRate.Text = (torrent.uploadRate / (float)1024).ToString();
            torrent.downloadRate = (Int64)(downloadRate.Text.ParseValidFloat(10) * 1024);

            // downloadRate.Text = (torrent.downloadRate / (float)1024).ToString();
            torrent.interval = interval.Text.ParseValidInt(torrent.interval);
            interval.Text = torrent.interval.ToString();
            double finishedPercent = fileSize.Text.ParseDouble(0);
            if (finishedPercent < 0 || finishedPercent > 100)
            {
                AddLogLine("Finished value is invalid: " + fileSize.Text + ", assuming 0 as default value");
                finishedPercent = 0;
            }

            if (finishedPercent >= 100)
            {
                seedMode = true;
                finishedPercent = 100;
            }

            fileSize.Text = finishedPercent.ToString();
            long size = (long)currentTorrentFile.totalLength;
            if (currentTorrentFile != null)
            {
                if (finishedPercent == 0)
                {
                    torrent.totalsize = (long)currentTorrentFile.totalLength;
                }
                else if (finishedPercent == 100)
                {
                    torrent.totalsize = 0;
                }
                else
                {
                    torrent.totalsize = (long)((currentTorrentFile.totalLength * (100 - finishedPercent)) / 100);
                }
            }
            else
            {
                torrent.totalsize = 0;
            }

            torrent.left = torrent.totalsize;
            torrent.filename = torrentFile.Text;

            // deploy custom values
            torrent.port = customPort.Text.GetValueDefault(torrent.port);
            customPort.Text = torrent.port;
            torrent.key = customKey.Text.GetValueDefault(currentClient.Key);
            torrent.numberOfPeers = customPeersNum.Text.GetValueDefault(torrent.numberOfPeers);
            currentClient.Key = customKey.Text.GetValueDefault(currentClient.Key);
            torrent.peerID = customPeerID.Text.GetValueDefault(currentClient.PeerID);
            currentClient.PeerID = customPeerID.Text.GetValueDefault(currentClient.PeerID);

            // Add log info
            AddLogLine("TORRENT INFO:");
            AddLogLine("Torrent name: " + currentTorrentFile.Name);
            AddLogLine("Tracker address: " + torrent.tracker);
            AddLogLine("Hash code: " + torrent.hash);
            AddLogLine("Upload rate: " + torrent.uploadRate / 1024);
            AddLogLine("Download rate: " + torrent.downloadRate / 1024);
            AddLogLine("Update interval: " + torrent.interval);
            AddLogLine("Size: " + size / 1024);
            AddLogLine("Left: " + torrent.totalsize / 1024);
            AddLogLine("Finished: " + finishedPercent);
            AddLogLine("Filename: " + torrent.filename);
            AddLogLine("Number of peers: " + torrent.numberOfPeers);
            AddLogLine("Port: " + torrent.port);
            AddLogLine("Key: " + torrent.key);
            AddLogLine("PeerID: " + torrent.peerID + "\n" + "\n");
            return torrent;
        }
Example #6
0
        private void updateCounters(TorrentInfo torrentInfo)
        {
            try
            {
                // Random random = new Random();
                // modify Upload Rate
                uploadCount.Text = FormatFileSize((ulong)torrentInfo.uploaded);
                Int64 uploadedR = torrentInfo.uploadRate + RandomSP(txtRandUpMin.Text, txtRandUpMax.Text, chkRandUP.Checked);

                // Int64 uploadedR = torrentInfo.uploadRate + (Int64)random.Next(10 * 1024) - 5 * 1024;
                if (uploadedR < 0) { uploadedR = 0; }
                torrentInfo.uploaded += uploadedR;

                // modify Download Rate
                downloadCount.Text = FormatFileSize((ulong)torrentInfo.downloaded);
                if (!seedMode && torrentInfo.downloadRate > 0)    // dont update download stats
                {
                    Int64 downloadedR = torrentInfo.downloadRate + RandomSP(txtRandDownMin.Text, txtRandDownMax.Text, chkRandDown.Checked);

                    // Int64 downloadedR = torrentInfo.downloadRate + (Int64)random.Next(10 * 1024) - 5 * 1024;
                    if (downloadedR < 0) { downloadedR = 0; }
                    torrentInfo.downloaded += downloadedR;
                    torrentInfo.left = torrentInfo.totalsize - torrentInfo.downloaded;
                }

                if (torrentInfo.left <= 0) // either seedMode or start seed mode
                {
                    torrentInfo.downloaded = torrentInfo.totalsize;
                    torrentInfo.left = 0;
                    torrentInfo.downloadRate = 0;
                    if (!seedMode)
                    {
                        currentTorrent = torrentInfo;
                        seedMode = true;
                        temporaryIntervalCounter = 0;
                        Thread myThread = new Thread(completedProcess);
                        myThread.Name = "completedProcess() Thread";
                        myThread.Start();
                    }
                }

                torrentInfo.interval = int.Parse(interval.Text);
                currentTorrent = torrentInfo;
                double finishedPercent;
                if (torrentInfo.totalsize == 0)
                {
                    fileSize.Text = "100";
                }
                else
                {
                    // finishedPercent = (((((float)currentTorrentFile.totalLength - (float)torrentInfo.totalsize) + (float)torrentInfo.downloaded) / (float)currentTorrentFile.totalLength) * 100);
                    finishedPercent = (((currentTorrentFile.totalLength - (float)torrentInfo.left)) / ((float)currentTorrentFile.totalLength)) * 100.0;
                    fileSize.Text = (finishedPercent >= 100) ? "100" : SetPrecision(finishedPercent.ToString(), 2);
                }

                downloadCount.Text = FormatFileSize((ulong)torrentInfo.downloaded);

                // modify Ratio Lable
                if (torrentInfo.downloaded / 1024 < 100)
                {
                    lblTorrentRatio.Text = "NaN";
                }
                else
                {
                    float data = torrentInfo.uploaded / (float)torrentInfo.downloaded;
                    lblTorrentRatio.Text = SetPrecision(data.ToString(), 2);
                }
            }
            catch (Exception e)
            {
                AddLogLine(e.Message);
                SetCountersCallback d = updateCounters;
                Invoke(d, new object[] { torrentInfo });
            }
        }
Example #7
0
        internal string getScrapeUrlString(TorrentInfo torrentInfo)
        {
            string urlString;
            urlString = torrentInfo.tracker;
            int index = urlString.LastIndexOf("/");
            if (urlString.Substring(index + 1, 8).ToLower() != "announce")
            {
                return "";
            }

            urlString = urlString.Substring(0, index + 1) + "scrape" + urlString.Substring(index + 9);
            string hash = HashUrlEncode(torrentInfo.hash, currentClient.HashUpperCase);
            if (urlString.Contains("?"))
            {
                urlString = urlString + "&";
            }
            else
            {
                urlString = urlString + "?";
            }

            return (urlString + "info_hash=" + hash);
        }
Example #8
0
        private void requestScrapeFromTracker(TorrentInfo torrentInfo)
        {
            Seeders = -1;
            Leechers = -1;
            if (checkRequestScrap.Checked && !scrapStatsUpdated)
            {
                try
                {
                    string text1 = getScrapeUrlString(torrentInfo);
                    if (text1 == "")
                    {
                        AddLogLine("This tracker doesnt seem to support scrape");
                    }

                    Uri uri1 = new Uri(text1);
                    TrackerResponse response1 = MakeWebRequestEx(uri1);
                    if ((response1 != null) && (response1.Dict != null))
                    {
                        string text2 = BEncode.String(response1.Dict["failure reason"]);
                        if (text2.Length > 0)
                        {
                            AddLogLine("Tracker Error: " + text2);
                        }
                        else
                        {
                            AddLogLine("---------- Scrape Info -----------");
                            ValueDictionary dictionary1 = (ValueDictionary)response1.Dict["files"];
                            string text3 = Encoding.GetEncoding(0x4e4).GetString(currentTorrentFile.InfoHash);
                            if (dictionary1[text3].GetType() == typeof(ValueDictionary))
                            {
                                ValueDictionary dictionary2 = (ValueDictionary)dictionary1[text3];
                                AddLogLine("complete: " + BEncode.String(dictionary2["complete"]));
                                AddLogLine("downloaded: " + BEncode.String(dictionary2["downloaded"]));
                                AddLogLine("incomplete: " + BEncode.String(dictionary2["incomplete"]));
                                updateScrapStats(BEncode.String(dictionary2["complete"]), BEncode.String(dictionary2["incomplete"]), BEncode.String(dictionary2["downloaded"]));
                                decimal leechers = BEncode.String(dictionary2["incomplete"]).ParseValidInt(-1);
                                if (Leechers != -1  && (leechers == 0))
                                {
                                    AddLogLine("Min number of leechers reached... setting upload speed to 0");
                                    updateTextBox(uploadRate, "0");
                                    chkRandUP.Checked = false;
                                }
                            }
                            else
                            {
                                AddLogLine("Scrape returned : '" + ((ValueString)dictionary1[text3]).String + "'");
                            }
                        }
                    }
                }
                catch (Exception exception1)
                {
                    AddLogLine("Scrape Error: " + exception1.Message);
                }
            }
        }
Example #9
0
        private string getUrlString(TorrentInfo torrentInfo, string eventType)
        {
            // Random random = new Random();
            string uploaded = "0";
            if (torrentInfo.uploaded > 0)
            {
                torrentInfo.uploaded = RoundByDenominator(torrentInfo.uploaded, 0x4000);
                uploaded = torrentInfo.uploaded.ToString();

                // uploaded = Convert.ToString(torrentInfo.uploaded + random.Next(1, 1023));
            }

            string downloaded = "0";
            if (torrentInfo.downloaded > 0)
            {
                torrentInfo.downloaded = RoundByDenominator(torrentInfo.downloaded, 0x10);
                downloaded = torrentInfo.downloaded.ToString();

                // downloaded = Convert.ToString(torrentInfo.downloaded + random.Next(1, 1023));
            }

            if (torrentInfo.left > 0)
            {
                torrentInfo.left = torrentInfo.totalsize - torrentInfo.downloaded;
            }

            string left = torrentInfo.left.ToString();
            string key = torrentInfo.key;
            string port = torrentInfo.port;
            string peerID = torrentInfo.peerID;
            string urlString;
            urlString = torrentInfo.tracker;
            if (urlString.Contains("?"))
            {
                urlString += "&";
            }
            else
            {
                urlString += "?";
            }

            if (eventType.Contains("started")) urlString = urlString.Replace("&natmapped=1&localip={localip}", "");
            if (!eventType.Contains("stopped")) urlString = urlString.Replace("&trackerid=48", "");
            urlString += currentClient.Query;
            urlString = urlString.Replace("{infohash}", HashUrlEncode(torrentInfo.hash, currentClient.HashUpperCase));
            urlString = urlString.Replace("{peerid}", peerID);
            urlString = urlString.Replace("{port}", port);
            urlString = urlString.Replace("{uploaded}", uploaded);
            urlString = urlString.Replace("{downloaded}", downloaded);
            urlString = urlString.Replace("{left}", left);
            urlString = urlString.Replace("{event}", eventType);
            if ((torrentInfo.numberOfPeers == "0") && !eventType.ToLower().Contains("stopped")) torrentInfo.numberOfPeers = "200";
            urlString = urlString.Replace("{numwant}", torrentInfo.numberOfPeers);
            urlString = urlString.Replace("{key}", key);
            urlString = urlString.Replace("{localip}", Functions.GetIp());
            return urlString;
        }
Example #10
0
 internal void deployDefaultValues()
 {
     TorrentInfo torrent = new TorrentInfo(0, 0);
     trackerAddress.Text = torrent.tracker;
     shaHash.Text = torrent.hash;
     long num1 = torrent.uploadRate / 1024;
     uploadRate.Text = num1.ToString();
     long num2 = torrent.downloadRate / 1024;
     downloadRate.Text = num2.ToString();
     interval.Text = torrent.interval.ToString();
     comboProxyType.SelectedItem = "None";
 }