Skip to content

Commit

Permalink
Fix worker disconnection when miner try to use stratum over SSL
Browse files Browse the repository at this point in the history
(bfgminer default behaviour). Bug #16
  • Loading branch information
Stratehm committed Aug 26, 2014
1 parent 739dd58 commit 759a02c
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ public abstract class StratumConnection {

private boolean disconnectOnParsingError;

// Flag that is true until the first line is read. Used to close the
// connection if a parsing error occurs on the first line read (even if
// disconnectOnParsingError is false) since in that case, the client might
// not be a stratum client.
private boolean isFirstLine;

public StratumConnection(Socket socket) {
this.socket = socket;
this.objectMapper = new ObjectMapper();
this.sentRequestIds = Collections.synchronizedMap(new HashMap<Long, JsonRpcRequest>());
this.throwDisconnectError = true;
this.disconnectOnParsingError = false;
this.isFirstLine = true;
}

/**
Expand Down Expand Up @@ -213,6 +220,9 @@ private void onLineRead(String line) {
LOGGER.debug("{}. Line read: {}", getConnectionName(), line);
try {
JsonRpcRequest request = objectMapper.readValue(line, JsonRpcRequest.class);
if (isFirstLine) {
isFirstLine = false;
}

// If there is an id, it may be a request or a response
if (request.getId() != null) {
Expand All @@ -234,7 +244,7 @@ private void onLineRead(String line) {
onNotificationReceived(new JsonRpcNotification(request));
}
} catch (JsonMappingException e) {
if (disconnectOnParsingError) {
if (isFirstLine || disconnectOnParsingError) {
throw e;
} else {
LOGGER.error("JSON-RPC Parsing error with line: {}", line, e);
Expand Down

0 comments on commit 759a02c

Please sign in to comment.