本文整理汇总了Java中org.bitcoinj.net.discovery.PeerDiscovery类的典型用法代码示例。如果您正苦于以下问题:Java PeerDiscovery类的具体用法?Java PeerDiscovery怎么用?Java PeerDiscovery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PeerDiscovery类属于org.bitcoinj.net.discovery包,在下文中一共展示了PeerDiscovery类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addPeerDiscovery
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
/**
* Add addresses from a discovery source to the list of potential peers to connect to. If max connections has not
* been configured, or set to zero, then it's set to the default at this point.
*/
public void addPeerDiscovery(PeerDiscovery peerDiscovery) {
lock.lock();
try {
if (getMaxConnections() == 0)
setMaxConnections(DEFAULT_CONNECTIONS);
peerDiscoverers.add(peerDiscovery);
} finally {
lock.unlock();
}
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:15,代码来源:PeerGroup.java
示例2: shutDown
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Override
protected void shutDown() throws Exception {
// This is run on a separate thread by the Service implementation.
vPingTimer.cancel();
// Blocking close of all sockets.
channels.stopAsync();
channels.awaitTerminated();
for (PeerDiscovery peerDiscovery : peerDiscoverers) {
peerDiscovery.shutdown();
}
if (torClient != null) {
torClient.stop();
}
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:15,代码来源:PeerGroup.java
示例3: peerDiscoveryPolling
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Test
public void peerDiscoveryPolling() throws InterruptedException {
// Check that if peer discovery fails, we keep trying until we have some nodes to talk with.
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean result = new AtomicBoolean();
peerGroup.addPeerDiscovery(new PeerDiscovery() {
@Override
public InetSocketAddress[] getPeers(long unused, TimeUnit unused2) throws PeerDiscoveryException {
if (!result.getAndSet(true)) {
// Pretend we are not connected to the internet.
throw new PeerDiscoveryException("test failure");
} else {
// Return a bogus address.
latch.countDown();
return new InetSocketAddress[]{new InetSocketAddress("localhost", 1)};
}
}
@Override
public void shutdown() {
}
});
peerGroup.startAsync();
peerGroup.awaitRunning();
latch.await();
// Check that we did indeed throw an exception. If we got here it means we threw and then PeerGroup tried
// again a bit later.
assertTrue(result.get());
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:29,代码来源:PeerGroupTest.java
示例4: PeerGroupService
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Inject
public PeerGroupService(NetworkParameters params,
PeerDiscovery peerDiscovery) {
this.netParams = params;
this.peerGroup = new PeerGroup(params);
peerGroup.setUserAgent(userAgentName, appVersion);
peerGroup.addPeerDiscovery(peerDiscovery);
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:9,代码来源:PeerGroupService.java
示例5: PeerService
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Inject
public PeerService(NetworkParameters params,
PeerDiscovery peerDiscovery,
SimpMessageSendingOperations messagingTemplate) {
super(params, peerDiscovery);
this.messagingTemplate = messagingTemplate;
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:8,代码来源:PeerService.java
示例6: createPeerDiscovery
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
private PeerDiscovery createPeerDiscovery(int nrOfAddressesWanted, int port) {
final InetSocketAddress[] addresses = new InetSocketAddress[nrOfAddressesWanted];
for (int addressNr = 0; addressNr < nrOfAddressesWanted; addressNr++) {
// make each address unique by using the counter to increment the port.
addresses[addressNr] = new InetSocketAddress("localhost", port + addressNr);
}
return new PeerDiscovery() {
public InetSocketAddress[] getPeers(long unused, TimeUnit unused2) throws PeerDiscoveryException {
return addresses;
}
public void shutdown() {
}
};
}
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:15,代码来源:PeerGroupTest.java
示例7: buildDiscoveries
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
private static List<PeerDiscovery> buildDiscoveries(Socks5Proxy proxy, NetworkParameters params, String[] seeds) {
List<PeerDiscovery> discoveries = new ArrayList<>(seeds.length);
for (String seed : seeds)
discoveries.add(new Socks5DnsSeedDiscovery(proxy, params, seed));
return discoveries;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:8,代码来源:Socks5DnsDiscovery.java
示例8: getPeers
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
/**
* Returns an array containing all the Bitcoin nodes that have been discovered.
*/
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
ArrayList<InetSocketAddress> list = new ArrayList<>();
for (PeerDiscovery discovery : discoveryList) {
list.addAll(Arrays.asList(discovery.getPeers(services, timeoutValue, timeoutUnit)));
}
return list.toArray(new InetSocketAddress[list.size()]);
}
开发者ID:bisq-network,项目名称:exchange,代码行数:13,代码来源:Socks5MultiDiscovery.java
示例9: PeerGroup
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
/**
* Creates a new PeerGroup allowing you to specify the {@link ClientConnectionManager} which is used to create new
* connections and keep track of existing ones.
*/
private PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager, @Nullable TorClient torClient) {
this.params = checkNotNull(params);
this.chain = chain;
fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
wallets = new CopyOnWriteArrayList<Wallet>();
peerFilterProviders = new CopyOnWriteArrayList<PeerFilterProvider>();
this.torClient = torClient;
// This default sentinel value will be overridden by one of two actions:
// - adding a peer discovery source sets it to the default
// - using connectTo() will increment it by one
maxConnections = 0;
int height = chain == null ? 0 : chain.getBestChainHeight();
versionMessage = new VersionMessage(params, height);
// We never request that the remote node wait for a bloom filter yet, as we have no wallets
versionMessage.relayTxesBeforeFilter = true;
downloadTxDependencies = true;
memoryPool = new MemoryPool();
inactives = new PriorityQueue<PeerAddress>(1, new Comparator<PeerAddress>() {
@Override
public int compare(PeerAddress a, PeerAddress b) {
int result = backoffMap.get(a).compareTo(backoffMap.get(b));
// Sort by port if otherwise equals - for testing
if (result == 0)
result = Ints.compare(a.getPort(), b.getPort());
return result;
}
});
backoffMap = new HashMap<PeerAddress, ExponentialBackoff>();
peers = new CopyOnWriteArrayList<Peer>();
pendingPeers = new CopyOnWriteArrayList<Peer>();
channels = connectionManager;
peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>();
peerEventListeners = new CopyOnWriteArrayList<ListenerRegistration<PeerEventListener>>();
runningBroadcasts = Collections.synchronizedSet(new HashSet<TransactionBroadcast>());
bloomFilterMerger = new FilterMerger(DEFAULT_BLOOM_FILTER_FP_RATE);
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:46,代码来源:PeerGroup.java
示例10: peerPriority
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Test
public void peerPriority() throws Exception {
final List<InetSocketAddress> addresses = Lists.newArrayList(
new InetSocketAddress("localhost", 2000),
new InetSocketAddress("localhost", 2001),
new InetSocketAddress("localhost", 2002)
);
peerGroup.addEventListener(listener);
peerGroup.addPeerDiscovery(new PeerDiscovery() {
@Override
public InetSocketAddress[] getPeers(long unused, TimeUnit unused2) throws PeerDiscoveryException {
return addresses.toArray(new InetSocketAddress[addresses.size()]);
}
@Override
public void shutdown() {
}
});
peerGroup.setMaxConnections(3);
Utils.setMockSleep(true);
peerGroup.startAsync();
peerGroup.awaitRunning();
handleConnectToPeer(0);
handleConnectToPeer(1);
handleConnectToPeer(2);
connectedPeers.take();
connectedPeers.take();
connectedPeers.take();
addresses.clear();
addresses.addAll(Lists.newArrayList(new InetSocketAddress("localhost", 2003)));
stopPeerServer(2);
assertEquals(2002, disconnectedPeers.take().getAddress().getPort()); // peer died
// discovers, connects to new peer
handleConnectToPeer(3);
assertEquals(2003, connectedPeers.take().getAddress().getPort());
stopPeerServer(1);
assertEquals(2001, disconnectedPeers.take().getAddress().getPort()); // peer died
// Alternates trying two offline peers
Utils.passMockSleep();
assertEquals(2001, disconnectedPeers.take().getAddress().getPort());
Utils.passMockSleep();
assertEquals(2002, disconnectedPeers.take().getAddress().getPort());
Utils.passMockSleep();
assertEquals(2001, disconnectedPeers.take().getAddress().getPort());
Utils.passMockSleep();
assertEquals(2002, disconnectedPeers.take().getAddress().getPort());
Utils.passMockSleep();
assertEquals(2001, disconnectedPeers.take().getAddress().getPort());
// Peer 2 comes online
startPeerServer(2);
Utils.passMockSleep();
handleConnectToPeer(2);
assertEquals(2002, connectedPeers.take().getAddress().getPort());
stopPeerServer(2);
assertEquals(2002, disconnectedPeers.take().getAddress().getPort()); // peer died
// Peer 2 is tried before peer 1, since it has a lower backoff due to recent success
Utils.passMockSleep();
assertEquals(2002, disconnectedPeers.take().getAddress().getPort());
Utils.passMockSleep();
assertEquals(2001, disconnectedPeers.take().getAddress().getPort());
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:69,代码来源:PeerGroupTest.java
示例11: peerGroupService
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
@Bean
public PeerGroupService peerGroupService(NetworkParameters params, PeerDiscovery peerDiscovery) {
return new PeerGroupService(params, peerDiscovery);
}
开发者ID:ConsensusJ,项目名称:consensusj,代码行数:5,代码来源:BitcoinConfig.java
示例12: setDiscovery
import org.bitcoinj.net.discovery.PeerDiscovery; //导入依赖的package包/类
/**
* Sets the peer discovery class to use. If none is provided then DNS is used, which is a reasonable default.
*/
public WalletConfig setDiscovery(@Nullable PeerDiscovery discovery) {
this.discovery = discovery;
return this;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:8,代码来源:WalletConfig.java
注:本文中的org.bitcoinj.net.discovery.PeerDiscovery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论