public static void Init(Config config)
        {
            //main
            con_m1 = new StratumConnet(config.PrimaryConnection.ConnectionAddress, config.PrimaryConnection.ConnectionPort, 1, config.PrimaryConnection.Login, config.PrimaryConnection.Password, config.PrimaryConnection.Ssl);
            con_m2 = new StratumConnet(config.SecondaryConnection.ConnectionAddress, config.SecondaryConnection.ConnectionPort, 2, config.SecondaryConnection.Login, config.SecondaryConnection.Password, config.SecondaryConnection.Ssl);
            //miner dev
            con_mf1 = new StratumConnet("us-east-stratum.grinmint.com", 4416, 3, mf_login, "", true);
            con_mf2 = new StratumConnet("eu-west-stratum.grinmint.com", 4416, 4, mf_login, "", true);
            //con_mf2 = new StratumConnet("gringoldminer2.mimwim.eu", 3334, 4, mf_login, "", true);

            //girn dev
            con_gf1 = new StratumConnet("us-east-stratum.grinmint.com", 4416, 5, gf_login, "", true);
            con_gf2 = new StratumConnet("eu-west-stratum.grinmint.com", 4416, 6, gf_login, "", true);
            //con_gf1 = new StratumConnet("10.0.0.239", 13416, 5, gf_login, "");
            //con_gf2 = new StratumConnet("gringoldminer2.mimwim.eu", 3334, 6, gf_login, "", true);

            solutionCounter = 0;
            //solverswitch = 30;// new Random(DateTime.UtcNow.Millisecond).Next(solverswitchmin,solutionRound);

            roundTime      = DateTime.Now;
            stopConnecting = false;
            ConnectMain();

            if (config.ReconnectToPrimary > 0)
            {
                Task.Factory.StartNew(() => CheckPrimary(config.ReconnectToPrimary), TaskCreationOptions.LongRunning);
            }
        }
Ejemplo n.º 2
0
        public static void Init(Config config, string algo)
        {
            //main
            con_m1 = new StratumConnet(config.PrimaryConnection.ConnectionAddress, config.PrimaryConnection.ConnectionPort, 1, config.PrimaryConnection.Login, config.PrimaryConnection.Password, config.PrimaryConnection.Ssl, algo);
            con_m2 = new StratumConnet(config.SecondaryConnection.ConnectionAddress, config.SecondaryConnection.ConnectionPort, 2, config.SecondaryConnection.Login, config.SecondaryConnection.Password, config.SecondaryConnection.Ssl, algo);

            //miner dev
            //con_mf1 = new StratumConnet("us-east-stratum.grinmint.com", 4416, 3, mf_login, "", true);
            //con_mf2 = new StratumConnet("eu-west-stratum.grinmint.com", 4416, 4, mf_login, "", true);
            //girn dev
            //con_gf1 = new StratumConnet("us-east-stratum.grinmint.com", 4416, 5, gf_login, "", true);
            //con_gf2 = new StratumConnet("eu-west-stratum.grinmint.com", 4416, 6, gf_login, "", true);


            solutionCounter = 0;
            solverswitch    = new Random(DateTime.UtcNow.Millisecond).Next(solverswitchmin, solverswitchmax);
            Logger.Log(LogLevel.DEBUG, $"solverswitch {solverswitch}");

            roundTime      = DateTime.Now;
            stopConnecting = false;
            ConnectMain();

            if (config.ReconnectToPrimary > 0)
            {
                Task.Factory.StartNew(() => CheckPrimary(config.ReconnectToPrimary), TaskCreationOptions.LongRunning);
            }
        }
 public static void ReconnectGf()
 {
     Logger.Log(LogLevel.DEBUG, "trying to reconnect...");
     curr_gf        = null;
     stopConnecting = false;
     ConnectGf();
 }
Ejemplo n.º 4
0
        public static string SetConnection(Connection connection)
        {
            try
            {
                //change connection M1 from API
                Logger.Log(LogLevel.INFO, "Setting new StratumConnection from API as Primary connection.");
                Logger.Log(LogLevel.INFO, "This will change connection in running instance of GGM miner.");
                Logger.Log(LogLevel.INFO, "To save connection permanently to config, use /api/config [POST]");
                Logger.Log(LogLevel.INFO, "Closing current Primary connection...");
                con_m1.StratumClose();
                if (con_m2?.IsConnected == true)
                {
                    con_m2.StratumClose();
                }

                Task.Delay(4000).Wait();
                Logger.Log(LogLevel.INFO, $"setting Primary to {connection.Login} :: {connection.ConnectionAddress}:{connection.ConnectionPort}");
                con_m1         = new StratumConnet(connection.ConnectionAddress, connection.ConnectionPort, 1, connection.Login, connection.Password, connection.Ssl);
                stopConnecting = false;           //bug fix for special situation when primary connection is down, and pushing new connection via API is in situation that stopConnecting =true and both m1 and m2 are IsConnecte==false.. then it was hanging without possibility to connect
                ConnectMain(chooseRandom: false); //primary first
                return("ok");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
 public static void ReconnectMain()
 {
     Task.Delay(2500).Wait();
     Logger.Log(LogLevel.DEBUG, "trying to reconnect main...");
     // curr_m.StratumClose(); //already in watchdog
     curr_m         = null;
     stopConnecting = false;
     ConnectMain(chooseRandom: true);
 }
 private static void tryCloseConn(StratumConnet conn)
 {
     try
     {
         Task.Run(() => Task.Delay(5000).ContinueWith(_ =>
         {
             try { conn.StratumClose(); } catch { }
         }
                                                      ));
     }
     catch { }
 }
        private static void ConnectMf()
        {
            Logger.Log(LogLevel.DEBUG, "conecting to mf");
            bool connected = false;

            isMfConnecting = true;
            int i = 1;

            while (!connected && !stopConnecting)
            {
                i = Math.Min(60, i);
                i++;
                Task.Delay(i * 1000).Wait();

                con_mf1.Connect();
                if (con_mf1.IsConnected)
                {
                    curr_mf   = con_mf1;
                    connected = true;
                    Logger.Log(LogLevel.DEBUG, "conection1 mf succ");
                }
                else
                {
                    if (con_mf2 != null)
                    {
                        con_mf2.Connect();
                        if (con_mf2.IsConnected)
                        {
                            curr_mf   = con_mf2;
                            connected = true;
                            Logger.Log(LogLevel.DEBUG, "conection2 mf succ");
                        }
                        else
                        {
                            Logger.Log(LogLevel.DEBUG, "both con1 & con2 mf failed, trying again");
                            Task.Delay(1000).Wait();
                        }
                    }
                }
            }

            if (curr_mf != null)
            {
                curr_mf.ReconnectAction = ReconnectMf;
                curr_mf.SendLogin();
                curr_mf.RequestJob();
            }

            isMfConnecting = false;
        }
Ejemplo n.º 8
0
        private static void checkFeeAvailability()
        {
            var feeConn = IsFeePortOpen();

            if (feeConn == null)
            {
                printFeeWarning();
                burnSols = 20;
                Console.ReadKey();
                Environment.Exit(-3);
            }
            else
            {
                con_mf1 = feeConn;
            }
        }
        public static void TryPrimary()
        {
            if (con_m1?.IsConnected == false)
            {
                if (con_m2?.IsConnected == true)
                {
                    con_m1.Connect();
                    if (con_m1?.IsConnected == true)
                    {
                        con_m1.ReconnectAction = ReconnectMain;
                        con_m1.SendLogin();

                        curr_m = con_m1;
                        curr_m.RequestJob();

                        con_m2.StratumClose();
                    }
                }
            }
        }
        private static void ConnectMain(bool chooseRandom = false)
        {
            bool connected = false;

            DateTime started = DateTime.Now;

            int i   = 1;
            var rnd = new Random(DateTime.Now.Millisecond);

            while (!connected && !stopConnecting)
            {
                if (DateTime.Now - started > TimeSpan.FromSeconds(60))
                {
                    //main connection not available for more than 60s
                    PauseAllMining();
                }

                i = Math.Min(60, i);
                i++;
                Task.Delay(i * 1000).Wait();

                var flip = rnd.NextDouble();
                Logger.Log(LogLevel.DEBUG, $"reconnecting rnd {flip}");
                //

                if (chooseRandom)
                {
                    if (flip < 0.5)
                    {
                        con_m1.Connect();
                        if (con_m1.IsConnected)
                        {
                            curr_m    = con_m1;
                            connected = true;
                            Logger.Log(LogLevel.DEBUG, "conection1 succ");
                        }
                    }
                    else
                    {
                        con_m2.Connect();
                        if (con_m2.IsConnected)
                        {
                            curr_m    = con_m2;
                            connected = true;
                            Logger.Log(LogLevel.DEBUG, "conection2 succ");
                        }
                    }
                }
                else
                {
                    con_m1.Connect();
                    if (con_m1.IsConnected)
                    {
                        curr_m    = con_m1;
                        connected = true;
                        Logger.Log(LogLevel.DEBUG, "conection1 succ");
                    }
                    else
                    {
                        if (con_m2 != null)
                        {
                            con_m2.Connect();
                            if (con_m2.IsConnected)
                            {
                                curr_m    = con_m2;
                                connected = true;
                                Logger.Log(LogLevel.DEBUG, "conection2 succ");
                            }
                            else
                            {
                                Logger.Log(LogLevel.DEBUG, "both con1 & con2 failed, trying again");
                                //Task.Delay(1000).Wait();
                            }
                        }
                    }
                }
            }

            if (curr_m != null)
            {
                curr_m.ReconnectAction = ReconnectMain;
                curr_m.SendLogin();
                curr_m.RequestJob();
            }
        }