MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterProcessPacket

Function clusterProcessPacket

app/redis-6.2.6/src/cluster.c:1752–2241  ·  view source on GitHub ↗

When this function is called, there is a packet to process starting * at node->rcvbuf. Releasing the buffer is up to the caller, so this * function should just handle the higher level stuff of processing the * packet, modifying the cluster state if needed. * * The function returns 1 if the link is still valid after the packet * was processed, otherwise 0 if the link was freed since the packe

Source from the content-addressed store, hash-verified

1750 * processing lead to some inconsistency error (for instance a PONG
1751 * received from the wrong sender ID). */
1752int clusterProcessPacket(clusterLink *link) {
1753 clusterMsg *hdr = (clusterMsg*) link->rcvbuf;
1754 uint32_t totlen = ntohl(hdr->totlen);
1755 uint16_t type = ntohs(hdr->type);
1756 mstime_t now = mstime();
1757
1758 if (type < CLUSTERMSG_TYPE_COUNT)
1759 server.cluster->stats_bus_messages_received[type]++;
1760 serverLog(LL_DEBUG,"--- Processing packet of type %d, %lu bytes",
1761 type, (unsigned long) totlen);
1762
1763 /* Perform sanity checks */
1764 if (totlen < 16) return 1; /* At least signature, version, totlen, count. */
1765 if (totlen > link->rcvbuf_len) return 1;
1766
1767 if (ntohs(hdr->ver) != CLUSTER_PROTO_VER) {
1768 /* Can't handle messages of different versions. */
1769 return 1;
1770 }
1771
1772 uint16_t flags = ntohs(hdr->flags);
1773 uint64_t senderCurrentEpoch = 0, senderConfigEpoch = 0;
1774 clusterNode *sender;
1775
1776 if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_PONG ||
1777 type == CLUSTERMSG_TYPE_MEET)
1778 {
1779 uint16_t count = ntohs(hdr->count);
1780 uint32_t explen; /* expected length of this packet */
1781
1782 explen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
1783 explen += (sizeof(clusterMsgDataGossip)*count);
1784 if (totlen != explen) return 1;
1785 } else if (type == CLUSTERMSG_TYPE_FAIL) {
1786 uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
1787
1788 explen += sizeof(clusterMsgDataFail);
1789 if (totlen != explen) return 1;
1790 } else if (type == CLUSTERMSG_TYPE_PUBLISH) {
1791 uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
1792
1793 explen += sizeof(clusterMsgDataPublish) -
1794 8 +
1795 ntohl(hdr->data.publish.msg.channel_len) +
1796 ntohl(hdr->data.publish.msg.message_len);
1797 if (totlen != explen) return 1;
1798 } else if (type == CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST ||
1799 type == CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK ||
1800 type == CLUSTERMSG_TYPE_MFSTART)
1801 {
1802 uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
1803
1804 if (totlen != explen) return 1;
1805 } else if (type == CLUSTERMSG_TYPE_UPDATE) {
1806 uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
1807
1808 explen += sizeof(clusterMsgDataUpdate);
1809 if (totlen != explen) return 1;

Callers 1

clusterReadHandlerFunction · 0.85

Calls 15

clusterLookupNodeFunction · 0.85
clusterDoBeforeSleepFunction · 0.85
connSockNameFunction · 0.85
strcmpFunction · 0.85
nodeIp2StringFunction · 0.85
clusterAddNodeFunction · 0.85
clusterSendPingFunction · 0.85
clusterDelNodeFunction · 0.85
clusterRenameNodeFunction · 0.85
freeClusterLinkFunction · 0.85

Tested by

no test coverage detected