From 6a5e7a1db6b3e063260d5ebc426356682657d6ca Mon Sep 17 00:00:00 2001 From: Stratehm Date: Mon, 24 Nov 2014 17:30:30 +0100 Subject: [PATCH] Modification for bug #24. Username is mandatory only if "appendWorkerNames" is disabled and password is mandatory only if "useWorkerPassword" is disabled. --- .../stratum/proxy/manager/ProxyManager.java | 39 +++++++++++++++++-- .../strat/mining/stratum/proxy/pool/Pool.java | 6 ++- .../stratum/proxy/rest/ProxyResources.java | 6 +-- src/main/resources/webapp/index.html | 12 ++++-- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java b/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java index e83470b..44a357c 100644 --- a/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java +++ b/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java @@ -711,18 +711,47 @@ public void removePool(String poolName, Boolean keepHistory) throws NoPoolAvaila * @throws URISyntaxException */ private void checkAddPoolParameters(AddPoolDTO addPoolDTO) throws BadParameterException, URISyntaxException { + checkPoolParameters(addPoolDTO.getPoolHost(), addPoolDTO.getUsername(), addPoolDTO.getAppendWorkerNames(), addPoolDTO.getPassword(), + addPoolDTO.getUseWorkerPassword()); + } + + /** + * Check that all parameters to update the pool are presents and valid. + * + * @param updatePoolDTO + * @throws URISyntaxException + */ + private void checkUpdatePoolParameters(UpdatePoolDTO updatePoolDTO) throws BadParameterException, URISyntaxException { + checkPoolParameters(updatePoolDTO.getPoolHost(), updatePoolDTO.getUsername(), updatePoolDTO.getAppendWorkerNames(), + updatePoolDTO.getPassword(), updatePoolDTO.getUseWorkerPassword()); + } - if (addPoolDTO.getPoolHost() == null || addPoolDTO.getPoolHost().trim().isEmpty()) { + /** + * Check that all mandatory of the pool are presents and valid. + * + * @param poolHost + * @param username + * @param appendWorkerNames + * @param password + * @param useWorkerPassword + * @throws BadParameterException + * @throws URISyntaxException + */ + private void checkPoolParameters(String poolHost, String username, Boolean appendWorkerNames, String password, Boolean useWorkerPassword) + throws BadParameterException, URISyntaxException { + if (poolHost == null || poolHost.trim().isEmpty()) { throw new BadParameterException("Pool host is empty."); } - new URI("stratum+tcp://" + addPoolDTO.getPoolHost().trim()); + new URI("stratum+tcp://" + poolHost.trim()); - if (addPoolDTO.getUsername() == null || addPoolDTO.getUsername().trim().isEmpty()) { + // The Username is mandatory only if appendWorkerNames is false. + if (!appendWorkerNames && (username == null || username.trim().isEmpty())) { throw new BadParameterException("Username is empty."); } - if (addPoolDTO.getPassword() == null || addPoolDTO.getPassword().trim().isEmpty()) { + // The Password is mandatory only if useWorkerPassword is false. + if (!useWorkerPassword && (password == null || password.trim().isEmpty())) { throw new BadParameterException("Password is empty."); } } @@ -952,6 +981,8 @@ public void updatePool(UpdatePoolDTO poolToUpdate) throws NotFoundException, Soc throw new NotFoundException("The pool with name " + poolToUpdate.getPoolName() + " has not been found."); } + checkUpdatePoolParameters(poolToUpdate); + if (poolToUpdate.getPoolHost() != null && !poolToUpdate.getPoolHost().equals(pool.getHost())) { if (!hasBeenStopped) { pool.stopPool("Pool updated and needed to restart."); diff --git a/src/main/java/strat/mining/stratum/proxy/pool/Pool.java b/src/main/java/strat/mining/stratum/proxy/pool/Pool.java index db9487b..d24d3e8 100644 --- a/src/main/java/strat/mining/stratum/proxy/pool/Pool.java +++ b/src/main/java/strat/mining/stratum/proxy/pool/Pool.java @@ -563,7 +563,8 @@ public void submitShare(MiningSubmitRequest workerRequest, ResponseReceivedCallb poolRequest.setNtime(workerRequest.getNtime()); if (isAppendWorkerNames) { - poolRequest.setWorkerName(username + workerSeparator + workerRequest.getWorkerName()); + poolRequest.setWorkerName((username == null ? "" : username) + (workerSeparator == null ? "" : workerSeparator) + + workerRequest.getWorkerName()); } else { poolRequest.setWorkerName(username); } @@ -900,7 +901,8 @@ public void authorizeWorker(MiningAuthorizeRequest workerRequest) throws Authori // means that each worker has to be authorized. If false, the // authorization has already been done with the configured username. if (isAppendWorkerNames) { - String finalUserName = username + workerSeparator + workerRequest.getUsername(); + String finalUserName = (username == null ? "" : username) + (workerSeparator == null ? "" : workerSeparator) + + workerRequest.getUsername(); // If the worker is already authorized, do nothing if (authorizedWorkers.contains(finalUserName)) { diff --git a/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java b/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java index df789ee..3194834 100644 --- a/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java +++ b/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java @@ -669,8 +669,8 @@ private PoolDetailsDTO convertPoolToDTO(Pool pool) { result.setIsActive(pool.isActive()); result.setName(pool.getName()); result.setNumberOfWorkerConnections(pool.getNumberOfWorkersConnections()); - result.setPassword(pool.getPassword()); - result.setUsername(pool.getUsername()); + result.setPassword(pool.getPassword() == null ? "" : pool.getPassword()); + result.setUsername(pool.getUsername() == null ? "" : pool.getUsername()); result.setWorkerExtranonce2Size(pool.getWorkerExtranonce2Size()); result.setPriority(pool.getPriority()); result.setWeight(pool.getWeight()); @@ -684,7 +684,7 @@ private PoolDetailsDTO convertPoolToDTO(Pool pool) { result.setLastStopCause(pool.getLastStopCause()); result.setLastStopDate(pool.getLastStopDate() != null ? simpleDateFormat.format(pool.getLastStopDate()) : null); result.setAppendWorkerNames(pool.isAppendWorkerNames()); - result.setWorkerNamesSeparator(pool.getWorkerSeparator()); + result.setWorkerNamesSeparator(pool.getWorkerSeparator() == null ? "" : pool.getWorkerSeparator()); result.setUseWorkerPassword(pool.isUseWorkerPassword()); return result; diff --git a/src/main/resources/webapp/index.html b/src/main/resources/webapp/index.html index 79a3a3b..d40007b 100644 --- a/src/main/resources/webapp/index.html +++ b/src/main/resources/webapp/index.html @@ -332,7 +332,7 @@
+ name **
@@ -342,7 +342,7 @@
+ ***
@@ -429,6 +429,8 @@

* Mandatory fields

+

** Mandatory if "Append worker names to user name" is not enabled

+

*** Mandatory if "Use worker password" is not enabled