Search in sources :

Example 1 with AddressMessage

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();
            }
        }
    }
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) Peer(org.bitcoinj.core.Peer) PeerGroup(org.bitcoinj.core.PeerGroup) ExecutionException(java.util.concurrent.ExecutionException) AddressMessage(org.bitcoinj.core.AddressMessage) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AddressMessage (org.bitcoinj.core.AddressMessage)1 Peer (org.bitcoinj.core.Peer)1 PeerAddress (org.bitcoinj.core.PeerAddress)1 PeerGroup (org.bitcoinj.core.PeerGroup)1