Skip to content

Commit

Permalink
Eliminate connect to self (hyperledger#3342)
Browse files Browse the repository at this point in the history
* don't allow connect to self

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
macfarla authored and eum602 committed Nov 3, 2023
1 parent e8bfee4 commit 9ebefb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Updated besu-native to version 0.4.3 [#3331](https://github.com/hyperledger/besu/pull/3331)

### Bug Fixes
- Prevent node from peering to itself [#3342](https://github.com/hyperledger/besu/pull/3342)


## 22.1.0-RC3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.p2p.permissions;

import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.ethereum.p2p.peers.Peer;
import org.hyperledger.besu.util.LimitedSet;
import org.hyperledger.besu.util.LimitedSet.Mode;
Expand Down Expand Up @@ -54,7 +55,8 @@ public static PeerPermissionsDenylist create(final int maxSize) {

@Override
public boolean isPermitted(final Peer localNode, final Peer remotePeer, final Action action) {
return !blacklist.contains(remotePeer.getId());
return !EnodeURLImpl.sameListeningEndpoint(localNode.getEnodeURL(), remotePeer.getEnodeURL())
&& !blacklist.contains(remotePeer.getId());
}

public void add(final Peer peer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public void trackedPeerIsNotPermitted() {
checkPermissions(blacklist, peer, true);
}

@Test
public void selfPeerIsNotPermitted() {
PeerPermissionsDenylist blacklist = PeerPermissionsDenylist.create();

checkPermissions(blacklist, localNode, false);
}

@Test
public void subscribeUpdate() {
PeerPermissionsDenylist blacklist = PeerPermissionsDenylist.create();
Expand Down

0 comments on commit 9ebefb9

Please sign in to comment.