• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Peers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Peers类属于nxt.peer包,在下文中一共展示了Peers类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processRequest

import nxt.peer.Peers; //导入依赖的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


示例2: processRequest

import nxt.peer.Peers; //导入依赖的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


示例3: processRequest

import nxt.peer.Peers; //导入依赖的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


示例4: processRequest

import nxt.peer.Peers; //导入依赖的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


示例5: processRequest

import nxt.peer.Peers; //导入依赖的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


示例6: activateListener

import nxt.peer.Peers; //导入依赖的package包/类
/**
 * Activate the event listener
 *
 * Event listeners will be added for the specified peer, block and transaction events.
 *
 * @param   peerEvents              Peer event list
 * @param   blockEvents             Block event list
 * @param   txEvents                Transaction event list
 * @throws  EventListenerException  Unable to activate event listeners
 */
void activateListener(List<Peers.Event> peerEvents, List<BlockchainProcessor.Event> blockEvents,
                                    List<TransactionProcessor.Event> txEvents)
                                    throws EventListenerException {
    if (deactivated)
        throw new EventListenerException("Event listener deactivated");
    if (eventListeners.size() >= maxEventUsers && eventListeners.get(address) == null)
        throw new EventListenerException(String.format("Too many API event users: Maximum %d", maxEventUsers));
    //
    // Start listening for events
    //
    addEvents(peerEvents, blockEvents, txEvents);
    //
    // Add this event listener to the active list
    //
    EventListener oldListener = eventListeners.get(address);
    if (oldListener != null)
        oldListener.deactivateListener();
    eventListeners.put(address, this);
    Logger.logDebugMessage(String.format("Event listener activated for %s", address));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:31,代码来源:EventListener.java


示例7: processRequest

import nxt.peer.Peers; //导入依赖的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


示例8: processRequest

import nxt.peer.Peers; //导入依赖的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


示例9: processRequest

import nxt.peer.Peers; //导入依赖的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


示例10: run

import nxt.peer.Peers; //导入依赖的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


示例11: getPeer

import nxt.peer.Peers; //导入依赖的package包/类
static Peer getPeer(int index) {
    String peerAddress = peerAddressMap.get(index);
    if (peerAddress == null) {
        return null;
    }
    return Peers.getPeer(peerAddress);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:8,代码来源:Users.java


示例12: processRequest

import nxt.peer.Peers; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {

    boolean active = "true".equalsIgnoreCase(req.getParameter("active"));
    String stateValue = Convert.emptyToNull(req.getParameter("state"));

    JSONArray peers = new JSONArray();
    for (Peer peer : active ? Peers.getActivePeers() : stateValue != null ? Peers.getPeers(Peer.State.valueOf(stateValue)) : Peers.getAllPeers()) {
        peers.add(peer.getPeerAddress());
    }

    JSONObject response = new JSONObject();
    response.put("peers", peers);
    return response;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:16,代码来源:GetPeers.java


示例13: shutdown

import nxt.peer.Peers; //导入依赖的package包/类
public static void shutdown() {
    Logger.logShutdownMessage("Shutting down...");
    API.shutdown();
    Users.shutdown();
    Peers.shutdown();
    ThreadPool.shutdown();
    Db.shutdown();
    if(BlockchainProcessorImpl.oclVerify) {
        OCLPoC.destroy();
    }
    Logger.logShutdownMessage("Burst server " + VERSION + " stopped.");
    Logger.shutdown();
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:14,代码来源:Nxt.java


示例14: run

import nxt.peer.Peers; //导入依赖的package包/类
@Override
public void run() {

    try {
        try {
            List<Transaction> transactionList = new ArrayList<>();
            int curTime = Nxt.getEpochTime();
            for (TransactionImpl transaction : nonBroadcastedTransactions) {
                if (TransactionDb.hasTransaction(transaction.getId()) || transaction.getExpiration() < curTime) {
                    nonBroadcastedTransactions.remove(transaction);
                } else if (transaction.getTimestamp() < curTime - 30) {
                    transactionList.add(transaction);
                }
            }
            DDosProtection.sanitizeTransactionList(transactionList, "Transaction rebroadcaster");
            if (transactionList.size() > 0) {
                Peers.rebroadcastTransactions(transactionList);
            }

        } catch (Exception e) {
            Logger.logDebugMessage("Error in transaction re-broadcasting thread", e);
        }
    } catch (Throwable t) {
        Logger.logMessage("CRITICAL ERROR. PLEASE REPORT TO THE DEVELOPERS.\n" + t.toString());
        t.printStackTrace();
        System.exit(1);
    }

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


示例15: shutdown

import nxt.peer.Peers; //导入依赖的package包/类
public static void shutdown() {
    Logger.logShutdownMessage("Shutting down...");
    API.shutdown();
    Users.shutdown();
    Peers.shutdown();
    ThreadPool.shutdown();
    Db.shutdown();
    Logger.logShutdownMessage("Nxt server " + VERSION + " stopped.");
    Logger.shutdown();
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:11,代码来源:Nxt.java


示例16: run

import nxt.peer.Peers; //导入依赖的package包/类
@Override
public void run() {

    try {
        try {
            List<Transaction> transactionList = new ArrayList<>();
            int curTime = Nxt.getEpochTime();
            for (TransactionImpl transaction : broadcastedTransactions) {
                if (TransactionDb.hasTransaction(transaction.getId()) || transaction.getExpiration() < curTime) {
                    broadcastedTransactions.remove(transaction);
                } else if (transaction.getTimestamp() < curTime - 30) {
                    transactionList.add(transaction);
                }
            }

            if (transactionList.size() > 0) {
                Peers.sendToSomePeers(transactionList);
            }

        } catch (Exception e) {
            Logger.logDebugMessage("Error in transaction re-broadcasting thread", e);
        }
    } catch (Throwable t) {
        Logger.logMessage("CRITICAL ERROR. PLEASE REPORT TO THE DEVELOPERS.\n" + t.toString());
        t.printStackTrace();
        System.exit(1);
    }

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


示例17: broadcast

import nxt.peer.Peers; //导入依赖的package包/类
@Override
public void broadcast(Transaction transaction) throws NxtException.ValidationException {
    synchronized (BlockchainImpl.getInstance()) {
        if (TransactionDb.hasTransaction(transaction.getId())) {
            Logger.logMessage("Transaction " + transaction.getStringId() + " already in blockchain, will not broadcast again");
            return;
        }
        if (unconfirmedTransactionTable.get(((TransactionImpl) transaction).getDbKey()) != null) {
            if (enableTransactionRebroadcasting) {
                broadcastedTransactions.add((TransactionImpl) transaction);
                Logger.logMessage("Transaction " + transaction.getStringId() + " already in unconfirmed pool, will re-broadcast");
            } else {
                Logger.logMessage("Transaction " + transaction.getStringId() + " already in unconfirmed pool, will not broadcast again");
            }
            return;
        }
        transaction.validate();
        processTransaction(new UnconfirmedTransaction((TransactionImpl) transaction, System.currentTimeMillis()));
        Logger.logDebugMessage("Accepted new transaction " + transaction.getStringId());
        Generator.getInstance().addTransaction((TransactionImpl)transaction); //TODO?
        List<Transaction> acceptedTransactions = Collections.singletonList(transaction);
        Peers.sendToSomePeers(acceptedTransactions);
        transactionListeners.notify(acceptedTransactions, Event.ADDED_UNCONFIRMED_TRANSACTIONS);
        if (enableTransactionRebroadcasting) {
            broadcastedTransactions.add((TransactionImpl) transaction);
        }
    } // synchronized
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:29,代码来源:TransactionProcessorImpl.java


示例18: processRequest

import nxt.peer.Peers; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {

    String version = Convert.nullToEmpty(req.getParameter("version"));
    int weight = ParameterParser.getInt(req, "weight", 0, (int)Constants.MAX_BALANCE_NXT, false);
    boolean connect = "true".equalsIgnoreCase(req.getParameter("connect")) && API.checkPassword(req);
    if (connect) {
        Peers.getAllPeers().parallelStream().unordered().forEach(Peers::connectPeer);
    }
    Set<String> addresses = new HashSet<>();
    Peers.getAllPeers().forEach(peer -> {
                if (peer.getState() == Peer.State.CONNECTED
                        && peer.shareAddress()
                        && !peer.isBlacklisted()
                        && peer.getVersion() != null && peer.getVersion().startsWith(version)
                        && (weight == 0 || peer.getWeight() > weight)) {
                    addresses.add(peer.getAnnouncedAddress());
                }
            });
    StringBuilder buf = new StringBuilder();
    for (String address : addresses) {
        buf.append(address).append("; ");
    }
    JSONObject response = new JSONObject();
    response.put("peers", buf.toString());
    response.put("count", addresses.size());
    return response;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:29,代码来源:DumpPeers.java


示例19: processRequest

import nxt.peer.Peers; //导入依赖的package包/类
/**
 * Process the GetInboundPeers API request
 *
 * @param   req                 API request
 * @return                      API response or null
 */
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
    boolean includePeerInfo = "true".equalsIgnoreCase(req.getParameter("includePeerInfo"));
    List<Peer> peers = Peers.getInboundPeers();
    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,代码行数:21,代码来源:GetInboundPeers.java


示例20: deactivateListener

import nxt.peer.Peers; //导入依赖的package包/类
/**
 * Deactivate the event listener
 */
void deactivateListener() {
    BlockchainProcessor blockProcessor = Nxt.getBlockchainProcessor();
    TransactionProcessor txProcessor = Nxt.getTransactionProcessor();
    lock.lock();
    try {
        if (deactivated)
            return;
        deactivated = true;
        //
        // Cancel all pending wait requests
        //
        if (!pendingWaits.isEmpty() && !dispatched) {
            dispatched = true;
            threadPool.submit(this);
        }
        //
        // Remove this event listener from the active list
        //
        eventListeners.remove(address);
        //
        // Stop listening for events
        //
        peerListeners.forEach(listener -> Peers.removeListener(listener, listener.getEvent()));
        blockListeners.forEach(listener -> blockProcessor.removeListener(listener, listener.getEvent()));
        txListeners.forEach(listener -> txProcessor.removeListener(listener, listener.getEvent()));
    } finally {
        lock.unlock();
    }
    Logger.logDebugMessage(String.format("Event listener deactivated for %s", address));
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:34,代码来源:EventListener.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LaunchOptions类代码示例发布时间:2022-05-22
下一篇:
Java IFilter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap