mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Add check for outbound connections at socket creation
This commit is contained in:
parent
5dd89391df
commit
4544fe6c83
1 changed files with 11 additions and 7 deletions
|
@ -89,20 +89,24 @@ public abstract class NetworkNode implements MessageListener, ConnectionListener
|
||||||
throw new TimeoutException("A timeout occurred when creating a socket.");
|
throw new TimeoutException("A timeout occurred when creating a socket.");
|
||||||
|
|
||||||
// Tor needs sometimes quite long to create a connection. To avoid that we get too many double
|
// Tor needs sometimes quite long to create a connection. To avoid that we get too many double
|
||||||
// sided connections we check again if we still don't have an incoming connection.
|
// sided connections we check again if we still don't have any connection for that node address.
|
||||||
Connection inboundConnection = getInboundConnection(peersNodeAddress);
|
Connection existingConnection = getInboundConnection(peersNodeAddress);
|
||||||
if (inboundConnection != null) {
|
if (existingConnection != null)
|
||||||
log.info("We found in the meantime an inbound connection for peersNodeAddress {}, " +
|
existingConnection = getOutboundConnection(peersNodeAddress);
|
||||||
|
|
||||||
|
if (existingConnection != null) {
|
||||||
|
log.info("We found in the meantime a connection for peersNodeAddress {}, " +
|
||||||
"so we use that for sending the message.\n" +
|
"so we use that for sending the message.\n" +
|
||||||
"That happens when Tor needs long for creating a new outbound connection.",
|
"That can happen if Tor needs long for creating a new outbound connection.\n" +
|
||||||
|
"We might have got a new inbound or outbound connection.",
|
||||||
peersNodeAddress.getFullAddress());
|
peersNodeAddress.getFullAddress());
|
||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
log.error("Error at closing socket " + throwable);
|
log.error("Error at closing socket " + throwable);
|
||||||
}
|
}
|
||||||
inboundConnection.sendMessage(message);
|
existingConnection.sendMessage(message);
|
||||||
return inboundConnection;
|
return existingConnection;
|
||||||
} else {
|
} else {
|
||||||
outboundConnection = new OutboundConnection(socket, NetworkNode.this, NetworkNode.this, peersNodeAddress);
|
outboundConnection = new OutboundConnection(socket, NetworkNode.this, NetworkNode.this, peersNodeAddress);
|
||||||
outBoundConnections.add(outboundConnection);
|
outBoundConnections.add(outboundConnection);
|
||||||
|
|
Loading…
Add table
Reference in a new issue