예제 #1
0
 /**
  * Link the connection to the user
  *
  * @param connection
  * @param request
  */
 private void linkConnectionToUser(WorkerConnection connection, MiningAuthorizeRequest request) {
   User user = users.get(request.getUsername());
   if (user == null) {
     user = new User(request.getUsername());
     user.setSamplingHashesPeriod(
         ConfigurationManager.getInstance().getUserHashrateSamplingPeriod());
     users.put(request.getUsername(), user);
   }
   user.addConnection(connection);
 }
예제 #2
0
  /**
   * Switch the given connection to the given pool.
   *
   * @param connection
   * @param newPool
   */
  public void switchPoolForConnection(WorkerConnection connection, Pool newPool)
      throws TooManyWorkersException, ChangeExtranonceNotSupportedException {
    // If the old pool is the same as the new pool, do nothing.
    if (!newPool.equals(connection.getPool())) {
      // Remove the connection from the old pool connection list.
      Set<WorkerConnection> oldPoolConnections = getPoolWorkerConnections(connection.getPool());
      if (oldPoolConnections != null) {
        oldPoolConnections.remove(connection);
      }

      // Then rebind the connection to this pool. An exception is thrown
      // if the rebind fails since the connection does not support the
      // extranonce change.
      connection.rebindToPool(newPool);

      // And finally add the worker connection to the pool's worker
      // connections
      Set<WorkerConnection> newPoolConnections = getPoolWorkerConnections(newPool);
      newPoolConnections.add(connection);

      // Ask to the pool to authorize the worker
      // Create a fake authorization request since when a connection is
      // rebound, the miner does not send auhtorization request (since it
      // has already done it). But it may be the first time this
      // connection is bound to this pool, so the username on this
      // connection is not yet authorized on the pool.
      for (Entry<String, String> entry : connection.getAuthorizedWorkers().entrySet()) {
        MiningAuthorizeRequest fakeRequest = new MiningAuthorizeRequest();
        fakeRequest.setUsername(entry.getKey());
        fakeRequest.setPassword(entry.getValue());
        try {
          onAuthorizeRequest(connection, fakeRequest);
        } catch (AuthorizationException e) {
          LOGGER.error(
              "Authorization of user {} failed on pool {} when rebinding connection {}. Closing the connection. Cause: {}",
              entry.getKey(),
              newPool.getName(),
              connection.getConnectionName(),
              e.getMessage());
          connection.close();
        }
      }
    }
  }