Esempio n. 1
0
        public void Authenticate(IMiner miner)
        {
            // if username validation is not on just authenticate the miner, else ask the current storage layer to do so.
            miner.Authenticated = !_poolConfig.Miner.ValidateUsername || _storageLayer.Authenticate(miner);

            _logger.Debug(
                miner.Authenticated ? "Authenticated miner: {0:l} [{1:l}]" : "Miner authentication failed: {0:l} [{1:l}]",
                miner.Username, ((IClient)miner).Connection.RemoteEndPoint);

            if (!miner.Authenticated)
            {
                return;
            }

            if (miner is IStratumMiner) // if we are handling a stratum-miner, apply stratum specific stuff.
            {
                var stratumMiner = (IStratumMiner)miner;
                stratumMiner.SetDifficulty(_poolConfig.Stratum.Diff); // set the initial difficulty for the miner and send it.
                stratumMiner.SendMessage(_poolConfig.Meta.MOTD);      // send the motd.
            }

            miner.Account = _accountManager.GetAccountByUsername(miner.Username);     // query the user.
            if (miner.Account == null)                                                // if the user doesn't exists.
            {
                _accountManager.AddAccount(new Account(miner));                       // create a new one.
                miner.Account = _accountManager.GetAccountByUsername(miner.Username); // re-query the newly created record.
            }

            OnMinerAuthenticated(new MinerEventArgs(miner)); // notify listeners about the new authenticated miner.
        }
Esempio n. 2
0
        public void Authenticate(IMiner miner)
        {
            // if username validation is not on just authenticate the miner, else ask the current storage layer to do so.
            miner.Authenticated = !_poolConfig.Miner.ValidateUsername || _storageLayer.Authenticate(miner);

            _logger.Information(
                miner.Authenticated ? "Authenticated miner: {0:l} [{1:l}]" : "Miner authentication failed: {0:l} [{1:l}]",
                miner.Username, ((IClient)miner).Connection.RemoteEndPoint);

            if (!miner.Authenticated)
            {
                return;
            }

            if (miner is IStratumMiner) // if we are handling a stratum-miner, apply stratum specific stuff.
            {
                var stratumMiner = (IStratumMiner)miner;
                stratumMiner.SetDifficulty(_poolConfig.Stratum.Diff); // set the initial difficulty for the miner and send it.
                stratumMiner.SendMessage(_poolConfig.Meta.MOTD);      // send the motd.
            }

            OnMinerAuthenticated(new MinerEventArgs(miner)); // notify listeners about the new authenticated miner.
        }