本文整理汇总了Java中nxt.peer.Peer.blacklist方法的典型用法代码示例。如果您正苦于以下问题:Java Peer.blacklist方法的具体用法?Java Peer.blacklist怎么用?Java Peer.blacklist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nxt.peer.Peer
的用法示例。
在下文中一共展示了Peer.blacklist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: getNextBlocks
import nxt.peer.Peer; //导入方法依赖的package包/类
private JSONArray getNextBlocks(Peer paramAnonymousPeer, Long paramAnonymousLong)
{
JSONObject localJSONObject1 = new JSONObject();
localJSONObject1.put("requestType", "getNextBlocks");
localJSONObject1.put("blockId", Convert.toUnsignedLong(paramAnonymousLong));
JSONObject localJSONObject2 = paramAnonymousPeer.send(JSON.prepareRequest(localJSONObject1));
if (localJSONObject2 == null) {
return null;
}
JSONArray localJSONArray = (JSONArray)localJSONObject2.get("nextBlocks");
if (localJSONArray == null) {
return null;
}
if (localJSONArray.size() > 1440)
{
Logger.logDebugMessage("Obsolete or rogue peer " + paramAnonymousPeer.getPeerAddress() + " sends too many nextBlocks, blacklisting");
paramAnonymousPeer.blacklist();
return null;
}
return localJSONArray;
}
示例7: getCommonBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonBlockId(Peer peer, long commonBlockId) {
while (true) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlockIds");
request.put("blockId", Convert.toUnsignedLong(commonBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return 0;
}
JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
if (nextBlockIds == null || nextBlockIds.size() == 0) {
return 0;
}
// prevent overloading with blockIds
if (nextBlockIds.size() > 1440) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlockIds, blacklisting");
peer.blacklist();
return 0;
}
for (Object nextBlockId : nextBlockIds) {
long blockId = Convert.parseUnsignedLong((String) nextBlockId);
if (! BlockDb.hasBlock(blockId)) {
return commonBlockId;
}
commonBlockId = blockId;
}
}
}
示例8: getCommonBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonBlockId(Peer peer, long commonBlockId) {
while (true) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlockIds");
request.put("blockId", Convert.toUnsignedLong(commonBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return 0;
}
JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
if (nextBlockIds == null || nextBlockIds.size() == 0) {
return 0;
}
// prevent overloading with blockIds
if (nextBlockIds.size() > 1440) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlockIds, blacklisting");
peer.blacklist();
return 0;
}
for (Object nextBlockId : nextBlockIds) {
long blockId = Convert.parseUnsignedLong((String) nextBlockId);
if (! BlockDb.hasBlock(blockId)) {
return commonBlockId;
}
commonBlockId = blockId;
}
}
}
示例9: getCommonBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private Long getCommonBlockId(Peer peer, Long commonBlockId) {
while (true) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlockIds");
request.put("blockId", Convert.toUnsignedLong(commonBlockId));
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return null;
}
JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
if (nextBlockIds == null || nextBlockIds.size() == 0) {
return null;
}
// prevent overloading with blockIds
if (nextBlockIds.size() > 1440) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many nextBlockIds, blacklisting");
peer.blacklist();
return null;
}
for (Object nextBlockId : nextBlockIds) {
Long blockId = Convert.parseUnsignedLong((String) nextBlockId);
if (! BlockDb.hasBlock(blockId)) {
return commonBlockId;
}
commonBlockId = blockId;
}
}
}
示例10: getCommonBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private Long getCommonBlockId(Peer paramAnonymousPeer, Long paramAnonymousLong)
{
for (;;)
{
JSONObject localJSONObject1 = new JSONObject();
localJSONObject1.put("requestType", "getNextBlockIds");
localJSONObject1.put("blockId", Convert.toUnsignedLong(paramAnonymousLong));
JSONObject localJSONObject2 = paramAnonymousPeer.send(JSON.prepareRequest(localJSONObject1));
if (localJSONObject2 == null) {
return null;
}
JSONArray localJSONArray = (JSONArray)localJSONObject2.get("nextBlockIds");
if ((localJSONArray == null) || (localJSONArray.size() == 0)) {
return null;
}
if (localJSONArray.size() > 1440)
{
Logger.logDebugMessage("Obsolete or rogue peer " + paramAnonymousPeer.getPeerAddress() + " sends too many nextBlockIds, blacklisting");
paramAnonymousPeer.blacklist();
return null;
}
for (Object localObject : localJSONArray)
{
Long localLong = Convert.parseUnsignedLong((String)localObject);
if (!BlockDb.hasBlock(localLong)) {
return paramAnonymousLong;
}
paramAnonymousLong = localLong;
}
}
}
示例11: getCommonMilestoneBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonMilestoneBlockId(Peer peer) {
String lastMilestoneBlockId = null;
while (true) {
JSONObject milestoneBlockIdsRequest = new JSONObject();
milestoneBlockIdsRequest.put("requestType", "getMilestoneBlockIds");
if (lastMilestoneBlockId == null) {
milestoneBlockIdsRequest.put("lastBlockId", blockchain.getLastBlock().getStringId());
} else {
milestoneBlockIdsRequest.put("lastMilestoneBlockId", lastMilestoneBlockId);
}
JSONObject response = peer.send(JSON.prepareRequest(milestoneBlockIdsRequest));
if (response == null) {
return 0;
}
JSONArray milestoneBlockIds = (JSONArray) response.get("milestoneBlockIds");
if (milestoneBlockIds == null) {
return 0;
}
if (milestoneBlockIds.isEmpty()) {
return Genesis.GENESIS_BLOCK_ID;
}
// prevent overloading with blockIds
if (milestoneBlockIds.size() > 20) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many milestoneBlockIds, blacklisting");
peer.blacklist();
return 0;
}
if (Boolean.TRUE.equals(response.get("last"))) {
peerHasMore = false;
}
for (Object milestoneBlockId : milestoneBlockIds) {
long blockId = Convert.parseUnsignedLong((String) milestoneBlockId);
if (BlockDb.hasBlock(blockId)) {
if (lastMilestoneBlockId == null && milestoneBlockIds.size() > 1) {
peerHasMore = false;
}
return blockId;
}
lastMilestoneBlockId = (String) milestoneBlockId;
}
}
}
示例12: getCommonMilestoneBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonMilestoneBlockId(Peer peer) {
String lastMilestoneBlockId = null;
while (true) {
JSONObject milestoneBlockIdsRequest = new JSONObject();
milestoneBlockIdsRequest.put("requestType", "getMilestoneBlockIds");
if (lastMilestoneBlockId == null) {
milestoneBlockIdsRequest.put("lastBlockId", blockchain.getLastBlock().getStringId());
} else {
milestoneBlockIdsRequest.put("lastMilestoneBlockId", lastMilestoneBlockId);
}
JSONObject response = peer.send(JSON.prepareRequest(milestoneBlockIdsRequest));
if (response == null) {
return 0;
}
Logger.logDebugMessage("getCommonMilestoneBlockId() resp= "+response);
JSONArray milestoneBlockIds = (JSONArray) response.get("milestoneBlockIds");
if (milestoneBlockIds == null) {
return 0;
}
if (milestoneBlockIds.isEmpty()) {
return Nxt.getGenesisBlockId();
}
// prevent overloading with blockIds
if (milestoneBlockIds.size() > 20) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many milestoneBlockIds, blacklisting");
peer.blacklist();
return 0;
}
if (Boolean.TRUE.equals(response.get("last"))) {
peerHasMore = false;
}
for (Object milestoneBlockId : milestoneBlockIds) {
long blockId = Convert.parseUnsignedLong((String) milestoneBlockId);
if (BlockDb.hasBlock(blockId)) {
if (lastMilestoneBlockId == null && milestoneBlockIds.size() > 1) {
peerHasMore = false;
}
return blockId;
}
lastMilestoneBlockId = (String) milestoneBlockId;
}
}
}
示例13: getCommonMilestoneBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonMilestoneBlockId(Peer peer) {
String lastMilestoneBlockId = null;
while (true) {
JSONObject milestoneBlockIdsRequest = new JSONObject();
milestoneBlockIdsRequest.put("requestType", "getMilestoneBlockIds");
if (lastMilestoneBlockId == null) {
milestoneBlockIdsRequest.put("lastBlockId", blockchain.getLastBlock().getStringId());
} else {
milestoneBlockIdsRequest.put("lastMilestoneBlockId", lastMilestoneBlockId);
}
JSONObject response = peer.send(JSON.prepareRequest(milestoneBlockIdsRequest));
if (response == null) {
return 0;
}
JSONArray milestoneBlockIds = (JSONArray) response.get("milestoneBlockIds");
if (milestoneBlockIds == null) {
return 0;
}
if (milestoneBlockIds.isEmpty()) {
return Genesis.GENESIS_BLOCK_ID;
}
// prevent overloading with blockIds
if (milestoneBlockIds.size() > 20) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getHost() + " sends too many milestoneBlockIds, blacklisting");
peer.blacklist("Too many milestoneBlockIds");
return 0;
}
if (Boolean.TRUE.equals(response.get("last"))) {
peerHasMore = false;
}
for (Object milestoneBlockId : milestoneBlockIds) {
long blockId = Convert.parseUnsignedLong((String) milestoneBlockId);
if (BlockDb.hasBlock(blockId)) {
if (lastMilestoneBlockId == null && milestoneBlockIds.size() > 1) {
peerHasMore = false;
}
return blockId;
}
lastMilestoneBlockId = (String) milestoneBlockId;
}
}
}
示例14: getBlockIdsAfterCommon
import nxt.peer.Peer; //导入方法依赖的package包/类
private List<Long> getBlockIdsAfterCommon(final Peer peer, final long startBlockId, final boolean countFromStart) {
long matchId = startBlockId;
List<Long> blockList = new ArrayList<>(720);
boolean matched = false;
int limit = countFromStart ? 720 : 1440;
while (true) {
JSONObject request = new JSONObject();
request.put("requestType", "getNextBlockIds");
request.put("blockId", Long.toUnsignedString(matchId));
request.put("limit", limit);
JSONObject response = peer.send(JSON.prepareRequest(request));
if (response == null) {
return Collections.emptyList();
}
JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
if (nextBlockIds == null || nextBlockIds.size() == 0) {
break;
}
// prevent overloading with blockIds
if (nextBlockIds.size() > limit) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getHost() + " sends too many nextBlockIds, blacklisting");
peer.blacklist("Too many nextBlockIds");
return Collections.emptyList();
}
boolean matching = true;
int count = 0;
for (Object nextBlockId : nextBlockIds) {
long blockId = Convert.parseUnsignedLong((String)nextBlockId);
if (matching) {
if (BlockDb.hasBlock(blockId)) {
matchId = blockId;
matched = true;
} else {
blockList.add(matchId);
blockList.add(blockId);
matching = false;
}
} else {
blockList.add(blockId);
if (blockList.size() >= 720) {
break;
}
}
if (countFromStart && ++count >= 720) {
break;
}
}
if (!matching || countFromStart) {
break;
}
}
if (blockList.isEmpty() && matched) {
blockList.add(matchId);
}
return blockList;
}
示例15: getCommonMilestoneBlockId
import nxt.peer.Peer; //导入方法依赖的package包/类
private long getCommonMilestoneBlockId(Peer peer) {
String lastMilestoneBlockId = null;
while (true) {
JSONObject milestoneBlockIdsRequest = new JSONObject();
milestoneBlockIdsRequest.put("requestType", "getMilestoneBlockIds");
if (lastMilestoneBlockId == null) {
milestoneBlockIdsRequest.put("lastBlockId", blockchain.getLastBlock().getStringId());
} else {
milestoneBlockIdsRequest.put("lastMilestoneBlockId", lastMilestoneBlockId);
}
JSONObject response = peer.send(JSON.prepareRequest(milestoneBlockIdsRequest));
if (response == null) {
return 0;
}
JSONArray milestoneBlockIds = (JSONArray) response.get("milestoneBlockIds");
if (milestoneBlockIds == null) {
return 0;
}
if (milestoneBlockIds.isEmpty()) {
return Genesis.GENESIS_BLOCK_ID;
}
// prevent overloading with blockIds
if (milestoneBlockIds.size() > 20) {
Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many milestoneBlockIds, blacklisting");
peer.blacklist();
return 0;
}
if (Boolean.TRUE.equals(response.get("last"))) {
peerHasMore = false;
}
for (Object milestoneBlockId : milestoneBlockIds) {
long blockId = Convert.parseUnsignedLong((String) milestoneBlockId);
if (BlockDb.hasBlock(blockId)) {
if (lastMilestoneBlockId == null && milestoneBlockIds.size() > 1) {
peerHasMore = false;
}
return blockId;
}
lastMilestoneBlockId = (String) milestoneBlockId;
}
}
}