コード例 #1
0
ファイル: Handler.cs プロジェクト: tr002196/GrinbleMiner
        private static void UpdateJobMonitor()
        {
            Stratum currentStratum = null;
            var     validUntil     = DateTime.MaxValue;

            while (true)
            {
                validUntil = DateTime.Now.AddMinutes(-MaxJobValidMinutes);
                try
                {
                    currentStratum = GetCurrentStratum();
                    var newJob = currentStratum?.CurrentJob;

                    if (newJob == null)
                    {
                        Log(Level.Info, string.Format("Waiting for new job...."));
                        Task.Delay(1000).Wait();
                    }
                    else if (newJob.Timestamp < validUntil)
                    {
                        Log(Level.Info, string.Format("Current job expired..."));

                        CurrentJob = null;
                        OnNewJob?.Invoke(currentStratum, CurrentJob);

                        currentStratum.Close();
                        currentStratum.ConnectAndOpen();

                        while (!currentStratum.IsConnected || currentStratum.IsInvalidConnection)
                        {
                            if (GetCurrentStratum() != currentStratum)
                            {
                                continue;
                            }

                            currentStratum.Close();
                            currentStratum.ConnectAndOpen();
                        }

                        if (GetCurrentStratum() != currentStratum)
                        {
                            continue;
                        }
                        currentStratum.RequestJobTemplate();
                    }
                    else if (CurrentJob == null || CurrentJob.JobID != newJob.JobID || CurrentJob.Height != newJob.Height)
                    {
                        CurrentJob = newJob;
                        OnNewJob?.Invoke(currentStratum, CurrentJob);
                    }
                }
                catch (Exception ex) { Log(ex); }

                Task.Delay(100).Wait();
            }
        }
コード例 #2
0
ファイル: Handler.cs プロジェクト: tr002196/GrinbleMiner
        public static void Initialize(Config settings)
        {
            CheckSettings(settings);

            MinerStratum    = new Stratum(FeeCategory.Miner, settings.Connections);
            GrinDevStratum  = new Stratum(FeeCategory.GrinDev, DevFee.GrinDevConnections);
            MinerDevStratum = new Stratum(FeeCategory.MinerDev, DevFee.MinerDevConnections);

            Task.WaitAll(new Task[]
            {
                Task.Factory.StartNew(() => MinerDevStratum.ConnectAndOpen()),
                Task.Factory.StartNew(() => GrinDevStratum.ConnectAndOpen()),
                Task.Factory.StartNew(() => MinerStratum.ConnectAndOpen())
            });

            Task.WaitAll(new Task[]
            {
                Task.Factory.StartNew(() => { if (MinerDevStratum.IsConnected && !MinerDevStratum.IsInvalidConnection)
                                              {
                                                  MinerDevStratum.RequestJobTemplate();
                                              }
                                      }),
                Task.Factory.StartNew(() => { if (GrinDevStratum.IsConnected && !GrinDevStratum.IsInvalidConnection)
                                              {
                                                  GrinDevStratum.RequestJobTemplate();
                                              }
                                      }),
                Task.Factory.StartNew(() => { if (MinerStratum.IsConnected && !MinerStratum.IsInvalidConnection)
                                              {
                                                  MinerStratum.RequestJobTemplate();
                                              }
                                      })
            });

            if (UpdateJobMonitorTask == null || Connection.TaskEndedStatuses.Any(s => UpdateJobMonitorTask.Status == s))
            {
                UpdateJobMonitorTask = Task.Factory.StartNew(() => UpdateJobMonitor());
            }
        }