Skip to content

Commit

Permalink
[RatisConsensus] Prevent misuse of addRemotePeer (#14779)
Browse files Browse the repository at this point in the history
  • Loading branch information
SzyWilliam authored Jan 27, 2025
1 parent 024b05c commit 526f678
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,16 @@ public void addRemotePeer(ConsensusGroupId groupId, Peer peer) throws ConsensusE

RaftPeer peerToAdd = Utils.fromPeerAndPriorityToRaftPeer(peer, DEFAULT_PRIORITY);
// pre-condition: peer not in this group
if (group.getPeers().contains(peerToAdd)) {
if (group.getPeers().stream()
.anyMatch(
p ->
p.getId().equals(peerToAdd.getId())
|| p.getAddress().equals(peerToAdd.getAddress()))) {
logger.warn(
"{}: try to add a peer {} with conflicting id or address in {}",
this,
peerToAdd,
group.getPeers());
throw new PeerAlreadyInConsensusGroupException(groupId, peer);
}

Expand Down

0 comments on commit 526f678

Please sign in to comment.