当前位置: 首页>>代码示例>>Java>>正文


Java Peer.send方法代码示例

本文整理汇总了Java中nxt.peer.Peer.send方法的典型用法代码示例。如果您正苦于以下问题:Java Peer.send方法的具体用法?Java Peer.send怎么用?Java Peer.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nxt.peer.Peer的用法示例。


在下文中一共展示了Peer.send方法的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;

		}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:25,代码来源:BlockchainProcessorImpl.java

示例2: 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

示例3: 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

示例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;

        }
 
开发者ID:Ziftr,项目名称:nxt,代码行数:25,代码来源:BlockchainProcessorImpl.java

示例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;

        }
 
开发者ID:aspnmy,项目名称:NasCoin,代码行数:25,代码来源:BlockchainProcessorImpl.java

示例6: 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

示例7: 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;
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:22,代码来源:BlockchainProcessorImpl.java

示例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;
				}
			}

		}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:32,代码来源:BlockchainProcessorImpl.java

示例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 0;
                }
                JSONArray nextBlockIds = (JSONArray) response.get("nextBlockIds");
            Logger.logDebugMessage("getNextBlockIds "+nextBlockIds.size());
                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;
                }
            }

        }
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:34,代码来源:GetBlocksFromPeers.java

示例10: 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;
                }
            }

        }
 
开发者ID:Ziftr,项目名称:nxt,代码行数:32,代码来源:BlockchainProcessorImpl.java

示例11: 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;
                }
            }

        }
 
开发者ID:aspnmy,项目名称:NasCoin,代码行数:32,代码来源:BlockchainProcessorImpl.java

示例12: 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;
    }
  }
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:32,代码来源:BlockchainProcessorImpl.java

示例13: run

import nxt.peer.Peer; //导入方法依赖的package包/类
public void run()
{
  try
  {
    try
    {
      Peer localPeer = Peers.getAnyPeer(Peer.State.CONNECTED, true);
      if (localPeer == null) {
        return;
      }
      JSONObject localJSONObject = localPeer.send(this.getUnconfirmedTransactionsRequest);
      if (localJSONObject == null) {
        return;
      }
      JSONArray localJSONArray = (JSONArray)localJSONObject.get("unconfirmedTransactions");
      if (localJSONArray == null) {
        return;
      }
      TransactionProcessorImpl.this.processJSONTransactions(localJSONArray, false);
    }
    catch (Exception localException)
    {
      Logger.logDebugMessage("Error processing unconfirmed transactions from peer", localException);
    }
  }
  catch (Throwable localThrowable)
  {
    Logger.logMessage("CRITICAL ERROR. PLEASE REPORT TO THE DEVELOPERS.\n" + localThrowable.toString());
    localThrowable.printStackTrace();
    System.exit(1);
  }
}
 
开发者ID:stevedoe,项目名称:nxt-client,代码行数:33,代码来源:TransactionProcessorImpl.java

示例14: 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;
				}
			}

		}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:47,代码来源:BlockchainProcessorImpl.java

示例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;
                }
                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;
                }
            }

        }
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:48,代码来源:GetBlocksFromPeers.java


注:本文中的nxt.peer.Peer.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。