Skip to content

Commit

Permalink
Modification for bug #24. Username is mandatory only if
Browse files Browse the repository at this point in the history
"appendWorkerNames" is disabled and password is mandatory only if
"useWorkerPassword" is disabled.
  • Loading branch information
Stratehm committed Nov 24, 2014
1 parent 65d3afd commit 6a5e7a1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
39 changes: 35 additions & 4 deletions src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down Expand Up @@ -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.");
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/strat/mining/stratum/proxy/pool/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ <h4 class="modal-title"></h4>

<div class="form-group">
<label class="col-md-4 control-label" for="username">User
name *</label>
name **</label>
<div class="col-md-8">
<input id="usernameField" name="username" placeholder=""
class="form-control input-md" required="" type="text">
Expand All @@ -342,7 +342,7 @@ <h4 class="modal-title"></h4>

<div class="form-group">
<label class="col-md-4 control-label" for="password">Password
*</label>
***</label>
<div class="col-md-8">
<input id="passwordField" name="password" placeholder=""
class="form-control input-md" required="" type="text">
Expand Down Expand Up @@ -429,6 +429,8 @@ <h4 class="modal-title"></h4>
</fieldset>
</form>
<p class="help-block">* Mandatory fields</p>
<p class="help-block">** Mandatory if "Append worker names to user name" is not enabled</p>
<p class="help-block">*** Mandatory if "Use worker password" is not enabled</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default validateButton">Add</button>
Expand Down Expand Up @@ -464,7 +466,7 @@ <h4 class="modal-title"></h4>

<div class="form-group">
<label class="col-md-4 control-label" for="username">User
name *</label>
name **</label>
<div class="col-md-8">
<input id="usernameField" name="username" placeholder=""
class="form-control input-md" required="" type="text">
Expand All @@ -474,7 +476,7 @@ <h4 class="modal-title"></h4>

<div class="form-group">
<label class="col-md-4 control-label" for="password">Password
*</label>
***</label>
<div class="col-md-8">
<input id="passwordField" name="password" placeholder=""
class="form-control input-md" required="" type="text">
Expand Down Expand Up @@ -543,6 +545,8 @@ <h4 class="modal-title"></h4>
</fieldset>
</form>
<p class="help-block">* If modified, the pool will restart to apply the new setting.</p>
<p class="help-block">** Mandatory if "Append worker names to user name" is not enabled</p>
<p class="help-block">*** Mandatory if "Use worker password" is not enabled</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default validateButton">Update</button>
Expand Down

0 comments on commit 6a5e7a1

Please sign in to comment.