Repository: valkey-io/valkey
File: src/cluster_legacy.c (C)

Code before:

int clusterCommandSpecial(client *c) {
    if (!strcasecmp(c->argv[1]->ptr, "meet") && (c->argc == 4 || c->argc == 5)) {
        /* CLUSTER MEET <ip> <port> [cport] */
        long long port, cport;

        if (getLongLongFromObject(c->argv[3], &port) != C_OK) {
            addReplyErrorFormat(c, "Invalid base port specified: %s", (char *)c->argv[3]->ptr);
            return 1;
        }
        if (port <= 0 || port > 65535) {
            addReplyErrorFormat(c, "Port number is out of range");
            return 1;
        }

        if (c->argc == 5) {
            if (getLongLongFromObject(c->argv[4], &cport) != C_OK) {
                addReplyErrorFormat(c, "Invalid bus port specified: %s", (char *)c->argv[4]->ptr);
                return 1;
            }
        } else {
            cport = port + CLUSTER_PORT_INCR;
        }

        if (cport <= 0 || cport > 65535) {
            addReplyErrorFormat(c, "Cport number is out of range");
            return 1;
        }

        if (clusterStartHandshake(c->argv[2]->ptr, port, cport) == 0 && errno == EINVAL) {
            addReplyErrorFormat(c, "Invalid node address specified: %s:%s", (char *)c->argv[2]->ptr,
                                (char *)c->argv[3]->ptr);
        } else {
            sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
            serverLog(LL_NOTICE, "Cluster meet %s:%lld (user request from '%s').", (char *)c->argv[2]->ptr, port,
                      client);
            sdsfree(client);
            addReply(c, shared.ok);
        }
    } else if (!strcasecmp(c->argv[1]->ptr, "flushslots") && c->argc == 2) {
        /* CLUSTER FLUSHSLOTS */
        if (kvstoreSize(server.db[0].keys) != 0) {
            addReplyError(c, "DB must be empty to perform CLUSTER FLUSHSLOTS.");
            return 1;
        }
        clusterDelNodeSlots(myself);
        clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG);
        addReply(c, shared.ok);
    } else if ((!strcasecmp(c->argv[1]->ptr, "addslots") || !strcasecmp(c->argv[1]->ptr, "delslots")) && c->argc >= 3) {
        /* CLUSTER ADDSLOTS <slot> [slot] ... */
        /* CLUSTER DELSLOTS <slot> [slot] ... */

Review comment (bug):
Just thinking about this error message. In the docs, we called it cluster-bus-port:

    CLUSTER MEET ip port [cluster-bus-port]

And in the other error for this field uses the word "bus port", when getLongLongFromObject fails:

    addReplyErrorFormat(c, "Invalid bus port specified: %s", (char *)c->argv[4]->ptr);

What do you think about this:

```suggestion
            addReplyErrorFormat(c, "Cluster bus port number is out of range");
```

Code after:

int clusterCommandSpecial(client *c) {
    if (!strcasecmp(c->argv[1]->ptr, "meet") && (c->argc == 4 || c->argc == 5)) {
        /* CLUSTER MEET <ip> <port> [cport] */
        long long port, cport;

        if (getLongLongFromObject(c->argv[3], &port) != C_OK) {
            addReplyErrorFormat(c, "Invalid base port specified: %s", (char *)c->argv[3]->ptr);
            return 1;
        }
        if (port <= 0 || port > 65535) {
            addReplyErrorFormat(c, "Port number is out of range");
            return 1;
        }

        if (c->argc == 5) {
            if (getLongLongFromObject(c->argv[4], &cport) != C_OK) {
                addReplyErrorFormat(c, "Invalid bus port specified: %s", (char *)c->argv[4]->ptr);
                return 1;
            }
        } else {
            cport = port + CLUSTER_PORT_INCR;
        }

        if (cport <= 0 || cport > 65535) {
            addReplyErrorFormat(c, "Cluster bus port number is out of range");
            return 1;
        }

        if (clusterStartHandshake(c->argv[2]->ptr, port, cport) == 0 && errno == EINVAL) {
            addReplyErrorFormat(c, "Invalid node address specified: %s:%s", (char *)c->argv[2]->ptr,
                                (char *)c->argv[3]->ptr);
        } else {
            sds client = catClientInfoShortString(sdsempty(), c, server.hide_user_data_from_log);
            serverLog(LL_NOTICE, "Cluster meet %s:%lld (user request from '%s').", (char *)c->argv[2]->ptr, port,
                      client);
            sdsfree(client);
            addReply(c, shared.ok);
        }
    } else if (!strcasecmp(c->argv[1]->ptr, "flushslots") && c->argc == 2) {
        /* CLUSTER FLUSHSLOTS */
        if (kvstoreSize(server.db[0].keys) != 0) {
            addReplyError(c, "DB must be empty to perform CLUSTER FLUSHSLOTS.");
            return 1;
        }
        clusterDelNodeSlots(myself);
        clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE | CLUSTER_TODO_SAVE_CONFIG);
        addReply(c, shared.ok);
    } else if ((!strcasecmp(c->argv[1]->ptr, "addslots") || !strcasecmp(c->argv[1]->ptr, "delslots")) && c->argc >= 3) {
        /* CLUSTER ADDSLOTS <slot> [slot] ... */
        /* CLUSTER DELSLOTS <slot> [slot] ... */