1
1
Here is my code.
params = TestNet3Params.get();
blockStore = new MemoryBlockStore(params);
chain = new BlockChain(params, blockStore);
chain.addWallet(newwallet);
final PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.setUserAgent("PeerMonitor", "1.0");
peerGroup.setMaxConnections(1);
peerGroup.addAddress(new PeerAddress(InetAddresses.forString("192.168.1.253"), 18333));
peerGroup.addEventListener(new AbstractPeerEventListener() {
@Override
public void onPeerDisconnected(Peer peer, int peerCount) {
System.out.println("hello "+peer.getAddress().getAddr().getHostAddress());
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
System.out.println("DNS Added...!!");
}
});
peerGroup.startAsync();
peerGroup.downloadBlockChain();
System.out.println("Full Downloaded...!!");
List<Peer> peers=peerGroup.getConnectedPeers();
System.out.println(peers);
for (Peer peer : peers) {
if(peer.getAddress().getAddr().getHostName().equals("192.168.1.253"))
{
System.out.println("checking peers...!!");
break;
}
}
System.out.println("going to stop...!!");
I want to stop the local peer and switch to the DNS when the downloading gets completed.
I have called peer.close() and it triggers onDisconnected() event but and in this event I am adding DNS to the peerGroup but despite of adding DNS it is still looking for peer. I want to completely switch from peer to DNS – Ankit Sharma – 2015-02-03T08:01:27.320
@AnkitSharma, What do you mean by adding DNS? Do you care which peers you are connected to? And why can you not just add it from the start, why do you have to do it after a peer is disconnected? – morsecoder – 2015-02-03T15:47:21.583
I want to download the bulk data from the bitcoin-qt for the sake of speed as when I download blockchain from DNS from the start it takes too much time. So when all the data has been downloaded from the local peer than I want to switch to the DNS – Ankit Sharma – 2015-02-04T06:24:26.420