Skip to content

Commit

Permalink
Add numAllConnectionsLostEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 committed Oct 21, 2020
1 parent 998fb77 commit 6973a1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
inventory.put(InventoryItem.maxConnections, String.valueOf(maxConnections));
inventory.put(InventoryItem.numConnections, String.valueOf(networkNode.getAllConnections().size()));
inventory.put(InventoryItem.peakNumConnections, String.valueOf(peerManager.getPeakNumConnections()));
inventory.put(InventoryItem.numAllConnectionsLostEvents, String.valueOf(peerManager.getNumAllConnectionsLostEvents()));
inventory.put(InventoryItem.sentBytes, String.valueOf(Statistic.totalSentBytesProperty().get()));
inventory.put(InventoryItem.sentBytesPerSec, String.valueOf(Statistic.totalSentBytesPerSecProperty().get()));
inventory.put(InventoryItem.receivedBytes, String.valueOf(Statistic.totalReceivedBytesProperty().get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum InventoryItem {
maxConnections("maxConnections", Integer.class, 0.33, 3, 0.4, 2.5),
numConnections("numConnections", Integer.class, 0.33, 3, 0.4, 2.5),
peakNumConnections("peakNumConnections", Integer.class, 0.33, 3, 0.4, 2.5),
numAllConnectionsLostEvents("numAllConnectionsLostEvents", Integer.class, 0.9, 1.1, 0.95, 1.05),
sentBytes("sentBytes", Long.class, 0, 5, 0, 4),
sentBytesPerSec("sentBytesPerSec", Double.class, 0, 3, 0, 2),
receivedBytes("receivedBytes", Long.class, 0, 5, 0, 4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private String getNetworkInfo(RequestInfo requestInfo,
addInventoryItem("Max. connections: ", requestInfo, averageValues, sb, InventoryItem.maxConnections);
addInventoryItem("Number of connections: ", requestInfo, averageValues, sb, InventoryItem.numConnections);
addInventoryItem("Peak number of connections: ", requestInfo, averageValues, sb, InventoryItem.peakNumConnections);

addInventoryItem("Number of 'All connections lost' events: ", requestInfo, averageValues, sb, InventoryItem.numAllConnectionsLostEvents);
addInventoryItem("Sent messages/sec: ", requestInfo, averageValues, sb, InventoryItem.sentMessagesPerSec,
value -> String.valueOf(MathUtils.roundDouble(Double.parseDouble(value), 2)));
addInventoryItem("Received messages/sec: ", requestInfo, averageValues, sb, InventoryItem.receivedMessagesPerSec,
Expand Down
14 changes: 14 additions & 0 deletions p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public interface Listener {
private int peakNumConnections;
@Setter
private boolean allowDisconnectSeedNodes;
@Getter
private int numAllConnectionsLostEvents;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -208,6 +210,9 @@ public void onConnection(Connection connection) {
if (lostAllConnections) {
lostAllConnections = false;
stopped = false;
log.info("\n------------------------------------------------------------\n" +
"Established a new connection from/to {} after all connections lost.\n" +
"------------------------------------------------------------", connection.getPeersNodeAddressOptional());
listeners.forEach(Listener::onNewConnectionAfterAllConnectionsLost);
}
connection.getPeersNodeAddressOptional()
Expand All @@ -220,13 +225,22 @@ public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection
log.info("onDisconnect called: nodeAddress={}, closeConnectionReason={}",
connection.getPeersNodeAddressOptional(), closeConnectionReason);
handleConnectionFault(connection);

boolean previousLostAllConnections = lostAllConnections;
lostAllConnections = networkNode.getAllConnections().isEmpty();

// If we enter to 'All connections lost' we count the event.
if (!previousLostAllConnections && lostAllConnections) {
numAllConnectionsLostEvents++;
}

if (lostAllConnections) {
stopped = true;
log.warn("\n------------------------------------------------------------\n" +
"All connections lost\n" +
"------------------------------------------------------------");
listeners.forEach(Listener::onAllConnectionsLost);

}
maybeRemoveBannedPeer(closeConnectionReason, connection);
}
Expand Down

0 comments on commit 6973a1f

Please sign in to comment.