mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Clean up Peer exception handling
This commit is contained in:
parent
0d4daee3c4
commit
7dd1fce5aa
@ -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
|
// 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.
|
// 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.");
|
throw new ProtocolException("Peer does not have a copy of the block chain.");
|
||||||
|
}
|
||||||
// newer clients use checksumming
|
// newer clients use checksumming
|
||||||
serializer.useChecksumming(peerVersion >= 209);
|
serializer.useChecksumming(peerVersion >= 209);
|
||||||
// Handshake is done!
|
// Handshake is done!
|
||||||
|
@ -97,10 +97,8 @@ public class Peer {
|
|||||||
try {
|
try {
|
||||||
conn = new NetworkConnection(address, params, bestHeight, 60000);
|
conn = new NetworkConnection(address, params, bestHeight, 60000);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
log.error("while trying to open connection", ex);
|
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
} catch (ProtocolException ex) {
|
} catch (ProtocolException ex) {
|
||||||
log.error("while trying to negotiate connection", ex);
|
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,13 +223,15 @@ public class PeerGroup {
|
|||||||
handleNewPeer(peer);
|
handleNewPeer(peer);
|
||||||
log.info("running " + peer);
|
log.info("running " + peer);
|
||||||
peer.run();
|
peer.run();
|
||||||
}
|
} catch (RuntimeException ex) {
|
||||||
finally {
|
// 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.
|
// In all cases, put the address back on the queue.
|
||||||
// We will retry this peer after all other peers have been tried.
|
// We will retry this peer after all other peers have been tried.
|
||||||
inactives.add(address);
|
inactives.add(address);
|
||||||
peers.remove(peer);
|
if (peers.remove(peer))
|
||||||
handlePeerDeath(peer);
|
handlePeerDeath(peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user