Beispiel #1
0
        public Task <ActivationResult> ActivateAsync(MinerStatus status)
        {
            long minerId = long.Parse(Context.UserIdentifier);
            var  address = GetRequestIP();

            return(MinerService.ActivateMinerAsync(Context.ConnectionId, minerId, status, address));
        }
Beispiel #2
0
        public async Task <IActionResult> GetStatusAsync()
        {
            int plotCount = await PlotManager.GetPlotCountAsync();

            var status = new MinerStatus(plotCount);

            return(Ok(status));
        }
Beispiel #3
0
        public string[] GetMinersWithStatus(MinerStatus status)
        {
            List <string> miners = new List <string>();

            foreach (KeyValuePair <string, Miner> item in data.installed)
            {
                if (item.Value.status == status)
                {
                    miners.Add(item.Key);
                }
            }

            return(miners.ToArray());
        }
Beispiel #4
0
        public async Task <MinerActivationResult> ActivateMinerAsync(string connectionId, long minerId, MinerStatus status, List <PlotInfo> plotInfos)
        {
            await MinerLock.WaitAsync();

            try
            {
                if (plotInfos.Count != status.PlotCount)
                {
                    Logger.LogWarning($"Miner [{minerId}] tried to activate with unmatching status and plotInfos plot count");
                    return(MinerActivationResult.FromStatusPlotCountUnmatch());
                }
                if (plotInfos.Count != plotInfos.Distinct().Count())
                {
                    Logger.LogWarning($"Miner [{minerId}] tried to activate with duplicate plot public keys");
                    return(MinerActivationResult.FromDuplicates());
                }
                if (ActiveMiners.ContainsKey(minerId))
                {
                    return(MinerActivationResult.FromAlreadyActive());
                }

                var conflicts = AddPlotInfosAndFilterConflicts(plotInfos);

                if (conflicts.Any())
                {
                    Logger.LogWarning($"Miner [{minerId}] tried to activate with {conflicts.Count} conflicing plots!");
                    status = new MinerStatus(status.PlotCount - conflicts.Count);
                }

                var activation = new MinerActivation(connectionId, status, plotInfos);
                ActiveMiners.Add(minerId, activation);

                long userId = await UserService.GetOwnerIdFromMinerId(minerId);

                Logger.LogInformation($"Activated miner [{minerId}]");

                return(conflicts.Any()
                    ? MinerActivationResult.FromConflicingPlots(userId, conflicts.ToArray())
                    : MinerActivationResult.FromSuccess(userId));
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "There was an exception while activating a miner!");
                return(MinerActivationResult.FromError());
            }
            finally
            {
                MinerLock.Release();
            }
        }
Beispiel #5
0
        public void RemoveConnection(string connectionId)
        {
            var rmObj = SignalRConnections.FirstOrDefault(ln => ln.SignalRConnectionId == connectionId);

            if (rmObj != null)
            {
                if (rmObj.MinerStatus != null)
                {
                    MinerStatus.Remove(rmObj.MinerStatus);
                }

                SignalRConnections.Remove(rmObj);
                SaveChanges();
            }
        }
        private static void PostJson(string uri, MinerStatus postParameters)
        {
            string postData = JsonConvert.SerializeObject(postParameters);

            byte[] bytes          = Encoding.UTF8.GetBytes(postData);
            var    httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);

            httpWebRequest.Method        = "POST";
            httpWebRequest.ContentLength = bytes.Length;
            httpWebRequest.ContentType   = "application/json";
            using (Stream requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Count());
            }
            var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        }
        public static void PostToServer(Object stateInfo)
        {
            if (!ApplicationState.PostStatusToServer)
            {
                return;
            }

            var stats = new MinerStatus
            {
                address     = ApplicationState.Wallet,
                name        = ApplicationState.RigName,
                hashrate    = ApplicationState.CurrentHashrate,
                temperature = ApplicationState.CurrentTemperature
            };

            PostJson(ApplicationState.Url, stats);
        }
Beispiel #8
0
        protected override async Task ExecuteAsync(IConsole console)
        {
            var clientStatusTask = MinerAccessor.GetStatusAsync().Try();
            var serverStatusTask = ServerAccessor.GetStatusAsync().Try();

            MinerStatus  clientStatus = await clientStatusTask;
            ServerStatus serverStatus = await serverStatusTask;

            await InfoAsync($"Client ");

            if (clientStatus == null)
            {
                await ErrorLineAsync("Offline");
            }
            else
            {
                await SuccessLineAsync("Online");
                await WriteLineAsync();
                await InfoLineAsync($"Currently harvesting {clientStatus.PlotCount} plots");
            }

            await WriteLineAsync();
            await InfoAsync($"Server ");

            if (serverStatus == null)
            {
                await ErrorLineAsync("Offline");
            }
            else
            {
                await SuccessLineAsync("Online");
                await WriteLineAsync();

                if (serverStatus.Synced)
                {
                    await InfoLineAsync("Node fully synced");
                    await InfoLineAsync($"Current peak height {serverStatus.SyncHeight}");
                }
                else
                {
                    await InfoLineAsync("Node Syncing...");
                    await InfoLineAsync($"Currently synced to block height {serverStatus.SyncHeight} / {serverStatus.MaxSyncHeight}");
                }
            }
        }
Beispiel #9
0
        public async Task <MinerUpdateResult> UpdateMinerAsync(string connectionId, long minerId, MinerStatus status, List <PlotInfo> plotInfos)
        {
            await MinerLock.WaitAsync();

            try
            {
                if (!ActiveMiners.TryGetValue(minerId, out var oldValue))
                {
                    throw new InvalidOperationException("Cannot update inactive miner");
                }
                if (oldValue.ConnectionId != connectionId)
                {
                    Logger.LogWarning($"Miner [{minerId}] tried to update state from a different connection");
                    return(MinerUpdateResult.FromInvalidConnection());
                }

                RemovePlotInfos(oldValue.PlotInfos);
                var conflicts = AddPlotInfosAndFilterConflicts(plotInfos);

                if (conflicts.Any())
                {
                    Logger.LogWarning($"Miner [{minerId}] tried to update with {conflicts.Count} conflicing plots!");
                    status = new MinerStatus(status.PlotCount - conflicts.Count);
                }

                oldValue.Update(status, plotInfos);
                Logger.LogInformation($"Updated miner [{minerId}]");

                return(conflicts.Any()
                    ? MinerUpdateResult.FromConflicingPlots(conflicts.ToArray())
                    : MinerUpdateResult.FromSuccess());
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "There was an excpetion while updating a miner!");
                return(MinerUpdateResult.FromError());
            }
            finally
            {
                MinerLock.Release();
            }
        }
Beispiel #10
0
        public async Task UpdateMinerAsync(string connectionId, long minerId, MinerStatus status)
        {
            await ActiveMinersLock.WaitAsync();

            try
            {
                if (!ActiveMiners.TryGetValue(minerId, out var oldValue))
                {
                    throw new InvalidOperationException("Cannot update inactive miner");
                }
                if (oldValue.ConnectionId != connectionId)
                {
                    throw new InvalidOperationException("Cannot update active miner from different connection");
                }

                oldValue.Status       = status;
                ActiveMiners[minerId] = oldValue;
                Logger.LogInformation($"Updated miner [{minerId}]");
            }
            finally
            {
                ActiveMinersLock.Release();
            }
        }
        public void NotifyMinerObserver(Message message, MinerStatus status = MinerStatus.Working, PoolStat poolStat = null)
        {
            switch (status)
            {
            case MinerStatus.Idling:
            {
                var text = string.Format("No worker detected! Please check your environment...\n-current hashrate: {0:0.00}\n-active workers: {1}", poolStat.Data.CurrentHashrate, poolStat.Data.ActiveWorkers);
                telegramBotClient.SendTextMessageAsync(message.Chat.Id, text);
                break;
            }

            case MinerStatus.PowerDecreasing:
            {
                var text = string.Format("Power decreasing, please check your environment...\n-current hashrate: {0:0.00}\n-active workers: {1}", poolStat.Data.CurrentHashrate, poolStat.Data.ActiveWorkers);
                telegramBotClient.SendTextMessageAsync(message.Chat.Id, text);
                break;
            }

            case MinerStatus.InternalServerError:
            {
                telegramBotClient.SendTextMessageAsync(message.Chat.Id, "No reply from flypool! Please check your environment and pool...");
                break;
            }

            case MinerStatus.WrongToken:
            {
                telegramBotClient.SendTextMessageAsync(message.Chat.Id, "Please, provide valid token...");
                break;
            }

            default:
            {
                break;
            }
            }
        }
Beispiel #12
0
        public Task <MinerUpdateResult> UpdateMinerAsync(MinerStatus status, List <PlotInfo> plotInfos)
        {
            long minerId = long.Parse(Context.UserIdentifier);

            return(MinerService.UpdateMinerAsync(Context.ConnectionId, minerId, status, plotInfos));
        }
Beispiel #13
0
        public async Task <ActivationResult> ActivateMinerAsync(string connectionId, long minerId, MinerStatus status, IPAddress address)
        {
            await ActiveMinersLock.WaitAsync();

            try
            {
                var activation = new MinerActivation(connectionId, address, status);
                if (!ActiveMiners.TryAdd(minerId, activation))
                {
                    return(ActivationResult.FromFailed("There already is a active connection from this miner!"));
                }

                Logger.LogInformation($"Activated miner [{minerId}]");
                long userId = await UserService.GetOwnerIdFromMinerId(minerId);

                return(ActivationResult.FromSuccess(userId));
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "There was an exception while activating a miner!");
                return(ActivationResult.FromFailed("An unknown error occurred!"));
            }
            finally
            {
                ActiveMinersLock.Release();
            }
        }
Beispiel #14
0
 public async Task UpdateMinerAsync(MinerStatus status)
 {
     long minerId = long.Parse(Context.UserIdentifier);
     await MinerService.UpdateMinerAsync(Context.ConnectionId, minerId, status);
 }