Return result of Network.connectPeer() back to caller.

This commit is contained in:
CalDescent 2022-01-05 18:34:54 +00:00
parent b2c4bf96af
commit 60d038b367

View File

@ -283,10 +283,8 @@ public class Network {
LOGGER.info("Making connection to peer {} to request files for signature {}...", peerAddressString, Base58.encode(signature)); LOGGER.info("Making connection to peer {} to request files for signature {}...", peerAddressString, Base58.encode(signature));
Peer peer = new Peer(peerData); Peer peer = new Peer(peerData);
peer.addPendingSignatureRequest(signature); peer.addPendingSignatureRequest(signature);
this.connectPeer(peer); return this.connectPeer(peer);
// If connection is successful, data will automatically be requested // If connection (and handshake) is successful, data will automatically be requested
// TODO: maybe we could block here (with a timeout) and return once we know the result of the file request
return true;
} }
else if (!isHandshaked) { else if (!isHandshaked) {
LOGGER.info("Peer {} is connected but not handshaked. Not attempting a new connection.", peerAddress); LOGGER.info("Peer {} is connected but not handshaked. Not attempting a new connection.", peerAddress);
@ -730,14 +728,14 @@ public class Network {
} }
} }
private void connectPeer(Peer newPeer) throws InterruptedException { private boolean connectPeer(Peer newPeer) throws InterruptedException {
SocketChannel socketChannel = newPeer.connect(this.channelSelector); SocketChannel socketChannel = newPeer.connect(this.channelSelector);
if (socketChannel == null) { if (socketChannel == null) {
return; return false;
} }
if (Thread.currentThread().isInterrupted()) { if (Thread.currentThread().isInterrupted()) {
return; return false;
} }
synchronized (this.connectedPeers) { synchronized (this.connectedPeers) {
@ -745,6 +743,8 @@ public class Network {
} }
this.onPeerReady(newPeer); this.onPeerReady(newPeer);
return true;
} }
private Peer getPeerFromChannel(SocketChannel socketChannel) { private Peer getPeerFromChannel(SocketChannel socketChannel) {