本文整理汇总了Java中org.bitcoinj.net.discovery.PeerDiscoveryException类的典型用法代码示例。如果您正苦于以下问题:Java PeerDiscoveryException类的具体用法?Java PeerDiscoveryException怎么用?Java PeerDiscoveryException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PeerDiscoveryException类属于org.bitcoinj.net.discovery包,在下文中一共展示了PeerDiscoveryException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: nextPeer
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/**
* worker for getPeer()
*/
@Nullable
private InetSocketAddress nextPeer() throws PeerDiscoveryException {
if (seedAddrs == null || seedAddrs.length == 0) {
throw new PeerDiscoveryException("No IP address seeds configured; unable to find any peers");
}
if (pnseedIndex >= seedAddrsResolved.length) {
return null;
}
if (seedAddrsResolved[pnseedIndex] == null) {
seedAddrsResolved[pnseedIndex] = lookup(proxy, seedAddrs[pnseedIndex]);
}
log.error("SeedPeersSocks5Dns::nextPeer: " + seedAddrsResolved[pnseedIndex]);
return seedAddrsResolved[pnseedIndex++];
}
开发者ID:bisq-network,项目名称:exchange,代码行数:20,代码来源:SeedPeersSocks5Dns.java
示例2: printDNS
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的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,项目名称:namecoinj,代码行数:8,代码来源:PrintPeers.java
示例3: peerDiscoveryPolling
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的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: createPeerDiscovery
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的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
示例5: getPeers
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/**
* Returns peer addresses. The actual DNS lookup is performed here.
*/
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
if (services != 0)
throw new PeerDiscoveryException("DNS seeds cannot filter by services: " + services);
try {
InetSocketAddress addr = new InetSocketAddress(DnsLookupTor.lookup(proxy, hostname), params.getPort());
return new InetSocketAddress[]{addr};
} catch (Exception e) {
throw new PeerDiscoveryException(e);
}
}
开发者ID:bisq-network,项目名称:exchange,代码行数:15,代码来源:Socks5DnsDiscovery.java
示例6: getPeers
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的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
示例7: getPeers
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/**
* Returns an array containing all the Bitcoin nodes within the list.
*/
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
if (services != 0)
throw new PeerDiscoveryException("DNS seeds cannot filter by services: " + services);
return seedAddrs;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:10,代码来源:Socks5SeedOnionDiscovery.java
示例8: getPeer
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/**
* Acts as an iterator, returning the address of each node in the list sequentially.
* Once all the list has been iterated, null will be returned for each subsequent query.
*
* @return InetSocketAddress - The address/port of the next node.
* @throws PeerDiscoveryException
*/
@Nullable
public InetSocketAddress getPeer() throws PeerDiscoveryException {
try {
return nextPeer();
} catch (PeerDiscoveryException e) {
throw new PeerDiscoveryException(e);
}
}
开发者ID:bisq-network,项目名称:exchange,代码行数:16,代码来源:SeedPeersSocks5Dns.java
示例9: getPeers
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/**
* Returns an array containing all the Bitcoin nodes within the list.
*/
@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
if (services != 0)
throw new PeerDiscoveryException("DNS seeds cannot filter by services: " + services);
return allPeers();
}
开发者ID:bisq-network,项目名称:exchange,代码行数:10,代码来源:SeedPeersSocks5Dns.java
示例10: printDNS
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
private static void printDNS() throws PeerDiscoveryException {
long start = System.currentTimeMillis();
DnsDiscovery dns = new DnsDiscovery(MainNetParams.get());
dnsPeers = dns.getPeers(0, 10, TimeUnit.SECONDS);
printPeers(dnsPeers);
printElapsed(start);
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:8,代码来源:PrintPeers.java
示例11: connectToAnyPeer
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/** Picks a peer from discovery and connects to it. If connection fails, picks another and tries again. */
protected void connectToAnyPeer() throws PeerDiscoveryException {
final State state = state();
if (!(state == State.STARTING || state == State.RUNNING)) return;
PeerAddress addr = null;
long nowMillis = Utils.currentTimeMillis();
long retryTime = 0;
lock.lock();
try {
if (useLocalhostPeerWhenPossible && maybeCheckForLocalhostPeer()) {
log.info("Localhost peer detected, trying to use it instead of P2P discovery");
maxConnections = 0;
connectToLocalHost();
return;
}
if (!haveReadyInactivePeer(nowMillis)) {
// Release the lock here because we'll probably do slow things like DNS lookups below,
discoverPeers();
groupBackoff.trackSuccess();
nowMillis = Utils.currentTimeMillis();
}
if (inactives.size() == 0) {
log.debug("Peer discovery didn't provide us any more peers, not trying to build new connection.");
return;
}
while (addr == null || (ipv6Unreachable && addr.getAddr() instanceof Inet6Address))
addr = inactives.poll();
retryTime = backoffMap.get(addr).getRetryTime();
} finally {
// discoverPeers might throw an exception if something goes wrong: we then hit this path with addr == null.
retryTime = Math.max(retryTime, groupBackoff.getRetryTime());
lock.unlock();
if (retryTime > nowMillis) {
// Sleep until retry time
final long millis = retryTime - nowMillis;
log.info("Waiting {} msec before next connect attempt {}", millis, addr == null ? "" : "to " + addr);
Utils.sleep(millis);
}
}
// This method constructs a Peer and puts it into pendingPeers.
checkNotNull(addr); // Help static analysis which can't see that addr is always set if we didn't throw above.
connectTo(addr, false, vConnectTimeoutMillis);
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:47,代码来源:PeerGroup.java
示例12: peerPriority
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的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
示例13: connectToAnyPeer
import org.bitcoinj.net.discovery.PeerDiscoveryException; //导入依赖的package包/类
/** Picks a peer from discovery and connects to it. If connection fails, picks another and tries again. */
protected void connectToAnyPeer() throws PeerDiscoveryException {
final State state = state();
if (!(state == State.STARTING || state == State.RUNNING)) return;
PeerAddress addr = null;
long nowMillis = Utils.currentTimeMillis();
long retryTime = 0;
lock.lock();
try {
if (useLocalhostPeerWhenPossible && maybeCheckForLocalhostPeer()) {
log.info("Localhost peer detected, trying to use it instead of P2P discovery");
maxConnections = 0;
connectToLocalHost();
return;
}
if (!haveReadyInactivePeer(nowMillis)) {
discoverPeers();
groupBackoff.trackSuccess();
nowMillis = Utils.currentTimeMillis();
}
if (inactives.size() == 0) {
log.debug("Peer discovery didn't provide us any more peers, not trying to build new connection.");
return;
}
addr = inactives.poll();
retryTime = backoffMap.get(addr).getRetryTime();
} finally {
// discoverPeers might throw an exception if something goes wrong: we then hit this path with addr == null.
retryTime = Math.max(retryTime, groupBackoff.getRetryTime());
lock.unlock();
if (retryTime > nowMillis) {
// Sleep until retry time
final long millis = retryTime - nowMillis;
log.info("Waiting {} msec before next connect attempt {}", millis, addr == null ? "" : "to " + addr);
Utils.sleep(millis);
}
}
// This method constructs a Peer and puts it into pendingPeers.
checkNotNull(addr); // Help static analysis which can't see that addr is always set if we didn't throw above.
connectTo(addr, false, vConnectTimeoutMillis);
}
开发者ID:egordon,项目名称:CoinJoin,代码行数:45,代码来源:PeerGroup.java
注:本文中的org.bitcoinj.net.discovery.PeerDiscoveryException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论