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

Function clusterBuildMessageHdr

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

Build the message header. hdr must point to a buffer at least * sizeof(clusterMsg) in bytes. */

Source from the content-addressed store, hash-verified

2432/* Build the message header. hdr must point to a buffer at least
2433 * sizeof(clusterMsg) in bytes. */
2434void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
2435 int totlen = 0;
2436 uint64_t offset;
2437 clusterNode *master;
2438
2439 /* If this node is a master, we send its slots bitmap and configEpoch.
2440 * If this node is a slave we send the master's information instead (the
2441 * node is flagged as slave so the receiver knows that it is NOT really
2442 * in charge for this slots. */
2443 master = (nodeIsSlave(myself) && myself->slaveof) ?
2444 myself->slaveof : myself;
2445
2446 memset(hdr,0,sizeof(*hdr));
2447 hdr->ver = htons(CLUSTER_PROTO_VER);
2448 hdr->sig[0] = 'R';
2449 hdr->sig[1] = 'C';
2450 hdr->sig[2] = 'm';
2451 hdr->sig[3] = 'b';
2452 hdr->type = htons(type);
2453 memcpy(hdr->sender,myself->name,CLUSTER_NAMELEN);
2454
2455 /* If cluster-announce-ip option is enabled, force the receivers of our
2456 * packets to use the specified address for this node. Otherwise if the
2457 * first byte is zero, they'll do auto discovery. */
2458 memset(hdr->myip,0,NET_IP_STR_LEN);
2459 if (server.cluster_announce_ip) {
2460 strncpy(hdr->myip,server.cluster_announce_ip,NET_IP_STR_LEN);
2461 hdr->myip[NET_IP_STR_LEN-1] = '\0';
2462 }
2463
2464 /* Handle cluster-announce-[tls-|bus-]port. */
2465 int announced_port, announced_pport, announced_cport;
2466 deriveAnnouncedPorts(&announced_port, &announced_pport, &announced_cport);
2467
2468 memcpy(hdr->myslots,master->slots,sizeof(hdr->myslots));
2469 memset(hdr->slaveof,0,CLUSTER_NAMELEN);
2470 if (myself->slaveof != NULL)
2471 memcpy(hdr->slaveof,myself->slaveof->name, CLUSTER_NAMELEN);
2472 hdr->port = htons(announced_port);
2473 hdr->pport = htons(announced_pport);
2474 hdr->cport = htons(announced_cport);
2475 hdr->flags = htons(myself->flags);
2476 hdr->state = server.cluster->state;
2477
2478 /* Set the currentEpoch and configEpochs. */
2479 hdr->currentEpoch = htonu64(server.cluster->currentEpoch);
2480 hdr->configEpoch = htonu64(master->configEpoch);
2481
2482 /* Set the replication offset. */
2483 if (nodeIsSlave(myself))
2484 offset = replicationGetSlaveOffset();
2485 else
2486 offset = server.master_repl_offset;
2487 hdr->offset = htonu64(offset);
2488
2489 /* Set the message flags. */
2490 if (nodeIsMaster(myself) && server.cluster->mf_end)
2491 hdr->mflags[0] |= CLUSTERMSG_FLAG0_PAUSED;

Callers 8

clusterSendPingFunction · 0.85
clusterSendPublishFunction · 0.85
clusterSendFailFunction · 0.85
clusterSendUpdateFunction · 0.85
clusterSendModuleFunction · 0.85
clusterSendFailoverAuthFunction · 0.85
clusterSendMFStartFunction · 0.85

Calls 5

memsetFunction · 0.85
strncpyFunction · 0.85
deriveAnnouncedPortsFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected