예제 #1
0
 public void Stop()
 {
     Console.WriteLine("PoolManager::stop() begin");
     if (_running != 0)     //: atomic
     {
         _asyncPending = 1; //: atomic
         _stopping     = 1; //: atomic
         if (_client != null && _client.IsConnected)
         {
             _client.DisconnectAsync();
             // Wait for async operations to complete
             while (_running != 0) //: atomic
             {
                 Thread.Sleep(500);
             }
             _client = null;
         }
         else
         {
             // Stop timing actors
             _failoverTimer?.Dispose(); _failoverTimer   = null;
             _submithrTimer?.Dispose(); _submithrTimer   = null;
             _reconnectTimer?.Dispose(); _reconnectTimer = null;
             if (Farm.F.IsMining)
             {
                 Console.WriteLine("Shutting down miners...");
                 Farm.F.Stop();
             }
         }
     }
     Console.WriteLine("PoolManager::stop() end");
 }
예제 #2
0
        static async Task Test(PoolClient client, string url)
        {
            client.SetConnection(new Uri(url));
            await client.ConnectAsync();

            while (client.IsConnected)
            {
                Thread.Sleep(1000);
            }
        }
예제 #3
0
        private void RotateConnect()
        {
            if (_client != null && _client.IsConnected)
            {
                return;
            }

            var connections = _options.Connections;

            // Check we're within bounds
            if (_activeConnectionIdx >= connections.Count)
            {
                _activeConnectionIdx = 0;
            }

            // If this connection is marked Unrecoverable then discard it
            if (connections[_activeConnectionIdx].IsUnrecoverable())
            {
                connections.RemoveAt(_activeConnectionIdx);
                _connectionAttempt = 0;
                if (_activeConnectionIdx >= connections.Count)
                {
                    _activeConnectionIdx = 0;
                }
                Interlocked.Add(ref _connectionSwitches, 1);
            }
            else if (_connectionAttempt >= _options.ConnectionMaxRetries)
            {
                // If this is the only connection we can't rotate forever
                if (connections.Count == 1)
                {
                    connections.RemoveAt(_activeConnectionIdx);
                }
                // Rotate connections if above max attempts threshold
                else
                {
                    _connectionAttempt = 0;
                    _activeConnectionIdx++;
                    if (_activeConnectionIdx >= connections.Count)
                    {
                        _activeConnectionIdx = 0;
                    }
                    Interlocked.Add(ref _connectionSwitches, 1);
                }
            }

            if (connections.Count != 0 && connections[_activeConnectionIdx].Host != "exit")
            {
                if (_client != null)
                {
                    _client = null;
                }
                var connection = connections[_activeConnectionIdx];
                switch (connection.GetStratumFamily())
                {
                case StratumFamily.GetWork: _client = new EthGetworkClient(Farm.F, _options.NoWorkTimeout, _options.GetWorkPollInterval); break;

                case StratumFamily.Stratum: _client = new EthStratumClient(Farm.F, _options.NoWorkTimeout, _options.NoResponseTimeout); break;

                case StratumFamily.Simulation: _client = new SimulateClient(Farm.F, _options.BenchmarkBlock); break;
                }
                if (_client != null)
                {
                    SetClientHandlers();
                }

                // Count connectionAttempts
                _connectionAttempt++;

                // Invoke connections
                _selectedHost = $"{connection.Host}:{connection.Port}";
                _client.SetConnection(connection);
                Console.WriteLine($"Selected pool {_selectedHost}");

                if (_connectionAttempt > 1 && _options.DelayBeforeRetry > 0)
                {
                    Console.WriteLine($"Next connection attempt in {_options.DelayBeforeRetry} seconds");
                    _reconnectTimer = new Timer(ReconnectTimer_Elapsed, null, new TimeSpan(0, 0, _options.DelayBeforeRetry), new TimeSpan(0, 0, -1));
                }
                else
                {
                    _client.ConnectAsync();
                }
            }
            else
            {
                Console.WriteLine(connections.Count == 0 ? "No more connections to try. Exiting..." : "'exit' failover just got hit. Exiting...");

                // Stop mining if applicable
                if (Farm.F.IsMining)
                {
                    Console.WriteLine("Shutting down miners...");
                    Farm.F.Stop();
                }

                _running = 0; //: atomic;
                Environment.Exit(0);
            }
        }