This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Remove Peer json RPC added #1129
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
80759ba
Maintain a staticnodes.json
f361ec5
fix spotless
251508e
Remove from addPeer
c1b6ae2
Removed excess code
b0ae782
StaticNodes loaded at startup
cd08c92
No More mods during RPC
b66e3d7
Merge remote-tracking branch 'upstream/master' into static_nodes
1bfb7f5
Updated tests
6e898f7
post review
b048268
fix spotless
12a1998
Remove Peer json RPC added
2164d34
Merge remote-tracking branch 'upstream/master' into remove_peer_rpc
08a377c
resolve conflicts
9f3bf76
Merge branch 'master' into remove_peer_rpc
rain-on f3b5e52
Merge branch 'master' into remove_peer_rpc
rain-on 4798348
post review
7040e58
Merge branch 'master' into remove_peer_rpc
rain-on File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...n/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminPeerModification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; | ||
|
||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.exception.InvalidJsonRpcParameters; | ||
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.p2p.P2pDisabledException; | ||
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public abstract class AdminPeerModification implements JsonRpcMethod { | ||
|
||
protected final JsonRpcParameter parameters; | ||
protected final P2PNetwork peerNetwork; | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
public AdminPeerModification(final P2PNetwork peerNetwork, final JsonRpcParameter parameters) { | ||
this.peerNetwork = peerNetwork; | ||
this.parameters = parameters; | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequest req) { | ||
if (req.getParamLength() != 1) { | ||
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
try { | ||
final String enodeString = parameters.required(req.getParams(), 0, String.class); | ||
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 Exception e) { | ||
LOG.error(getName() + " - Error processing request: " + req, e); | ||
throw e; | ||
} | ||
} | ||
|
||
protected abstract JsonRpcResponse performOperation(final Object id, final String enode); | ||
} |
46 changes: 46 additions & 0 deletions
46
...rc/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
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; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class AdminRemovePeer extends AdminPeerModification { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
public AdminRemovePeer(final P2PNetwork peerNetwork, final JsonRpcParameter parameters) { | ||
super(peerNetwork, parameters); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "admin_removePeer"; | ||
} | ||
|
||
@Override | ||
protected JsonRpcResponse performOperation(final Object id, final String enode) { | ||
LOG.debug("Remove ({}) to peer cache", enode); | ||
final EnodeURL enodeURL = new EnodeURL(enode); | ||
final boolean result = | ||
peerNetwork.removeMaintainedConnectionPeer(DefaultPeer.fromEnodeURL(enodeURL)); | ||
return new JsonRpcSuccessResponse(id, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
|
@@ -66,7 +67,11 @@ public int size() { | |
} | ||
|
||
public boolean isAlreadyConnected(final BytesValue nodeId) { | ||
return connections.containsKey(nodeId); | ||
return getConnectionForPeer(nodeId).isPresent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did this need to change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda preferred re-using the same interface as was now exposed ... but have changed it back. |
||
} | ||
|
||
public Optional<PeerConnection> getConnectionForPeer(final BytesValue nodeID) { | ||
return Optional.ofNullable(connections.get(nodeID)); | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Something makes me think that AdminModifyPeer would be more consistent. (Noun-verb-noun instead of Noun-Noun-verb?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.