@Override
    protected Message processRequest0(final CliRequestContext ctx, final AddPeerRequest request, final RpcRequestClosure done) {
        final List<PeerId> oldPeers = ctx.node.listPeers();
        final String addingPeerIdStr = request.getPeerId();
        final PeerId addingPeer = new PeerId();
        if (addingPeer.parse(addingPeerIdStr)) {
            LOG.info("Receive AddPeerRequest to {} from {}, adding {}", ctx.node.getNodeId(), done.getRpcCtx()
                .getRemoteAddress(), addingPeerIdStr);
            ctx.node.addPeer(addingPeer, status -> {
                if (!status.isOk()) {
                    done.run(status);
                } else {
                    final AddPeerResponse.Builder rb = AddPeerResponse.newBuilder();
                    boolean alreadyExists = false;
                    for (final PeerId oldPeer : oldPeers) {
                        rb.addOldPeers(oldPeer.toString());
                        rb.addNewPeers(oldPeer.toString());
                        if (oldPeer.equals(addingPeer)) {
                            alreadyExists = true;
                        }
                    }
                    if (!alreadyExists) {
                        rb.addNewPeers(addingPeerIdStr);
                    }
                    done.sendResponse(rb.build());
                }
            });
        } else {
            return RpcFactoryHelper //
                .responseFactory() //
                .newResponse(defaultResp(), RaftError.EINVAL, "Fail to parse peer id %s", addingPeerIdStr);
        }

        return null;
    }
AddPeer request processor.

@author boyan (boyan@alibaba-inc.com)
@author jiachun.fjc
jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/cli/AddPeerRequestProcessor.java