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

Code before:
    uint16_t cport;          /* cluster port last time it was seen */
    uint16_t flags;          /* node->flags copy */
    uint16_t pport;          /* secondary port last time it was seen */
    uint16_t notused1;
} clusterMsgDataGossip;

typedef struct {
    char nodename[CLUSTER_NAMELEN];
} clusterMsgDataFail;

typedef struct {
    uint32_t channel_len;
    uint32_t message_len;
    unsigned char bulk_data[8]; /* 8 bytes just as placeholder. */
} clusterMsgDataPublish;

typedef struct {
    uint32_t message_len;
    unsigned char message_data[8]; /* 8 bytes just as placeholder. */
} clusterMsgDataPublishMessage;

typedef struct {
    uint64_t data_count;
    clusterMsgDataPublishMessage *bulk_data;
} clusterMsgDataPublishMulti;

typedef struct {
    uint64_t configEpoch;                   /* Config epoch of the specified instance. */
    char nodename[CLUSTER_NAMELEN];         /* Name of the slots owner. */
    unsigned char slots[CLUSTER_SLOTS / 8]; /* Slots bitmap. */
} clusterMsgDataUpdate;

typedef struct {
    uint64_t module_id;         /* ID of the sender module. */
    uint32_t len;               /* ID of the sender module. */
    uint8_t type;               /* Type from 0 to 255. */
    unsigned char bulk_data[3]; /* 3 bytes just as placeholder. */
} clusterMsgModule;

/* The cluster supports optional extension messages that can be sent
 * along with ping/pong/meet messages to give additional info in a
 * consistent manner. */
typedef enum {
    CLUSTERMSG_EXT_TYPE_HOSTNAME,
    CLUSTERMSG_EXT_TYPE_HUMAN_NODENAME,
    CLUSTERMSG_EXT_TYPE_FORGOTTEN_NODE,
    CLUSTERMSG_EXT_TYPE_SHARDID,
    CLUSTERMSG_EXT_TYPE_CLIENT_IPV4,
    CLUSTERMSG_EXT_TYPE_CLIENT_IPV6,
} clusterMsgPingtypes;


Review comment (suggestion):
Could you place these struct along side the `clusterMsgDataLight` and add a top comment "Light message and it's supported message types"

Code after:
    char nodename[CLUSTER_NAMELEN];
    uint32_t ping_sent;
    uint32_t pong_received;
    char ip[NET_IP_STR_LEN]; /* IP address last time it was seen */
    uint16_t port;           /* primary port last time it was seen */
    uint16_t cport;          /* cluster port last time it was seen */
    uint16_t flags;          /* node->flags copy */
    uint16_t pport;          /* secondary port last time it was seen */
    uint16_t notused1;
} clusterMsgDataGossip;

typedef struct {
    char nodename[CLUSTER_NAMELEN];
} clusterMsgDataFail;

typedef struct {
    uint32_t channel_len;
    uint32_t message_len;
    unsigned char bulk_data[8]; /* 8 bytes just as placeholder. */
} clusterMsgDataPublish;

typedef struct {
    uint64_t configEpoch;                   /* Config epoch of the specified instance. */
    char nodename[CLUSTER_NAMELEN];         /* Name of the slots owner. */
    unsigned char slots[CLUSTER_SLOTS / 8]; /* Slots bitmap. */
} clusterMsgDataUpdate;

typedef struct {
    uint64_t module_id;         /* ID of the sender module. */
    uint32_t len;               /* ID of the sender module. */
    uint8_t type;               /* Type from 0 to 255. */
    unsigned char bulk_data[3]; /* 3 bytes just as placeholder. */
} clusterMsgModule;

/* The cluster supports optional extension messages that can be sent
 * along with ping/pong/meet messages to give additional info in a
 * consistent manner. */
typedef enum {
    CLUSTERMSG_EXT_TYPE_HOSTNAME,
    CLUSTERMSG_EXT_TYPE_HUMAN_NODENAME,
    CLUSTERMSG_EXT_TYPE_FORGOTTEN_NODE,
    CLUSTERMSG_EXT_TYPE_SHARDID,
    CLUSTERMSG_EXT_TYPE_CLIENT_IPV4,
    CLUSTERMSG_EXT_TYPE_CLIENT_IPV6,
} clusterMsgPingtypes;

/* Helper function for making sure extensions are eight byte aligned. */
#define EIGHT_BYTE_ALIGN(size) ((((size) + 7) / 8) * 8)

typedef struct {
    char hostname[1]; /* The announced hostname, ends with \0. */