mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-29 01:38:39 -04:00
Change log level, add stopped flag, move connection listener inside success handler
This commit is contained in:
parent
03b5a03048
commit
2775c0a55d
5 changed files with 48 additions and 28 deletions
|
@ -33,7 +33,6 @@ public class Broadcaster implements ConnectionListener, PeerManager.Listener {
|
||||||
private PeerManager peerManager;
|
private PeerManager peerManager;
|
||||||
private final Set<Listener> listeners = new CopyOnWriteArraySet<>();
|
private final Set<Listener> listeners = new CopyOnWriteArraySet<>();
|
||||||
private boolean stopped = false;
|
private boolean stopped = false;
|
||||||
|
|
||||||
private final IntegerProperty numOfBroadcasts = new SimpleIntegerProperty(0);
|
private final IntegerProperty numOfBroadcasts = new SimpleIntegerProperty(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,8 @@ public class RequestDataHandler implements MessageListener {
|
||||||
connection.addMessageListener(RequestDataHandler.this);
|
connection.addMessageListener(RequestDataHandler.this);
|
||||||
log.trace("Send " + getDataRequest + " to " + nodeAddress + " succeeded.");
|
log.trace("Send " + getDataRequest + " to " + nodeAddress + " succeeded.");
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call.");
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." +
|
||||||
|
"Might be caused by an previous timeout.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,8 @@ public class RequestDataHandler implements MessageListener {
|
||||||
log.info(errorMessage);
|
log.info(errorMessage);
|
||||||
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE);
|
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call. " +
|
||||||
|
"Might be caused by an previous timeout.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -123,7 +125,8 @@ public class RequestDataHandler implements MessageListener {
|
||||||
log.info(errorMessage + " / RequestDataHandler=" + RequestDataHandler.this);
|
log.info(errorMessage + " / RequestDataHandler=" + RequestDataHandler.this);
|
||||||
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT);
|
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that timeoutTimer.run call.");
|
log.trace("We have stopped already. We ignore that timeoutTimer.run call. " +
|
||||||
|
"Might be caused by an previous networkNode.sendMessage.onFailure.");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
10);
|
10);
|
||||||
|
|
|
@ -69,14 +69,18 @@ class KeepAliveHandler implements MessageListener {
|
||||||
public void sendPing(Connection connection) {
|
public void sendPing(Connection connection) {
|
||||||
Log.traceCall("connection=" + connection + " / this=" + this);
|
Log.traceCall("connection=" + connection + " / this=" + this);
|
||||||
if (!stopped) {
|
if (!stopped) {
|
||||||
this.connection = connection;
|
|
||||||
connection.addMessageListener(this);
|
|
||||||
Ping ping = new Ping(nonce);
|
Ping ping = new Ping(nonce);
|
||||||
SettableFuture<Connection> future = networkNode.sendMessage(connection, ping);
|
SettableFuture<Connection> future = networkNode.sendMessage(connection, ping);
|
||||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Connection connection) {
|
public void onSuccess(Connection connection) {
|
||||||
|
if (!stopped) {
|
||||||
log.trace("Send " + ping + " to " + connection + " succeeded.");
|
log.trace("Send " + ping + " to " + connection + " succeeded.");
|
||||||
|
KeepAliveHandler.this.connection = connection;
|
||||||
|
connection.addMessageListener(KeepAliveHandler.this);
|
||||||
|
} else {
|
||||||
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,12 +95,12 @@ class KeepAliveHandler implements MessageListener {
|
||||||
peerManager.handleConnectionFault(connection);
|
peerManager.handleConnectionFault(connection);
|
||||||
listener.onFault(errorMessage);
|
listener.onFault(errorMessage);
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that sendPing.onFailure call.");
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that sendPing call.");
|
log.trace("We have stopped already. We ignore that sendPing call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +124,7 @@ class KeepAliveHandler implements MessageListener {
|
||||||
nonce, pong.requestNonce);
|
nonce, pong.requestNonce);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that onMessage call.");
|
log.trace("We have stopped already. We ignore that onMessage call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class GetPeersRequestHandler {
|
||||||
private final PeerManager peerManager;
|
private final PeerManager peerManager;
|
||||||
private final Listener listener;
|
private final Listener listener;
|
||||||
private Timer timeoutTimer;
|
private Timer timeoutTimer;
|
||||||
|
private boolean stopped;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -74,28 +75,40 @@ class GetPeersRequestHandler {
|
||||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Connection connection) {
|
public void onSuccess(Connection connection) {
|
||||||
|
if (!stopped) {
|
||||||
log.trace("GetPeersResponse sent successfully");
|
log.trace("GetPeersResponse sent successfully");
|
||||||
cleanup();
|
cleanup();
|
||||||
listener.onComplete();
|
listener.onComplete();
|
||||||
|
} else {
|
||||||
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NotNull Throwable throwable) {
|
public void onFailure(@NotNull Throwable throwable) {
|
||||||
|
if (!stopped) {
|
||||||
String errorMessage = "Sending getPeersResponse to " + connection +
|
String errorMessage = "Sending getPeersResponse to " + connection +
|
||||||
" failed. That is expected if the peer is offline. getPeersResponse=" + getPeersResponse + "." +
|
" failed. That is expected if the peer is offline. getPeersResponse=" + getPeersResponse + "." +
|
||||||
"Exception: " + throwable.getMessage();
|
"Exception: " + throwable.getMessage();
|
||||||
log.info(errorMessage);
|
log.info(errorMessage);
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);
|
||||||
|
} else {
|
||||||
|
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
checkArgument(timeoutTimer == null, "onGetPeersRequest must not be called twice.");
|
checkArgument(timeoutTimer == null, "onGetPeersRequest must not be called twice.");
|
||||||
timeoutTimer = UserThread.runAfter(() -> {
|
timeoutTimer = UserThread.runAfter(() -> {
|
||||||
|
if (!stopped) {
|
||||||
String errorMessage = "A timeout occurred at sending getPeersResponse:" + getPeersResponse + " on connection:" + connection;
|
String errorMessage = "A timeout occurred at sending getPeersResponse:" + getPeersResponse + " on connection:" + connection;
|
||||||
log.info(errorMessage + " / PeerExchangeHandshake=" +
|
log.info(errorMessage + " / PeerExchangeHandshake=" +
|
||||||
GetPeersRequestHandler.this);
|
GetPeersRequestHandler.this);
|
||||||
log.info("timeoutTimer called. this=" + this);
|
log.info("timeoutTimer called. this=" + this);
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, connection);
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, connection);
|
||||||
|
} else {
|
||||||
|
log.trace("We have stopped already. We ignore that timeoutTimer.run call.");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
TIME_OUT_SEC, TimeUnit.SECONDS);
|
TIME_OUT_SEC, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
@ -114,6 +127,7 @@ class GetPeersRequestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
|
stopped = true;
|
||||||
if (timeoutTimer != null) {
|
if (timeoutTimer != null) {
|
||||||
timeoutTimer.stop();
|
timeoutTimer.stop();
|
||||||
timeoutTimer = null;
|
timeoutTimer = null;
|
||||||
|
|
|
@ -94,7 +94,7 @@ class PeerExchangeHandler implements MessageListener {
|
||||||
connection.addMessageListener(PeerExchangeHandler.this);
|
connection.addMessageListener(PeerExchangeHandler.this);
|
||||||
log.trace("Send " + getPeersRequest + " to " + nodeAddress + " succeeded.");
|
log.trace("Send " + getPeersRequest + " to " + nodeAddress + " succeeded.");
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped that handler already. We ignore that sendGetPeersRequest.onSuccess call.");
|
log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onSuccess call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class PeerExchangeHandler implements MessageListener {
|
||||||
log.info(errorMessage);
|
log.info(errorMessage);
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress);
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, nodeAddress);
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped that handler already. We ignore that sendGetPeersRequest.onFailure call.");
|
log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest.onFailure call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -121,7 +121,7 @@ class PeerExchangeHandler implements MessageListener {
|
||||||
log.info("timeoutTimer called on " + this);
|
log.info("timeoutTimer called on " + this);
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, nodeAddress);
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, nodeAddress);
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped that handler already. We ignore that timeoutTimer.run call.");
|
log.trace("We have stopped that handler already. We ignore that timeoutTimer.run call.");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TIME_OUT_SEC, TimeUnit.SECONDS);
|
TIME_OUT_SEC, TimeUnit.SECONDS);
|
||||||
|
@ -129,7 +129,7 @@ class PeerExchangeHandler implements MessageListener {
|
||||||
log.warn("My node address is still null at sendGetPeersRequest. We ignore that call.");
|
log.warn("My node address is still null at sendGetPeersRequest. We ignore that call.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped that handler already. We ignore that sendGetPeersRequest call.");
|
log.trace("We have stopped that handler already. We ignore that sendGetPeersRequest call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class PeerExchangeHandler implements MessageListener {
|
||||||
nonce, getPeersResponse.requestNonce);
|
nonce, getPeersResponse.requestNonce);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped that handler already. We ignore that onMessage call.");
|
log.trace("We have stopped that handler already. We ignore that onMessage call.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue