mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 08:25:23 -04:00
Use uid for connections set storage key, add more logs
This commit is contained in:
parent
4544fe6c83
commit
75af3adb81
2 changed files with 30 additions and 21 deletions
|
@ -420,19 +420,13 @@ public class Connection implements MessageListener {
|
||||||
|
|
||||||
Connection that = (Connection) o;
|
Connection that = (Connection) o;
|
||||||
|
|
||||||
if (portInfo != null ? !portInfo.equals(that.portInfo) : that.portInfo != null) return false;
|
return !(uid != null ? !uid.equals(that.uid) : that.uid != null);
|
||||||
//noinspection SimplifiableIfStatement
|
|
||||||
if (uid != null ? !uid.equals(that.uid) : that.uid != null) return false;
|
|
||||||
return peersNodeAddressOptional != null ? peersNodeAddressOptional.equals(that.peersNodeAddressOptional) : that.peersNodeAddressOptional == null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = portInfo != null ? portInfo.hashCode() : 0;
|
return uid != null ? uid.hashCode() : 0;
|
||||||
result = 31 * result + (uid != null ? uid.hashCode() : 0);
|
|
||||||
result = 31 * result + (peersNodeAddressOptional != null ? peersNodeAddressOptional.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -147,7 +147,7 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private InboundConnection getInboundConnection(@NotNull NodeAddress peersNodeAddress) {
|
private InboundConnection getInboundConnection(@NotNull NodeAddress peersNodeAddress) {
|
||||||
Optional<InboundConnection> inboundConnectionOptional = lookupInboundConnection(peersNodeAddress);
|
Optional<InboundConnection> inboundConnectionOptional = lookupInBoundConnection(peersNodeAddress);
|
||||||
if (inboundConnectionOptional.isPresent()) {
|
if (inboundConnectionOptional.isPresent()) {
|
||||||
InboundConnection connection = inboundConnectionOptional.get();
|
InboundConnection connection = inboundConnectionOptional.get();
|
||||||
log.trace("We have found a connection in inBoundConnections. Connection.uid=" + connection.getUid());
|
log.trace("We have found a connection in inBoundConnections. Connection.uid=" + connection.getUid());
|
||||||
|
@ -165,7 +165,7 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private OutboundConnection getOutboundConnection(@NotNull NodeAddress peersNodeAddress) {
|
private OutboundConnection getOutboundConnection(@NotNull NodeAddress peersNodeAddress) {
|
||||||
Optional<OutboundConnection> outboundConnectionOptional = lookupOutboundConnection(peersNodeAddress);
|
Optional<OutboundConnection> outboundConnectionOptional = lookupOutBoundConnection(peersNodeAddress);
|
||||||
if (outboundConnectionOptional.isPresent()) {
|
if (outboundConnectionOptional.isPresent()) {
|
||||||
OutboundConnection connection = outboundConnectionOptional.get();
|
OutboundConnection connection = outboundConnectionOptional.get();
|
||||||
log.trace("We have found a connection in outBoundConnections. Connection.uid=" + connection.getUid());
|
log.trace("We have found a connection in outBoundConnections. Connection.uid=" + connection.getUid());
|
||||||
|
@ -264,6 +264,11 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
||||||
|
log.trace("onDisconnect connectionListener\n\tconnection={}" + connection);
|
||||||
|
if (inBoundConnections.contains(connection))
|
||||||
|
log.warn("We have the connection in our inBoundConnections. That must not happen as it should be called " +
|
||||||
|
"from the server listener and get removed from there.");
|
||||||
|
printOutBoundConnections();
|
||||||
outBoundConnections.remove(connection);
|
outBoundConnections.remove(connection);
|
||||||
// inbound connections are removed in the listener of the server
|
// inbound connections are removed in the listener of the server
|
||||||
connectionListeners.stream().forEach(e -> e.onDisconnect(closeConnectionReason, connection));
|
connectionListeners.stream().forEach(e -> e.onDisconnect(closeConnectionReason, connection));
|
||||||
|
@ -335,7 +340,9 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
|
||||||
|
log.trace("onDisconnect at server socket connectionListener\n\tconnection={}" + connection);
|
||||||
inBoundConnections.remove(connection);
|
inBoundConnections.remove(connection);
|
||||||
|
printInboundConnections();
|
||||||
NetworkNode.this.onDisconnect(closeConnectionReason, connection);
|
NetworkNode.this.onDisconnect(closeConnectionReason, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,28 +357,36 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
executorService.submit(server);
|
executorService.submit(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<OutboundConnection> lookupOutboundConnection(NodeAddress peersNodeAddress) {
|
private Optional<OutboundConnection> lookupOutBoundConnection(NodeAddress peersNodeAddress) {
|
||||||
StringBuilder sb = new StringBuilder("Lookup for peersNodeAddress=");
|
log.trace("lookupOutboundConnection for peersNodeAddress={}", peersNodeAddress.getFullAddress());
|
||||||
sb.append(peersNodeAddress.toString()).append("/ outBoundConnections.size()=")
|
printOutBoundConnections();
|
||||||
.append(outBoundConnections.size()).append("/\n\toutBoundConnections=");
|
|
||||||
outBoundConnections.stream().forEach(e -> sb.append(e).append("\n\t"));
|
|
||||||
log.debug(sb.toString());
|
|
||||||
return outBoundConnections.stream()
|
return outBoundConnections.stream()
|
||||||
.filter(connection -> connection.hasPeersNodeAddress() &&
|
.filter(connection -> connection.hasPeersNodeAddress() &&
|
||||||
peersNodeAddress.equals(connection.getPeersNodeAddressOptional().get())).findAny();
|
peersNodeAddress.equals(connection.getPeersNodeAddressOptional().get())).findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<InboundConnection> lookupInboundConnection(NodeAddress peersNodeAddress) {
|
private void printOutBoundConnections() {
|
||||||
StringBuilder sb = new StringBuilder("Lookup for peersNodeAddress=");
|
StringBuilder sb = new StringBuilder("outBoundConnections size()=")
|
||||||
sb.append(peersNodeAddress.toString()).append("/ inBoundConnections.size()=")
|
.append(outBoundConnections.size()).append("\n\toutBoundConnections=");
|
||||||
.append(inBoundConnections.size()).append("/\n\tinBoundConnections=");
|
outBoundConnections.stream().forEach(e -> sb.append(e).append("\n\t"));
|
||||||
inBoundConnections.stream().forEach(e -> sb.append(e).append("\n\t"));
|
|
||||||
log.debug(sb.toString());
|
log.debug(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<InboundConnection> lookupInBoundConnection(NodeAddress peersNodeAddress) {
|
||||||
|
log.trace("lookupInboundConnection for peersNodeAddress={}", peersNodeAddress.getFullAddress());
|
||||||
|
printInboundConnections();
|
||||||
return inBoundConnections.stream()
|
return inBoundConnections.stream()
|
||||||
.filter(connection -> connection.hasPeersNodeAddress() &&
|
.filter(connection -> connection.hasPeersNodeAddress() &&
|
||||||
peersNodeAddress.equals(connection.getPeersNodeAddressOptional().get())).findAny();
|
peersNodeAddress.equals(connection.getPeersNodeAddressOptional().get())).findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printInboundConnections() {
|
||||||
|
StringBuilder sb = new StringBuilder("inBoundConnections size()=")
|
||||||
|
.append(inBoundConnections.size()).append("\n\tinBoundConnections=");
|
||||||
|
inBoundConnections.stream().forEach(e -> sb.append(e).append("\n\t"));
|
||||||
|
log.debug(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected Socket createSocket(NodeAddress peersNodeAddress) throws IOException;
|
abstract protected Socket createSocket(NodeAddress peersNodeAddress) throws IOException;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue