Beispiel #1
0
        public void UpdatePoolFeature_EnableMissingFeature_Succeeds()
        {
            // arrange
            string host     = "google.com";
            string fragment = PoolFeatures.XNSubFragment;
            bool   enabled  = true;

            // act
            string result = PoolFeatures.UpdatePoolFeature(host, fragment, enabled);

            // assert
            Assert.AreEqual("google.com/#xnsub", result);
        }
Beispiel #2
0
        public void UpdatePoolFeature_EnableFeature_RemovesDupeSlashes()
        {
            // arrange
            string host     = "google.com/";
            string fragment = PoolFeatures.XNSubFragment;
            bool   enabled  = true;

            // act
            string result = PoolFeatures.UpdatePoolFeature(host, fragment, enabled);

            // assert
            Assert.AreEqual("google.com/#xnsub", result);
        }
Beispiel #3
0
        public void UpdatePoolFeature_EnableMultipleFeatures_C_Succeeds()
        {
            // arrange
            string host    = "google.com/#xnsub/#skipcbcheck";
            bool   enabled = true;

            // act
            string result = PoolFeatures.UpdatePoolFeature(host, PoolFeatures.XNSubFragment, enabled);

            result = PoolFeatures.UpdatePoolFeature(result, PoolFeatures.SkipCBCheckFragment, enabled);

            // assert
            Assert.AreEqual("google.com/#xnsub/#skipcbcheck", result);
        }
Beispiel #4
0
        public Process Launch(string reason = "")
        {
            bool redirectOutput      = false;
            bool ensureProcessStarts = true;

            //otherwise cgminer output shows under *nix in the terminal
            //DONT do it for Windows though or cgminer will close after opening

            //commented out for now - seems to eventually cause issues under .nix too
            //the miner keeps mining but Accepted shares stop updating
            //if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix)
            //    redirectOutput = true;

            string arguments = minerConfiguration.LaunchArguments;

            string serialArg = String.Empty;

            if (!legacyApi)
            {
                serialArg = MinerParameter.ScanSerialNoAuto;

                arguments = String.Format("{0} {1}", arguments, serialArg);

                if (minerConfiguration.StratumProxy)
                {
                    if (minerConfiguration.StratumProxyPort > 0)
                    {
                        arguments = String.Format("{0} --http-port {1}", arguments, minerConfiguration.StratumProxyPort);
                    }
                    if (minerConfiguration.StratumProxyStratumPort > 0)
                    {
                        arguments = String.Format("{0} --stratum-port {1}", arguments, minerConfiguration.StratumProxyStratumPort);
                    }
                }
            }

            IEnumerable <MiningPool> validPools = minerConfiguration.Pools
                                                  .Where(p => !String.IsNullOrEmpty(p.Host) &&
                                                         !String.IsNullOrEmpty(p.Username));

            foreach (MiningPool pool in validPools)
            {
                string argument;

                string poolUri;
                try
                {
                    poolUri = pool.BuildPoolUri();
                }
                catch (UriFormatException ex)
                {
                    throw new MinerLaunchException(String.Format("The '{0}' pool host '{1}' is not a valid URI.", this.minerConfiguration.CoinName, pool.Host)
                                                   + Environment.NewLine + Environment.NewLine + ex.Message);
                }

                //automatically add the #xnsub & #skipcbcheck fragments to pool URIs when mining NiceHash with BFGMiner
                if (!legacyApi && pool.Host.ToLower().Contains("nicehash.com"))
                {
                    poolUri = PoolFeatures.UpdatePoolFeature(poolUri, PoolFeatures.XNSubFragment, true);
                    poolUri = PoolFeatures.UpdatePoolFeature(poolUri, PoolFeatures.SkipCBCheckFragment, true);
                }

                if (pool.QuotaEnabled)
                {
                    argument = string.Format("--quota \"{2};{0}\" -u {1}", poolUri, pool.Username, pool.Quota);
                }
                else
                {
                    argument = string.Format("-o {0} -u {1}", poolUri, pool.Username);
                }

                //some pools do not require a password
                //but the miners require some password
                string password = "******"\"";
                if (!String.IsNullOrEmpty(pool.Password))
                {
                    password = pool.Password;
                }

                argument = String.Format("{0} -p {1}", argument, password);

                if (!String.IsNullOrEmpty(pool.MinerFlags))
                {
                    argument = String.Format("{0} {1}", argument, pool.MinerFlags);
                }

                arguments = string.Format("{0} {1}", arguments, argument);
            }

            if (!legacyApi)
            {
                if (minerConfiguration.DeviceDescriptors.Exists(d => d.Kind == DeviceKind.GPU))
                {
                    arguments = String.Format("{0} {1}", arguments, MinerParameter.ScanSerialOpenCL);
                }

                if (minerConfiguration.DeviceDescriptors.Exists(d => d.Kind == DeviceKind.CPU))
                {
                    arguments = String.Format("{0} {1}", arguments, MinerParameter.ScanSerialCpu);
                }
            }

            if (legacyApi)
            {
                //AZNSGMiner doesn't understand -d 1 -d 2 -d 3, we need to use -d 1,2,3
                arguments = string.Format("{0} -d {1}", arguments, String.Join(",", minerConfiguration.DeviceDescriptors.Select(dd => dd.RelativeIndex.ToString()).ToArray()));
            }
            else
            {
                foreach (DeviceDescriptor deviceDescriptor in minerConfiguration.DeviceDescriptors)
                {
                    if (deviceDescriptor.Kind == DeviceKind.GPU)
                    {
                        arguments = string.Format("{0} -d OCL{1}", arguments, deviceDescriptor.RelativeIndex);
                    }
                    else if (deviceDescriptor.Kind == DeviceKind.CPU)
                    {
                        arguments = string.Format("{0} -d CPU{1}", arguments, deviceDescriptor.RelativeIndex);
                    }
                    else if (deviceDescriptor.Kind == DeviceKind.USB)
                    {
                        //hashbuster may not have path - but does in later versions of bfgminer
                        //leaving as a code-path (for now)
                        if (deviceDescriptor.Driver.Equals("hashbusterusb", StringComparison.OrdinalIgnoreCase))
                        {
                            //FIXED IN BFGMINER 3.9
                            //SAFE TO REMOVE THIS CODE PATH ONCE 3.9 HAS BEEN RELEASED & STABLE

                            //hard-coded implementation for now until the bfgminer implementation is a bit more stable
                            //3.8.1 introduced a Path for HashBuster Micro, but the path is not usable with -S -d
                            arguments = string.Format("{0} -S {1}:auto -d {1}@{2}", arguments, deviceDescriptor.Driver, deviceDescriptor.Serial);
                        }
                        else if (String.IsNullOrEmpty(deviceDescriptor.Path))
                        {
                            arguments = string.Format("{0} -S {1}:{2} -d {1}@{2}", arguments, deviceDescriptor.Driver, deviceDescriptor.Serial);
                        }
                        else
                        {
                            arguments = string.Format("{0} -S {1}:{2} -d {1}@{2}", arguments, deviceDescriptor.Driver, deviceDescriptor.Path);
                        }
                    }
                }
            }

            string minerName = Path.GetFileName(Path.GetDirectoryName(minerConfiguration.ExecutablePath));

            if (minerConfiguration.Algorithm.MinerArguments.ContainsKey(minerName))
            {
                arguments = String.Format("{0} {1}", minerConfiguration.Algorithm.MinerArguments[minerName], arguments.TrimStart());
            }

            if (minerConfiguration.ApiListen)
            {
                const string localIp       = "127.0.0.1";
                string       allowedApiIps = minerConfiguration.AllowedApiIps;

                if (String.IsNullOrEmpty(allowedApiIps))
                {
                    allowedApiIps = String.Empty;
                }
                else
                {
                    allowedApiIps = allowedApiIps.Replace(" ", "");
                }

                if (!allowedApiIps.Contains(localIp))
                {
                    allowedApiIps = String.Format("{0},{1}", localIp, allowedApiIps);
                }
                arguments = string.Format("{0} --api-listen --api-port {1} --api-allow W:{2}", arguments,
                                          minerConfiguration.ApiPort, allowedApiIps);
            }

            //don't mine with GPUs if this is solely a stratum instance
            if (minerConfiguration.StratumProxy && (minerConfiguration.DeviceDescriptors.Count == 0))
            {
                minerConfiguration.DisableGpu = true;
            }

            //required to run from inside an .app package on OS X
            //also required under Windows to avoid "initscr(): Unable to create SP"
            arguments = arguments + " -T";

            //limits console output
            //we don't read the console output anyway and this is proven to improve performance (at least with very fast devices, e.g. KnC)
            arguments = arguments + " -q";

            //specify a value for --log so we can depend on the API RPC current hashrate key
            arguments = String.Format("{0} --log {1}", arguments, minerConfiguration.LogInterval);

            if (legacyApi)
            {
                //remove --set-device ABC and --set ABC
                arguments = RemoveArgumentPairs(arguments, "--set-device");
                arguments = RemoveArgumentPairs(arguments, "--set");
            }

            Process process = StartMinerProcess(arguments, redirectOutput, ensureProcessStarts, reason);

            return(process);
        }
 private void UpdatePoolFeature(string fragment, bool enabled)
 {
     hostEdit.Text = PoolFeatures.UpdatePoolFeature(hostEdit.Text, fragment, enabled);
 }