From 08a377c18cd3b4d10ab2f24256e616e4e6162cf0 Mon Sep 17 00:00:00 2001 From: tmohay Date: Wed, 20 Mar 2019 12:34:02 +1100 Subject: [PATCH] resolve conflicts --- .../internal/methods/AdminAddPeer.java | 22 ++++++++++++++----- .../methods/AdminPeerModification.java | 9 ++------ .../internal/methods/AdminRemovePeer.java | 8 +++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java index e654f5629f..7979ee986e 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java @@ -13,6 +13,11 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; +import tech.pegasys.pantheon.ethereum.p2p.PeerNotPermittedException; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; @@ -35,11 +40,16 @@ public String getName() { } @Override - protected boolean performOperation(final String enode) { - LOG.debug("Adding ({}) to peers", enode); - final EnodeURL enodeURL = new EnodeURL(enode); - final Peer peer = DefaultPeer.fromEnodeURL(enodeURL); - boolean addedToNetwork = peerNetwork.addMaintainConnectionPeer(peer); - return addedToNetwork; + protected JsonRpcResponse performOperation(final Object id, final String enode) { + try { + LOG.debug("Adding ({}) to peers", enode); + final EnodeURL enodeURL = new EnodeURL(enode); + final Peer peer = DefaultPeer.fromEnodeURL(enodeURL); + boolean addedToNetwork = peerNetwork.addMaintainConnectionPeer(peer); + return new JsonRpcSuccessResponse(id, addedToNetwork); + } catch (final PeerNotPermittedException e) { + return new JsonRpcErrorResponse( + id, JsonRpcError.NON_PERMITTED_NODE_CANNOT_BE_ADDED_AS_A_PEER); + } } } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminPeerModification.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminPeerModification.java index 9ef04a265b..2129f00dc6 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminPeerModification.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminPeerModification.java @@ -18,9 +18,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; -import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.P2pDisabledException; -import tech.pegasys.pantheon.ethereum.p2p.PeerNotWhitelistedException; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import org.apache.logging.log4j.LogManager; @@ -44,21 +42,18 @@ public JsonRpcResponse response(final JsonRpcRequest req) { } try { final String enodeString = parameters.required(req.getParams(), 0, String.class); - return new JsonRpcSuccessResponse(req.getId(), performOperation(enodeString)); + return performOperation(req.getId(), enodeString); } catch (final InvalidJsonRpcParameters e) { return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_PARAMS); } catch (final IllegalArgumentException e) { return new JsonRpcErrorResponse(req.getId(), JsonRpcError.PARSE_ERROR); } catch (final P2pDisabledException e) { return new JsonRpcErrorResponse(req.getId(), JsonRpcError.P2P_DISABLED); - } catch (final PeerNotWhitelistedException e) { - return new JsonRpcErrorResponse( - req.getId(), JsonRpcError.NON_WHITELISTED_NODE_CANNOT_BE_ADDED_AS_A_PEER); } catch (final Exception e) { LOG.error(getName() + " - Error processing request: " + req, e); throw e; } } - protected abstract boolean performOperation(final String enode); + protected abstract JsonRpcResponse performOperation(final Object id, final String enode); } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java index 6094742f3d..8b3c4c826e 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java @@ -13,6 +13,8 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -34,9 +36,11 @@ public String getName() { } @Override - protected boolean performOperation(final String enode) { + protected JsonRpcResponse performOperation(final Object id, final String enode) { LOG.debug("Remove ({}) to peer cache", enode); final EnodeURL enodeURL = new EnodeURL(enode); - return peerNetwork.removeMaintainedConnectionPeer(DefaultPeer.fromEnodeURL(enodeURL)); + final boolean result = + peerNetwork.removeMaintainedConnectionPeer(DefaultPeer.fromEnodeURL(enodeURL)); + return new JsonRpcSuccessResponse(id, result); } }