3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Clean up Peer exception handling

This commit is contained in:
Miron Cuperman (devrandom) 2011-07-20 22:10:14 +00:00
parent 0d4daee3c4
commit 7dd1fce5aa
3 changed files with 14 additions and 7 deletions

View File

@ -100,8 +100,15 @@ public class NetworkConnection {
});
// BitCoinJ is a client mode implementation. That means there's not much point in us talking to other client
// mode nodes because we can't download the data from them we need to find/verify transactions.
if (!versionMessage.hasBlockChain())
if (!versionMessage.hasBlockChain()) {
// Shut down the socket
try {
shutdown();
} catch (IOException ex) {
// ignore exceptions while aborting
}
throw new ProtocolException("Peer does not have a copy of the block chain.");
}
// newer clients use checksumming
serializer.useChecksumming(peerVersion >= 209);
// Handshake is done!

View File

@ -97,10 +97,8 @@ public class Peer {
try {
conn = new NetworkConnection(address, params, bestHeight, 60000);
} catch (IOException ex) {
log.error("while trying to open connection", ex);
throw new RuntimeException(ex);
} catch (ProtocolException ex) {
log.error("while trying to negotiate connection", ex);
throw new RuntimeException(ex);
}
}

View File

@ -223,13 +223,15 @@ public class PeerGroup {
handleNewPeer(peer);
log.info("running " + peer);
peer.run();
}
finally {
} catch (RuntimeException ex) {
// do not propagate RuntimeException - log and try next peer
log.error("error while talking to peer", ex);
} finally {
// In all cases, put the address back on the queue.
// We will retry this peer after all other peers have been tried.
inactives.add(address);
peers.remove(peer);
handlePeerDeath(peer);
if (peers.remove(peer))
handlePeerDeath(peer);
}
}
};