Ejemplo n.º 1
0
        static public async Task Start(string address, CancellationToken token)
        {
            var random = new Random();

            _address = address;
            NHLog.Info("NHWebSocket-WD", "Starting nhmws watchdog");
            NHSmaData.InitializeIfNeeded();
            // TODO use this or just use the application exit source
            while (!token.IsCancellationRequested)
            {
                try
                {
                    await NewConnection(token);
                }
                catch (Exception e)
                {
                    NHLog.Error("NHWebSocket-WD", $"Error occured: {e.Message}");
                }
                // if we didn't initialize the restart delay reconnect
                if (!_isNhmwsRestart && !token.IsCancellationRequested)
                {
                    // delays re-connect 10 to 30 seconds
                    var delaySeconds = 10 + random.Next(0, 20);
                    NHLog.Info("NHWebSocket-WD", $"Attempting reconnect in {delaySeconds} seconds");
                    await Task.Delay(delaySeconds * 1000, token);
                }
                else if (_isNhmwsRestart && !token.IsCancellationRequested)
                {
                    NHLog.Info("NHWebSocket-WD", $"Restarting nhmws SESSION");
                }
            }
            NHLog.Info("NHWebSocket-WD", "Ending nhmws watchdog");
        }
 public void StartConnectionold()
 {
     NHSmaData.InitializeIfNeeded();
     _connectionAttempted = true;
     try
     {
         if (_webSocket == null)
         {
             _webSocket = new WebSocket(Links.NhmSocketAddress_old, true);
         }
         else
         {
             _webSocket.Close();
         }
         _webSocket.OnOpen           += ConnectCallback;
         _webSocket.OnMessage        += ReceiveCallback;
         _webSocket.OnError          += ErrorCallback;
         _webSocket.OnClose          += CloseCallback;
         _webSocket.Log.Level         = LogLevel.Debug;
         _webSocket.Log.Output        = (data, s) => Helpers.ConsolePrint("SOCKET_OLD", data.ToString());
         _webSocket.EnableRedirection = true;
         _webSocket.Connect();
         _connectionEstablished = true;
     }
     catch (Exception e)
     {
         Helpers.ConsolePrint("SOCKET_OLD", e.ToString());
     }
 }
Ejemplo n.º 3
0
        public void StartConnection(string btc = null, string worker = null, string group = null)
        {
            NHSmaData.InitializeIfNeeded();
            _connectionAttempted = true;

            _login.rig = ApplicationStateManager.RigID;

            if (btc != null)
            {
                _login.btc = btc;
            }
            if (worker != null)
            {
                _login.worker = worker;
            }
            if (group != null)
            {
                _login.group = group;
            }

            try
            {
                if (_webSocket == null)
                {
                    _webSocket = new WebSocket(_address, true);

                    _webSocket.OnOpen           += Login;
                    _webSocket.OnMessage        += ReceiveCallback;
                    _webSocket.OnError          += ErrorCallback;
                    _webSocket.OnClose          += CloseCallback;
                    _webSocket.Log.Level         = LogLevel.Debug;
                    _webSocket.Log.Output        = (data, s) => NHM.Common.Logger.Info("SOCKET", data.ToString());
                    _webSocket.EnableRedirection = true;
                }
                else
                {
                    NHM.Common.Logger.Info("SOCKET", $"Credentials change reconnecting nhmws");
                    _connectionEstablished = false;
                    _restartConnection     = true;
                    _webSocket?.Close(CloseStatusCode.Normal, $"Credentials change reconnecting {ApplicationStateManager.Title}.");
                }
                NHM.Common.Logger.Info("SOCKET", "Connecting");
                _webSocket.Connect();
                NHM.Common.Logger.Info("SOCKET", "Connected");
                _connectionEstablished = true;
                _restartConnection     = false;
            } catch (Exception e)
            {
                NHM.Common.Logger.Error("SOCKET", e.ToString());
            }
        }
        public static void Initialize(TestContext context)
        {
            foreach (AlgorithmType algo in Enum.GetValues(typeof(AlgorithmType)))
            {
                if (algo > 0)
                {
                    StartPaying[algo] = R.NextDouble();
                }
            }

            NHSmaData.InitializeIfNeeded();
            NHSmaData.UpdateSmaPaying(StartPaying);

            NHSmaData.UpdateStableAlgorithms(TestStables);
        }
Ejemplo n.º 5
0
        private void ConnectCallback(object sender, EventArgs e)
        {
            try
            {
                NHSmaData.InitializeIfNeeded();
                //send login
                var version = "NHML/" + Application.ProductVersion;
                var login   = new NicehashLogin
                {
                    version = version
                };
                var loginJson = JsonConvert.SerializeObject(login);
                SendData(loginJson);

                OnConnectionEstablished?.Invoke(null, EventArgs.Empty);
            } catch (Exception er)
            {
                Helpers.ConsolePrint("SOCKET", er.ToString());
            }
        }
Ejemplo n.º 6
0
            private static void ConnectCallback(object sender, EventArgs e)
            {
                try
                {
                    NHSmaData.InitializeIfNeeded();
                    //send login
                    var version = "NHML/" + Application.ProductVersion;
                    var login   = new nicehash_login
                    {
                        version = version
                    };
                    var loginJson = JsonConvert.SerializeObject(login);
                    SendData(loginJson);

                    DeviceStatus_Tick(null); // Send device to populate rig stats

                    OnConnectionEstablished.Emit(null, EventArgs.Empty);
                }
                catch (Exception er)
                {
                    Helpers.ConsolePrint("SOCKET", er.ToString());
                }
            }