Search in sources :

Example 1 with Peer

use of org.xel.peer.Peer in project elastic-core-maven by OrdinaryDude.

the class BlacklistPeer method processRequest.

@Override
protected 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;
}
Also used : JSONObject(org.json.simple.JSONObject) Peer(org.xel.peer.Peer)

Example 2 with Peer

use of org.xel.peer.Peer in project elastic-core-maven by OrdinaryDude.

the class GetInboundPeers method processRequest.

/**
 * Process the GetInboundPeers API request
 *
 * @param   req                 API request
 * @return                      API response or null
 */
@Override
protected 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;
}
Also used : JSONObject(org.json.simple.JSONObject) Peer(org.xel.peer.Peer) JSONArray(org.json.simple.JSONArray)

Example 3 with Peer

use of org.xel.peer.Peer in project elastic-core-maven by OrdinaryDude.

the class RemoveBlacklistedPeer method processRequest.

@Override
JSONStreamAware processRequest(HttpServletRequest req, User user) throws IOException {
    if (Users.allowedUserHosts == null && !InetAddress.getByName(req.getRemoteAddr()).isLoopbackAddress()) {
        return LOCAL_USERS_ONLY;
    } else {
        int index = Integer.parseInt(req.getParameter("peer"));
        Peer peer = Users.getPeer(index);
        if (peer != null && peer.isBlacklisted()) {
            peer.unBlacklist();
        }
    }
    return null;
}
Also used : Peer(org.xel.peer.Peer)

Example 4 with Peer

use of org.xel.peer.Peer in project elastic-core-maven by OrdinaryDude.

the class GetBlockchainStatus method processRequest.

@Override
protected 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);
    response.put("correctInvalidFees", Constants.correctInvalidFees);
    response.put("ledgerTrimKeep", AccountLedger.trimKeep);
    JSONArray servicesArray = new JSONArray();
    Peers.getServices().forEach(service -> servicesArray.add(service.name()));
    response.put("services", servicesArray);
    if (APIProxy.isActivated()) {
        String servingPeer = APIProxy.getInstance().getMainPeerAnnouncedAddress();
        response.put("apiProxy", true);
        response.put("apiProxyPeer", servingPeer);
    } else {
        response.put("apiProxy", false);
    }
    response.put("isLightClient", Constants.isLightClient);
    response.put("maxAPIRecords", API.maxRecords);
    response.put("blockchainState", Peers.getMyBlockchainState());
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) BlockchainProcessor(org.xel.BlockchainProcessor) Peer(org.xel.peer.Peer) JSONArray(org.json.simple.JSONArray) Block(org.xel.Block)

Example 5 with Peer

use of org.xel.peer.Peer in project elastic-core-maven by OrdinaryDude.

the class SetAPIProxyPeer method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
    String peerAddress = Convert.emptyToNull(request.getParameter("peer"));
    if (peerAddress == null) {
        Peer peer = APIProxy.getInstance().setForcedPeer(null);
        if (peer == null) {
            return API_PROXY_NO_OPEN_API_PEERS;
        }
        return JSONData.peer(peer);
    }
    Peer peer = Peers.findOrCreatePeer(peerAddress, false);
    if (peer == null) {
        return UNKNOWN_PEER;
    }
    if (peer.getState() != Peer.State.CONNECTED) {
        return PEER_NOT_CONNECTED;
    }
    if (!peer.isOpenAPI()) {
        return PEER_NOT_OPEN_API;
    }
    APIProxy.getInstance().setForcedPeer(peer);
    return JSONData.peer(peer);
}
Also used : Peer(org.xel.peer.Peer)

Aggregations

Peer (org.xel.peer.Peer)16 JSONObject (org.json.simple.JSONObject)9 JSONArray (org.json.simple.JSONArray)6 Block (org.xel.Block)2 ArrayList (java.util.ArrayList)1 JSONStreamAware (org.json.simple.JSONStreamAware)1 BlockchainProcessor (org.xel.BlockchainProcessor)1 Transaction (org.xel.Transaction)1