本文整理汇总了Java中nxt.peer.Peer类的典型用法代码示例。如果您正苦于以下问题:Java Peer类的具体用法?Java Peer怎么用?Java Peer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Peer类属于nxt.peer包,在下文中一共展示了Peer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getNextBlocks
import nxt.peer.Peer; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlocks");
request.put("blockId", Convert.toUnsignedLong(curBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return null;
}
JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
if (nextBlocks == null) {
return null;
}
// prevent overloading with blocks
if (nextBlocks.size() > 1440) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
peer.blacklist();
return null;
}
return nextBlocks;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:25,代码来源:BlockchainProcessorImpl.java
示例2: notify
import nxt.peer.Peer; //导入依赖的package包/类
@Override
public void notify(Peer peer) {
JSONObject response = new JSONObject();
JSONArray removedActivePeers = new JSONArray();
JSONObject removedActivePeer = new JSONObject();
removedActivePeer.put("index", Users.getIndex(peer));
removedActivePeers.add(removedActivePeer);
response.put("removedActivePeers", removedActivePeers);
JSONArray removedKnownPeers = new JSONArray();
JSONObject removedKnownPeer = new JSONObject();
removedKnownPeer.put("index", Users.getIndex(peer));
removedKnownPeers.add(removedKnownPeer);
response.put("removedKnownPeers", removedKnownPeers);
JSONArray addedBlacklistedPeers = new JSONArray();
JSONObject addedBlacklistedPeer = new JSONObject();
addedBlacklistedPeer.put("index", Users.getIndex(peer));
addedBlacklistedPeer.put("address", peer.getPeerAddress());
addedBlacklistedPeer.put("announcedAddress", Convert.truncate(peer.getAnnouncedAddress(), "-", 25, true));
if (peer.isWellKnown()) {
addedBlacklistedPeer.put("wellKnown", true);
}
addedBlacklistedPeer.put("software", peer.getSoftware());
addedBlacklistedPeers.add(addedBlacklistedPeer);
response.put("addedBlacklistedPeers", addedBlacklistedPeers);
Users.sendNewDataToAll(response);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:27,代码来源:Users.java
示例3: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("application", Nxt.APPLICATION);
response.put("version", Nxt.VERSION);
response.put("time", Nxt.getEpochTime());
Block lastBlock = Nxt.getBlockchain().getLastBlock();
response.put("lastBlock", lastBlock.getStringId());
response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
response.put("numberOfBlocks", lastBlock.getHeight() + 1);
BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
response.put("isScanning", blockchainProcessor.isScanning());
return response;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:GetBlockchainStatus.java
示例4: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
String peerAddress = req.getParameter("peer");
if (peerAddress == null) {
return MISSING_PEER;
}
Peer peer = Peers.getPeer(peerAddress);
if (peer == null) {
return UNKNOWN_PEER;
}
return JSONData.peer(peer);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:17,代码来源:GetPeer.java
示例5: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest request)
throws NxtException {
JSONObject response = new JSONObject();
String peerAddress = request.getParameter("peer");
if (peerAddress == null) {
return MISSING_PEER;
}
Peer peer = Peers.getPeer(peerAddress);
if (peer == null) {
//maybe add as new peer?
return UNKNOWN_PEER;
} else {
peer.blacklist();
response.put("done", true);
}
return response;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:21,代码来源:BlacklistPeer.java
示例6: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONObject processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("application", Nxt.APPLICATION);
response.put("version", Nxt.VERSION);
response.put("time", Nxt.getEpochTime());
Block lastBlock = Nxt.getBlockchain().getLastBlock();
response.put("lastBlock", lastBlock.getStringId());
response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
response.put("numberOfBlocks", lastBlock.getHeight() + 1);
BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
response.put("isScanning", blockchainProcessor.isScanning());
return response;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:18,代码来源:GetBlockchainStatus.java
示例7: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
boolean active = "true".equalsIgnoreCase(req.getParameter("active"));
String stateValue = Convert.emptyToNull(req.getParameter("state"));
boolean includePeerInfo = "true".equalsIgnoreCase(req.getParameter("includePeerInfo"));
JSONArray peers = new JSONArray();
for (Peer peer : active ? Peers.getActivePeers() : stateValue != null ? Peers.getPeers(Peer.State.valueOf(stateValue)) : Peers.getAllPeers()) {
peers.add(includePeerInfo ? JSONData.peer(peer) : peer.getPeerAddress());
}
JSONObject response = new JSONObject();
response.put("peers", peers);
return response;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:17,代码来源:GetPeers.java
示例8: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest request)
throws NxtException {
JSONObject response = new JSONObject();
String peerAddress = request.getParameter("peer");
if (peerAddress == null) {
return MISSING_PEER;
}
Peer peer = Peers.addPeer(peerAddress);
if (peer != null) {
Peers.connectPeer(peer);
response = JSONData.peer(peer);
} else {
response.put("error", "Failed to add peer");
}
return response;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:22,代码来源:AddPeer.java
示例9: advertisesBetterChain
import nxt.peer.Peer; //导入依赖的package包/类
private boolean advertisesBetterChain(Peer peer) {
JSONObject response = peer.send(getCumulativeDifficultyRequest);
Logger.logDebugMessage("advertisesBetterChain "+response);
if (response == null) {
return false;
}
BigInteger myCumulativeDifficulty = ((BlockPOW)blockchain.getLastBlock()).getCumulativeDifficulty();
String peerCumulativeDifficulty = (String) response.get("cumulativeDifficulty");
if (peerCumulativeDifficulty == null) {
return false;
}
BigInteger betterCumulativeDifficulty = new BigInteger(peerCumulativeDifficulty);
return betterCumulativeDifficulty.compareTo(myCumulativeDifficulty) == 1;
/*
if (response.get("blockchainHeight") != null) {
lastBlockchainFeeder = peer;
lastBlockchainFeederHeight = ((Long) response.get("blockchainHeight")).intValue();
}
if (betterCumulativeDifficulty.equals(myCumulativeDifficulty)) {
return false;
}
*/
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:26,代码来源:GetBlocksFromPeers.java
示例10: getNextBlocks
import nxt.peer.Peer; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlocks");
request.put("blockId", Convert.toUnsignedLong(curBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return null;
}
JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
if (nextBlocks == null) {
return null;
}
/*
// prevent overloading with blocks
if (nextBlocks.size() > 720) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
peer.blacklist();
return null;
}*/
return nextBlocks;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:26,代码来源:GetBlocksFromPeers.java
示例11: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest request)
throws NxtException {
JSONObject response = new JSONObject();
String peerAddress = request.getParameter("peer");
if (peerAddress == null) {
return MISSING_PEER;
}
Peer peer = Peers.findOrCreatePeer(peerAddress, true);
if (peer == null) {
return UNKNOWN_PEER;
} else {
Peers.addPeer(peer);
peer.blacklist("Manual blacklist");
response.put("done", true);
}
return response;
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:21,代码来源:BlacklistPeer.java
示例12: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONObject processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("application", Nxt.APPLICATION);
response.put("version", Nxt.VERSION);
response.put("time", Nxt.getEpochTime());
Block lastBlock = Nxt.getBlockchain().getLastBlock();
response.put("lastBlock", lastBlock.getStringId());
response.put("cumulativeDifficulty", lastBlock.getCumulativeDifficulty().toString());
response.put("numberOfBlocks", lastBlock.getHeight() + 1);
BlockchainProcessor blockchainProcessor = Nxt.getBlockchainProcessor();
Peer lastBlockchainFeeder = blockchainProcessor.getLastBlockchainFeeder();
response.put("lastBlockchainFeeder", lastBlockchainFeeder == null ? null : lastBlockchainFeeder.getAnnouncedAddress());
response.put("lastBlockchainFeederHeight", blockchainProcessor.getLastBlockchainFeederHeight());
response.put("isScanning", blockchainProcessor.isScanning());
response.put("isDownloading", blockchainProcessor.isDownloading());
response.put("maxRollback", Constants.MAX_ROLLBACK);
response.put("currentMinRollbackHeight", Nxt.getBlockchainProcessor().getMinRollbackHeight());
response.put("isTestnet", Constants.isTestnet);
response.put("maxPrunableLifetime", Constants.MAX_PRUNABLE_LIFETIME);
response.put("includeExpiredPrunable", Constants.INCLUDE_EXPIRED_PRUNABLE);
return response;
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:24,代码来源:GetBlockchainStatus.java
示例13: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
String peerAddress = req.getParameter("peer");
if (peerAddress == null) {
return MISSING_PEER;
}
Peer peer = Peers.findOrCreatePeer(peerAddress, false);
if (peer == null) {
return UNKNOWN_PEER;
}
return JSONData.peer(peer);
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:17,代码来源:GetPeer.java
示例14: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
boolean active = "true".equalsIgnoreCase(req.getParameter("active"));
String stateValue = Convert.emptyToNull(req.getParameter("state"));
boolean includePeerInfo = "true".equalsIgnoreCase(req.getParameter("includePeerInfo"));
Collection<? extends Peer> peers = active ? Peers.getActivePeers() : stateValue != null ? Peers.getPeers(Peer.State.valueOf(stateValue)) : Peers.getAllPeers();
JSONArray peersJSON = new JSONArray();
if (includePeerInfo) {
peers.forEach(peer -> peersJSON.add(JSONData.peer(peer)));
} else {
peers.forEach(peer -> peersJSON.add(peer.getHost()));
}
JSONObject response = new JSONObject();
response.put("peers", peersJSON);
return response;
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:20,代码来源:GetPeers.java
示例15: processRequest
import nxt.peer.Peer; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest request)
throws NxtException {
String peerAddress = Convert.emptyToNull(request.getParameter("peer"));
if (peerAddress == null) {
return MISSING_PEER;
}
JSONObject response = new JSONObject();
Peer peer = Peers.findOrCreatePeer(peerAddress, true);
if (peer != null) {
boolean isNewlyAdded = Peers.addPeer(peer, peerAddress);
Peers.connectPeer(peer);
response = JSONData.peer(peer);
response.put("isNewlyAdded", isNewlyAdded);
} else {
response.put("errorCode", 8);
response.put("errorDescription", "Failed to add peer");
}
return response;
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:21,代码来源:AddPeer.java
示例16: getNextBlocks
import nxt.peer.Peer; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, long curBlockId) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlocks");
request.put("blockId", Convert.toUnsignedLong(curBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return null;
}
JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
if (nextBlocks == null) {
return null;
}
// prevent overloading with blocks
if (nextBlocks.size() > 720) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
peer.blacklist();
return null;
}
return nextBlocks;
}
开发者ID:Ziftr,项目名称:nxt,代码行数:25,代码来源:BlockchainProcessorImpl.java
示例17: onPeerEvent
import nxt.peer.Peer; //导入依赖的package包/类
@Inject
@Optional
private void onPeerEvent(@UIEventTopic(INxtService.TOPIC_PEER) Peer peer) {
if (peersText != null && !peersText.isDisposed()) {
int active = nxt.getAllConnectedPeers().size();
int known = nxt.getAllWellknownPeers().size();
int blacklisted = nxt.getAllBlacklistedPeers().size();
peersText.setText(createPeerText(active, known, blacklisted));
peersText.pack();
long downloadVolume = 0;
long uploadVolume = 0;
for (Peer p : nxt.getAllConnectedPeers()) {
downloadVolume += p.getDownloadedVolume();
uploadVolume += p.getUploadedVolume();
}
downloadsText.setText(createDownloadsText(downloadVolume, uploadVolume));
downloadsText.pack();
mainComposite.layout();
}
}
开发者ID:incentivetoken,项目名称:offspring,代码行数:24,代码来源:StatusBar.java
示例18: getElements
import nxt.peer.Peer; //导入依赖的package包/类
@Override
public Object[] getElements(Object inputElement) {
if (nxt == null) { return new Object[0]; }
List<Peer> peers = null;
if (peerType == PeerTable.TYPE_ACTIVE_PEERS) {
peers = nxt.getAllConnectedPeers();
}
else if (peerType == PeerTable.TYPE_KNOWN_PEERS) {
peers = nxt.getAllWellknownPeers();
}
else if (peerType == PeerTable.TYPE_BLACKLISTED_PEERS) {
peers = nxt.getAllBlacklistedPeers();
}
if (peers == null) { return new Object[0]; }
return peers.toArray(new Object[peers.size()]);
}
开发者ID:incentivetoken,项目名称:offspring,代码行数:19,代码来源:PeerContentProvider.java
示例19: getNextBlocks
import nxt.peer.Peer; //导入依赖的package包/类
private JSONArray getNextBlocks(Peer peer, Long curBlockId) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlocks");
request.put("blockId", Convert.toUnsignedLong(curBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return null;
}
JSONArray nextBlocks = (JSONArray) response.get("nextBlocks");
if (nextBlocks == null) {
return null;
}
// prevent overloading with blocks
if (nextBlocks.size() > 1440) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
peer.blacklist();
return null;
}
return nextBlocks;
}
开发者ID:aspnmy,项目名称:NasCoin,代码行数:25,代码来源:BlockchainProcessorImpl.java
示例20: run
import nxt.peer.Peer; //导入依赖的package包/类
@Override
public void run() {
try {
try {
Peer peer = Peers.getAnyPeer(Peer.State.CONNECTED, true);
if (peer == null) {
return;
}
JSONObject response = peer.send(getUnconfirmedTransactionsRequest);
if (response == null) {
return;
}
JSONArray transactionsData = (JSONArray)response.get("unconfirmedTransactions");
if (transactionsData == null || transactionsData.size() == 0) {
return;
}
processPeerTransactions(transactionsData, false);
} catch (Exception e) {
Logger.logDebugMessage("Error processing unconfirmed transactions from peer", e);
}
} catch (Throwable t) {
Logger.logMessage("CRITICAL ERROR. PLEASE REPORT TO THE DEVELOPERS.\n" + t.toString());
t.printStackTrace();
System.exit(1);
}
}
开发者ID:aspnmy,项目名称:NasCoin,代码行数:27,代码来源:TransactionProcessorImpl.java
注:本文中的nxt.peer.Peer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论