use of org.bitcoinj.core.AddressMessage in project cryptoputty by alokmenghrajani.
the class CrawlerThread method run.
public void run() {
// Continuously get peers and try to connect to them.
while (true) {
PeerGroup peerGroup = CryptoputtyApplication.kit.peerGroup();
if (peerGroup == null) {
continue;
}
List<Peer> connectedPeers = peerGroup.getConnectedPeers();
Collections.shuffle(connectedPeers);
for (Peer peer : connectedPeers) {
try {
Thread.sleep(1000);
AddressMessage newPeers = peer.getAddr().get(5000, TimeUnit.MILLISECONDS);
for (PeerAddress newPeer : newPeers.getAddresses()) {
peerGroup.addAddress(newPeer);
}
} catch (TimeoutException e) {
// Don't do anything...
} catch (InterruptedException | ExecutionException e) {
log.warn("failed to get peers");
e.printStackTrace();
}
}
}
}
Aggregations