Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6987a959
Commit
6987a959
authored
Feb 10, 2014
by
antirez
Browse files
Cluster: clusterReadHandler() fixed to work with new message header.
parent
ad85f520
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
6987a959
...
@@ -1167,8 +1167,6 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -1167,8 +1167,6 @@ int clusterProcessPacket(clusterLink *link) {
/* Perform sanity checks */
/* Perform sanity checks */
if
(
totlen
<
16
)
return
1
;
/* At least signature, version, totlen, count. */
if
(
totlen
<
16
)
return
1
;
/* At least signature, version, totlen, count. */
if
(
hdr
->
sig
[
0
]
!=
'R'
||
hdr
->
sig
[
1
]
!=
'C'
||
hdr
->
sig
[
2
]
!=
'm'
||
hdr
->
sig
[
3
]
!=
'b'
)
return
1
;
/* Bad signature. */
if
(
ntohs
(
hdr
->
ver
)
!=
0
)
return
1
;
/* Can't handle versions other than 0. */
if
(
ntohs
(
hdr
->
ver
)
!=
0
)
return
1
;
/* Can't handle versions other than 0. */
if
(
totlen
>
sdslen
(
link
->
rcvbuf
))
return
1
;
if
(
totlen
>
sdslen
(
link
->
rcvbuf
))
return
1
;
if
(
type
==
CLUSTERMSG_TYPE_PING
||
type
==
CLUSTERMSG_TYPE_PONG
||
if
(
type
==
CLUSTERMSG_TYPE_PING
||
type
==
CLUSTERMSG_TYPE_PONG
||
...
@@ -1582,18 +1580,22 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1582,18 +1580,22 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
while
(
1
)
{
/* Read as long as there is data to read. */
while
(
1
)
{
/* Read as long as there is data to read. */
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
rcvbuflen
=
sdslen
(
link
->
rcvbuf
);
if
(
rcvbuflen
<
4
)
{
if
(
rcvbuflen
<
8
)
{
/* First, obtain the first
four
bytes to get the full message
/* First, obtain the first
8
bytes to get the full message
* length. */
* length. */
readlen
=
4
-
rcvbuflen
;
readlen
=
8
-
rcvbuflen
;
}
else
{
}
else
{
/* Finally read the full message. */
/* Finally read the full message. */
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
hdr
=
(
clusterMsg
*
)
link
->
rcvbuf
;
if
(
rcvbuflen
==
4
)
{
if
(
rcvbuflen
==
8
)
{
/* Perform some sanity check on the message length. */
/* Perform some sanity check on the message signature
if
(
ntohl
(
hdr
->
totlen
)
<
CLUSTERMSG_MIN_LEN
)
{
* and length. */
if
(
memcmp
(
hdr
->
sig
,
"RCmb"
,
4
)
!=
0
||
ntohl
(
hdr
->
totlen
)
<
CLUSTERMSG_MIN_LEN
)
{
redisLog
(
REDIS_WARNING
,
redisLog
(
REDIS_WARNING
,
"Bad message length received from Cluster bus."
);
"Bad message length or signature received "
"from Cluster bus."
);
handleLinkIOError
(
link
);
handleLinkIOError
(
link
);
return
;
return
;
}
}
...
@@ -1619,7 +1621,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1619,7 +1621,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
/* Total length obtained? Process this packet. */
/* Total length obtained? Process this packet. */
if
(
rcvbuflen
>=
4
&&
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
rcvbuflen
>=
8
&&
rcvbuflen
==
ntohl
(
hdr
->
totlen
))
{
if
(
clusterProcessPacket
(
link
))
{
if
(
clusterProcessPacket
(
link
))
{
sdsfree
(
link
->
rcvbuf
);
sdsfree
(
link
->
rcvbuf
);
link
->
rcvbuf
=
sdsempty
();
link
->
rcvbuf
=
sdsempty
();
...
...
src/cluster.h
View file @
6987a959
...
@@ -196,9 +196,9 @@ union clusterMsgData {
...
@@ -196,9 +196,9 @@ union clusterMsgData {
typedef
struct
{
typedef
struct
{
char
sig
[
4
];
/* Siganture "RCmb" (Redis Cluster message bus). */
char
sig
[
4
];
/* Siganture "RCmb" (Redis Cluster message bus). */
uint32_t
totlen
;
/* Total length of this message */
uint16_t
ver
;
/* Protocol version, currently set to 0. */
uint16_t
ver
;
/* Protocol version, currently set to 0. */
uint16_t
notused0
;
/* 2 bytes not used. */
uint16_t
notused0
;
/* 2 bytes not used. */
uint32_t
totlen
;
/* Total length of this message */
uint16_t
type
;
/* Message type */
uint16_t
type
;
/* Message type */
uint16_t
count
;
/* Only used for some kind of messages. */
uint16_t
count
;
/* Only used for some kind of messages. */
uint64_t
currentEpoch
;
/* The epoch accordingly to the sending node. */
uint64_t
currentEpoch
;
/* The epoch accordingly to the sending node. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment