当前位置: 首页>>代码示例>>Java>>正文


Java DnsDiscovery类代码示例

本文整理汇总了Java中com.google.bitcoin.net.discovery.DnsDiscovery的典型用法代码示例。如果您正苦于以下问题:Java DnsDiscovery类的具体用法?Java DnsDiscovery怎么用?Java DnsDiscovery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DnsDiscovery类属于com.google.bitcoin.net.discovery包,在下文中一共展示了DnsDiscovery类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void main(String[] args) {
    BriefLogFormatter.init();
    NetworkParameters params = MainNetParams.get();
    PeerGroup peerGroup = new PeerGroup(params);
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));
    peerGroup.addEventListener(new AbstractPeerEventListener() {
        @Override
        public void onTransaction(Peer peer, Transaction tx) {
            try {
                if (tx.getOutputs().size() != 1) return;
                if (!tx.getOutput(0).getScriptPubKey().isSentToRawPubKey()) return;
                log.info("Saw raw pay to pubkey {}", tx);
            } catch (ScriptException e) {
                e.printStackTrace();
            }
        }
    });
    peerGroup.start();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:20,代码来源:WatchMempool.java

示例2: main

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void main(String[] args) {
    BriefLogFormatter.init();
    NetworkParameters params = MainNetParams.get();
    PeerGroup peerGroup = new PeerGroup(params);
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));
    peerGroup.addEventListener(new AbstractPeerEventListener() {
        @Override
        public void onTransaction(Peer peer, Transaction tx) {
            try {
                if (tx.getOutputs().size() != 1) return;
                if (!tx.getOutput(0).getScriptPubKey().isSentToRawPubKey()) return;
                log.info("Saw raw pay to pubkey {}", tx);
            } catch (ScriptException e) {
                e.printStackTrace();
            }
        }
    });
    peerGroup.startAsync();
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:20,代码来源:WatchMempool.java

示例3: printDNS

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
private static void printDNS() throws PeerDiscoveryException {
    long start = System.currentTimeMillis();
    DnsDiscovery dns = new DnsDiscovery(MainNetParams.get());
    dnsPeers = dns.getPeers(10, TimeUnit.SECONDS);
    printPeers(dnsPeers);
    printElapsed(start);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:8,代码来源:PrintPeers.java

示例4: setup

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
private static void setup() throws BlockStoreException {
    if (store != null) return;  // Already done.
    // Will create a fresh chain if one doesn't exist or there is an issue with this one.
    if (!chainFileName.exists() && wallet.getTransactions(true).size() > 0) {
        // No chain, so reset the wallet as we will be downloading from scratch.
        System.out.println("Chain file is missing so clearing transactions from the wallet.");
        reset();
    }
    if (mode == ValidationMode.SPV) {
        store = new SPVBlockStore(params, chainFileName);
        chain = new BlockChain(params, wallet, store);
    } else if (mode == ValidationMode.FULL) {
        FullPrunedBlockStore s = new H2FullPrunedBlockStore(params, chainFileName.getAbsolutePath(), 5000);
        store = s;
        chain = new FullPrunedBlockChain(params, wallet, s);
    }
    // This will ensure the wallet is saved when it changes.
    wallet.autosaveToFile(walletFile, 200, TimeUnit.MILLISECONDS, null);
    peers = new PeerGroup(params, chain);
    peers.setUserAgent("WalletTool", "1.0");
    peers.addWallet(wallet);
    if (options.has("peers")) {
        String peersFlag = (String) options.valueOf("peers");
        String[] peerAddrs = peersFlag.split(",");
        for (String peer : peerAddrs) {
            try {
                peers.addAddress(new PeerAddress(InetAddress.getByName(peer), params.getPort()));
            } catch (UnknownHostException e) {
                System.err.println("Could not understand peer domain name/IP address: " + peer + ": " + e.getMessage());
                System.exit(1);
            }
        }
    } else {
        peers.addPeerDiscovery(new DnsDiscovery(params));
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:37,代码来源:WalletTool.java

示例5: initSingletons

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
protected void initSingletons()
{
    // Initialize the instance of MySingleton
    peerGroup = new PeerGroup(Constants.NETWORK_PARAMETERS);
    peerGroup.setMaxConnections(5);
    peerGroup.setUserAgent("ArmoryCompanion Android", Constants.VERSION, "Relaying txs like a boss");
    peerGroup.addPeerDiscovery(new DnsDiscovery(Constants.NETWORK_PARAMETERS));
    peerGroup.start();
    List<Peer> connectedPeers = peerGroup.getConnectedPeers();
    peerListAdapter = new PeerListAdapter(this, connectedPeers);
}
 
开发者ID:hank,项目名称:armorycompanion,代码行数:12,代码来源:ArmoryCompanionApplication.java

示例6: startUp

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
@SuppressLint("NewApi")
@Override
   protected void startUp() throws Exception {
       // Runs in a separate thread.
       if (!directory.exists()) {
           if (!directory.mkdir()) {
               throw new IOException("Could not create named directory.");
           }
       }
       FileInputStream walletStream = null;
       try {
           File chainFile = new File(directory, filePrefix + ".spvchain");
           boolean chainFileExists = chainFile.exists();
           vWalletFile = new File(directory, filePrefix + ".wallet");
           boolean shouldReplayWallet = vWalletFile.exists() && !chainFileExists;

           vStore = new SPVBlockStore(params, chainFile);
           if (!chainFileExists && checkpoints != null) {
               mLogger.info(String.format("checkpoint at time %d", scanTime));
               CheckpointManager.checkpoint(params, checkpoints, vStore, scanTime);
           }
           vChain = new BlockChain(params, vStore);
           vPeerGroup = new PeerGroup(params, vChain);
           if (this.userAgent != null)
               vPeerGroup.setUserAgent(userAgent, version);
           if (vWalletFile.exists()) {
               walletStream = new FileInputStream(vWalletFile);
               vWallet = new Wallet(params);
               addWalletExtensions(); // All extensions must be present before we deserialize
               new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
               if (shouldReplayWallet)
                   vWallet.clearTransactions(0);
           } else {
               if (keyCrypter == null)
                   vWallet = new Wallet(params);
               else
                   vWallet = new Wallet(params, keyCrypter);
               // vWallet.addKey(new ECKey());
               addWalletExtensions();
           }
           if (useAutoSave) vWallet.autosaveToFile(vWalletFile, 1, TimeUnit.SECONDS, null);
           // Set up peer addresses or discovery first, so if wallet extensions try to broadcast a transaction
           // before we're actually connected the broadcast waits for an appropriate number of connections.
           if (peerAddresses != null) {
               for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr);
               peerAddresses = null;
           } else {
               vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
           }
           vChain.addWallet(vWallet);
           vPeerGroup.addWallet(vWallet);
           onSetupCompleted();

           if (blockingStartup) {
               vPeerGroup.startAndWait();
               // Make sure we shut down cleanly.
               installShutdownHook();
               MyDownloadListener listener = (this.downloadListener != null) ? this.downloadListener : new MyDownloadListener();
               vPeerGroup.startBlockChainDownload(listener);
               listener.await();
           } else {
               Futures.addCallback(vPeerGroup.start(), new FutureCallback<State>() {
                   @Override
                   public void onSuccess(State result) {
                       final PeerEventListener l = downloadListener == null ? new MyDownloadListener() : downloadListener;
                       vPeerGroup.startBlockChainDownload(l);
                   }

                   @Override
                   public void onFailure(Throwable t) {
                       throw new RuntimeException(t);
                   }
               });
           }
       } catch (BlockStoreException e) {
           throw new IOException(e);
       } finally {
           if (walletStream != null) walletStream.close();
       }
   }
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:81,代码来源:MyWalletAppKit.java

示例7: startPeerGroup

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
public void startPeerGroup() throws Exception
    {
        final String lockName = context.getPackageName() + " peer connection";
        final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

        ConnectionDetector cd = new ConnectionDetector(context.getApplicationContext());

        if (cd.isConnectingToInternet())
        {
            Log.d(TAG, "acquiring wakelock");
            wakeLock.acquire();

            Log.d(TAG, "starting peergroup");
            peerGroup.setFastCatchupTimeSecs(application.getAhimsaWallet().getEarliestKeyCreationTime());
            peerGroup.setUserAgent(Constants.USER_AGENT, Constants.VERSION);
            Log.d(TAG, "started peergroup");


            final boolean hasTrustedPeer = !config.getTrustedPeer().isEmpty();
            peerGroup.setMaxConnections(hasTrustedPeer ? 1 : config.getMaxConnectedPeers());
            peerGroup.addPeerDiscovery(new PeerDiscovery()
            {
                private final PeerDiscovery normalPeerDiscovery = new DnsDiscovery(Constants.NETWORK_PARAMETERS);

                @Override
                public InetSocketAddress[] getPeers(final long timeoutValue, final TimeUnit timeoutUnit) throws PeerDiscoveryException
                {
                    final List<InetSocketAddress> peers = new LinkedList<InetSocketAddress>();

                    boolean needsTrimPeersWorkaround = false;

                    if (hasTrustedPeer)
                    {
                        Log.d(TAG, "trusted peer '" + config.getTrustedPeer() + "'" + (hasTrustedPeer ? " only" : ""));

                        final InetSocketAddress addr = new InetSocketAddress(config.getTrustedPeer(), Constants.NETWORK_PARAMETERS.getPort());
                        if (addr.getAddress() != null)
                        {
                            peers.add(addr);
                            needsTrimPeersWorkaround = true;
                        }
                    }

                    if (!hasTrustedPeer)
                        peers.addAll(Arrays.asList(normalPeerDiscovery.getPeers(timeoutValue, timeoutUnit)));

                    // workaround because PeerGroup will shuffle peers
                    if (needsTrimPeersWorkaround)
                        while (peers.size() >= config.getMaxConnectedPeers())
                            peers.remove(peers.size() - 1);

                    return peers.toArray(new InetSocketAddress[0]);
                }

                @Override
                public void shutdown()
                {
                    normalPeerDiscovery.shutdown();
                }
            });

            peerGroup.startAsync();

//            ListenableFuture<PeerGroup> future2 = peerGroup.waitForPeers(config.getMinConnectedPeers());
//            future2.get(config.getTimeout(), TimeUnit.SECONDS);

            Log.d(TAG, "pending peers  : " + peerGroup.getPendingPeers());
            Log.d(TAG, "connected peers: " + peerGroup.getConnectedPeers());
        }
        else
        {
            throw new RuntimeException("No internet connection present");
        }
    }
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:76,代码来源:BitcoinNode.java

示例8: setup

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
private static void setup() throws BlockStoreException {
    if (store != null) return;  // Already done.
    // Will create a fresh chain if one doesn't exist or there is an issue with this one.
    if (!chainFileName.exists() && wallet.getTransactions(true).size() > 0) {
        // No chain, so reset the wallet as we will be downloading from scratch.
        System.out.println("Chain file is missing so clearing transactions from the wallet.");
        reset();
    }
    if (mode == ValidationMode.SPV) {
        store = new SPVBlockStore(params, chainFileName);
        chain = new BlockChain(params, wallet, store);
    } else if (mode == ValidationMode.FULL) {
        FullPrunedBlockStore s = new H2FullPrunedBlockStore(params, chainFileName.getAbsolutePath(), 5000);
        store = s;
        chain = new FullPrunedBlockChain(params, wallet, s);
    }
    // This will ensure the wallet is saved when it changes.
    wallet.autosaveToFile(walletFile, 200, TimeUnit.MILLISECONDS, null);
    peers = new PeerGroup(params, chain);
    peers.setUserAgent("WalletTool", "1.0");
    peers.addWallet(wallet);
    if (options.has("peers")) {
        String peersFlag = (String) options.valueOf("peers");
        String[] peerAddrs = peersFlag.split(",");
        for (String peer : peerAddrs) {
            try {
                peers.addAddress(new PeerAddress(InetAddress.getByName(peer), params.getPort()));
            } catch (UnknownHostException e) {
                System.err.println("Could not understand peer domain name/IP address: " + peer + ": " + e.getMessage());
                System.exit(1);
            }
        }
    } else {
        if (params == RegTestParams.get()) {
            log.info("Assuming regtest node on localhost");
            peers.addAddress(InetAddress.getLoopbackAddress());
        } else {
            peers.addPeerDiscovery(new DnsDiscovery(params));
        }
    }
}
 
开发者ID:keremhd,项目名称:mintcoinj,代码行数:42,代码来源:WalletTool.java

示例9: main

import com.google.bitcoin.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void main(String[] args) {
	BriefLogFormatter.init();
	NetworkParameters params = MainNetParams.get();
	PeerGroup peerGroup = new PeerGroup(params);
	peerGroup.addPeerDiscovery(new DnsDiscovery(params));
	peerGroup.addEventListener(new AbstractPeerEventListener() {
		private boolean _debug = true;

		@Override
		public void onTransaction(Peer peer, Transaction tx) {
			try {
				log.info("TxLockTime {}", tx.getLockTime());
				log.info("TxIn{}/Out{}", tx.getInputs().size(), tx
						.getOutputs().size());
				log.info("Saw Tx {}", tx);
				if (_debug) {
					for (TransactionInput tin : tx.getInputs()) {
						log.info("InputSequenceNumber {}",
								tin.getSequenceNumber());

						if (tin.getSequenceNumber() == TransactionInput.NO_SEQUENCE) {
							log.info("InputSequenceNumber==UINT_MAX lock time ignored");
						}

						log.info("InputScriptSig {}", tin.getScriptSig()
								.toString());
						log.info("InputOutpoint previous output hash {}",
								tin.getOutpoint().getHash());
						log.info("InputOutpoint previous output index {}",
								tin.getOutpoint().getIndex());
						TransactionOutput tout = tin.getOutpoint()
								.getConnectedOutput();
						// Map<Sha256Hash, Integer> appearInHashes =
						// preTx.getAppearsInHashes();
						log.info("OutpointTx output", tout);
					}
				}
			} catch (ScriptException e) {
				e.printStackTrace();
			}
		}
	});
	peerGroup.start();
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:45,代码来源:BitcoinMainWatchPeerGroup.java


注:本文中的com.google.bitcoin.net.discovery.DnsDiscovery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。