本文整理汇总了Java中com.google.bitcoin.core.Peer类的典型用法代码示例。如果您正苦于以下问题:Java Peer类的具体用法?Java Peer怎么用?Java Peer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Peer类属于com.google.bitcoin.core包,在下文中一共展示了Peer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlocksDownloaded
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(Peer peer, Block block, int blocksLeft) {
if (caughtUp)
return;
if (blocksLeft == 0) {
caughtUp = true;
doneDownload();
done.release();
}
if (blocksLeft < 0 || originalBlocksLeft <= 0)
return;
long now = System.currentTimeMillis();
long msecsLeft = estimateComplete(now, blocksLeft);
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
long delta = now - lastUpdateTime;
if (delta >= 500) {
progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000), msecsLeft);
lastPercent = (int) pct;
lastUpdateTime = now;
}
}
示例2: redraw
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
private void redraw() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Button broadcastTransactionButton = (Button)findViewById(R.id.scanButton);
ListView peerListView = (ListView)findViewById(R.id.peerList);
List<Peer> connectedPeers = application.getPeerGroup().getConnectedPeers();
application.getPeerListAdapter().replace(connectedPeers);
// Enable button if we're sufficiently connected
if(application.getPeerGroup().numConnectedPeers() >= 3) {
broadcastTransactionButton.setEnabled(true);
} else {
broadcastTransactionButton.setEnabled(false);
}
}
});
}
示例3: getView
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.peer_row, parent, false);
}
Log.i("Adapter", "In getView, position " + position);
Peer peer = values.get(position);
TextView peerName = (TextView) convertView.findViewById(R.id.peerName);
TextView peerAddress = (TextView) convertView.findViewById(R.id.peerAddress);
peerName.setText(peer.getPeerVersionMessage().subVer);
peerAddress.setText(peer.getPeerVersionMessage().theirAddr.toString());
return convertView;
}
示例4: onBlocksDownloaded
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
public void onBlocksDownloaded(Peer peer, Block block, int blocksLeft) {
if (caughtUp)
return;
if (blocksLeft == 0) {
caughtUp = true;
doneDownload();
done.release();
}
if (blocksLeft < 0 || originalBlocksLeft <= 0)
return;
double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft));
if ((int) pct != lastPercent) {
progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000));
lastPercent = (int) pct;
}
}
示例5: lookupReverseDNS
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
private void lookupReverseDNS(final Peer peer) {
new Thread() {
@Override
public void run() {
// This can take a looooong time.
String reverseDns = peer.getAddress().getAddr().getCanonicalHostName();
synchronized (reverseDnsLookups) {
reverseDnsLookups.put(peer, reverseDns);
}
refreshUI();
}
}.start();
}
示例6: getAddressForPeer
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
private Object getAddressForPeer(Peer peer) {
String s;
synchronized (reverseDnsLookups) {
s = reverseDnsLookups.get(peer);
}
if (s != null)
return s;
else
return peer.getAddress().getAddr().getHostAddress();
}
示例7: onChainDownloadStarted
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onChainDownloadStarted(Peer peer, int blocksLeft) {
startDownload(blocksLeft);
originalBlocksLeft = blocksLeft;
if (blocksLeft == 0) {
doneDownload();
done.release();
}
}
示例8: onBlocksDownloaded
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(Peer peer, Block block, int blocksLeft) {
logger.info("Block downloaded: "+blocksLeft);
/*
//this doesn't work
Blocks blocks = Blocks.getInstance();
try {
blocks.importBlock(block, blocks.blockStore.get(block.getHash()).getHeight());
} catch (BlockStoreException e) {
}
*/
}
示例9: initSingletons
import com.google.bitcoin.core.Peer; //导入依赖的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);
}
示例10: onChainDownloadStarted
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
public void onChainDownloadStarted(Peer peer, int blocksLeft) {
Log.d(TAG, String.format("onChainDownloadStarted | peer: %s, blocksLeft: %s", peer.toString(), blocksLeft));
startDownload(blocksLeft);
originalBlocksLeft = blocksLeft;
if (blocksLeft == 0) {
doneDownload();
done.release();
}
}
示例11: onBlocksDownloaded
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onBlocksDownloaded(final Peer peer, final Block block, final int blocksLeft)
{
bestChainHeightEver = Math.max(bestChainHeightEver, blockChain.getChainHead().getHeight());
delayHandler.removeCallbacksAndMessages(null);
final long now = System.currentTimeMillis();
if (now - lastMessageTime.get() > Constants.BLOCKCHAIN_STATE_BROADCAST_THROTTLE_MS)
delayHandler.post(runnable);
else
delayHandler.postDelayed(runnable, Constants.BLOCKCHAIN_STATE_BROADCAST_THROTTLE_MS);
}
示例12: getConnectedPeers
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public List<Peer> getConnectedPeers()
{
if (peerGroup != null)
return peerGroup.getConnectedPeers();
else
return null;
}
示例13: onResume
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onResume()
{
super.onResume();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
adapter.notifyDataSetChanged();
final Loader<String> loader = loaderManager.getLoader(ID_REVERSE_DNS_LOADER);
final boolean loaderRunning = loader != null && loader.isStarted();
if (!loaderRunning)
{
for (int i = 0; i < adapter.getCount(); i++)
{
final Peer peer = adapter.getItem(i);
final InetAddress address = peer.getAddress().getAddr();
if (!hostnames.containsKey(address))
{
final Bundle args = new Bundle();
args.putSerializable("address", address);
loaderManager.initLoader(ID_REVERSE_DNS_LOADER, args, reverseDnsLoaderCallbacks).forceLoad();
break;
}
}
}
handler.postDelayed(this, REFRESH_MS);
}
}, REFRESH_MS);
}
示例14: onLoadFinished
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public void onLoadFinished(final Loader<List<Peer>> loader, final List<Peer> peers)
{
adapter.clear();
if (peers != null)
for (final Peer peer : peers)
adapter.add(peer);
}
示例15: onPreMessageReceived
import com.google.bitcoin.core.Peer; //导入依赖的package包/类
@Override
public Message onPreMessageReceived(Peer peer, Message m) {
if (m instanceof Pong) {
// nothing
} else if (m instanceof InventoryMessage) {
InventoryMessage inv = (InventoryMessage) m;
log.info("[MESSAGE INV] size={}\nitem={}",
inv.getItems().size(),
Joiner.on(",").join(Lists.transform(inv.getItems(), FunInvItemToString)));
} else {
log.info("[MESSAGE] = {}", m);
}
return super.onPreMessageReceived(peer, m);
}