summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-01-13 10:20:49 +0100
committerantirez <antirez@gmail.com>2015-01-13 16:23:44 +0100
commit45e2a26ded818ca080bb0f833ddcff958227acee (patch)
tree2981f77db8016d7810fbcebdbb50196cdf0e2d98
parent799a3ccac1503ed327c24b75ed1541d5749a71d8 (diff)
downloadredis-45e2a26ded818ca080bb0f833ddcff958227acee.tar.gz
Cluster: clusterMsgDataGossip structure, explict padding + minor stuff.
Also explicitly set version to 0, add a protocol version define, improve comments in the gossip structure. Note that the structure layout is the same after the change, we are just making the padding explicit with an additional not used 16 bits field. So this commit is still able to talk with the previous versions of cluster nodes.
-rw-r--r--src/cluster.c4
-rw-r--r--src/cluster.h10
-rw-r--r--src/redis.h2
3 files changed, 10 insertions, 6 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 7d89c6f9f..c1af411b8 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -1465,7 +1465,8 @@ int clusterProcessPacket(clusterLink *link) {
/* Perform sanity checks */
if (totlen < 16) return 1; /* At least signature, version, totlen, count. */
- if (ntohs(hdr->ver) != 0) return 1; /* Can't handle versions other than 0.*/
+ if (ntohs(hdr->ver) != CLUSTER_PROTO_VER)
+ return 1; /* Can't handle versions other than the current one.*/
if (totlen > sdslen(link->rcvbuf)) return 1;
if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_PONG ||
type == CLUSTERMSG_TYPE_MEET)
@@ -2027,6 +2028,7 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
myself->slaveof : myself;
memset(hdr,0,sizeof(*hdr));
+ hdr->ver = htons(CLUSTER_PROTO_VER);
hdr->sig[0] = 'R';
hdr->sig[1] = 'C';
hdr->sig[2] = 'm';
diff --git a/src/cluster.h b/src/cluster.h
index 7d6567d45..ef5caf0d6 100644
--- a/src/cluster.h
+++ b/src/cluster.h
@@ -163,10 +163,11 @@ typedef struct {
char nodename[REDIS_CLUSTER_NAMELEN];
uint32_t ping_sent;
uint32_t pong_received;
- char ip[REDIS_IP_STR_LEN]; /* IP address last time it was seen */
- uint16_t port; /* port last time it was seen */
- uint16_t flags;
- uint32_t notused; /* for 64 bit alignment */
+ char ip[REDIS_IP_STR_LEN]; /* IP address last time it was seen */
+ uint16_t port; /* port last time it was seen */
+ uint16_t flags; /* node->flags copy */
+ uint16_t notused1; /* Some room for future improvements. */
+ uint32_t notused2;
} clusterMsgDataGossip;
typedef struct {
@@ -211,6 +212,7 @@ union clusterMsgData {
} update;
};
+#define CLUSTER_PROTO_VER 0 /* Cluster bus protocol version. */
typedef struct {
char sig[4]; /* Siganture "RCmb" (Redis Cluster message bus). */
diff --git a/src/redis.h b/src/redis.h
index 64f124e15..9e9c29a50 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -124,7 +124,7 @@ typedef long long mstime_t; /* millisecond time type. */
#define REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC 1
#define REDIS_DEFAULT_MIN_SLAVES_TO_WRITE 0
#define REDIS_DEFAULT_MIN_SLAVES_MAX_LAG 10
-#define REDIS_IP_STR_LEN INET6_ADDRSTRLEN
+#define REDIS_IP_STR_LEN 46 /* INET6_ADDRSTRLEN is 46, but we need to be sure */
#define REDIS_PEER_ID_LEN (REDIS_IP_STR_LEN+32) /* Must be enough for ip:port */
#define REDIS_BINDADDR_MAX 16
#define REDIS_MIN_RESERVED_FDS 32