Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Prevent connecting to self #1150

Merged
merged 4 commits into from
Mar 22, 2019
Merged

Prevent connecting to self #1150

merged 4 commits into from
Mar 22, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Mar 21, 2019

When receiving an AddPeer, or when loading the static-nodes.json file, pantheon
should not accept its own NodeID as a valid connection.

When receiving an AddPeer, or when loading the static-nodes.json file, pantheon
should not accept its own NodeID as a valid connection.
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

*/
package tech.pegasys.pantheon.ethereum.p2p;

public class PreventLocalNodeConnection extends RuntimeException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be more about what went wrong rather than why we don't allow it. So ConnectingToLocalPeerException maybe? Also good to end exception names with Exception (though we break that convention in a few places).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -369,6 +370,11 @@ public boolean addMaintainConnectionPeer(final Peer peer) {
if (!isPeerAllowed(peer)) {
throw new PeerNotPermittedException();
}

if (peer.getId().equals(this.getLocalPeerInfo().getNodeId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the this looks unnecessary

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rain-on rain-on merged commit 0ae1e06 into PegaSysEng:master Mar 22, 2019
@rain-on rain-on deleted the self_connect branch March 22, 2019 04:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants