// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/cluster.c
// Function: clusterProcessGossipSection
void clusterProcessGossipSection(clusterMsg *hdr, clusterLink *link) {

    // 记录这条消息中包含了多少个节点的信息
    uint16_t count = ntohs(hdr->count);

    // 指向第一个节点的信息
    clusterMsgDataGossip *g = (clusterMsgDataGossip*) hdr->data.ping.gossip;

    // 取出发送者
    clusterNode *sender = link->node ? link->node : clusterLookupNode(hdr->sender);

    // 遍历所有节点的信息
    while(count--) {
        sds ci = sdsempty();

        // 分析节点的 flag
        uint16_t flags = ntohs(g->flags);

        // 信息节点
        clusterNode *node;

        // 取出节点的 flag
        if (flags == 0) ci = sdscat(ci,"noflags,");
        if (flags & REDIS_NODE_MYSELF) ci = sdscat(ci,"myself,");
        if (flags & REDIS_NODE_MASTER) ci = sdscat(ci,"master,");
        if (flags & REDIS_NODE_SLAVE) ci = sdscat(ci,"slave,");
        if (flags & REDIS_NODE_PFAIL) ci = sdscat(ci,"fail?,");
        if (flags & REDIS_NODE_FAIL) ci = sdscat(ci,"fail,");
        if (flags & REDIS_NODE_HANDSHAKE) ci = sdscat(ci,"handshake,");
        if (flags & REDIS_NODE_NOADDR) ci = sdscat(ci,"noaddr,");
        if (ci[sdslen(ci)-1] == ',') ci[sdslen(ci)-1] = ' ';

        redisLog(REDIS_DEBUG,"GOSSIP %.40s %s:%d %s",
            g->nodename,
            g->ip,
            ntohs(g->port),
            ci);
        sdsfree(ci);

        /* Update our state accordingly to the gossip sections */
        // 使用消息中的信息对节点进行更新
        node = clusterLookupNode(g->nodename);
        // 节点已经存在于当前节点
        if (node) {
            /* We already know this node.
               Handle failure reports, only when the sender is a master. */
            // 如果 sender 是一个主节点，那么我们需要处理下线报告
            if (sender && nodeIsMaster(sender) && node != myself) {
                // 节点处于 FAIL 或者 PFAIL 状态
                if (flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL)) {

                    // 添加 sender 对 node 的下线报告
                    if (clusterNodeAddFailureReport(node,sender)) {
                        redisLog(REDIS_VERBOSE,
                            "Node %.40s reported node %.40s as not reachable.",
                            sender->name, node->name);
                    }

                    // 尝试将 node 标记为 FAIL
                    markNodeAsFailingIfNeeded(node);

                // 节点处于正常状态
                } else {

                    // 如果 sender 曾经发送过对 node 的下线报告
                    // 那么清除该报告
                    if (clusterNodeDelFailureReport(node,sender)) {
                        redisLog(REDIS_VERBOSE,
                            "Node %.40s reported node %.40s is back online.",
                            sender->name, node->name);
                    }
                }
            }

            /* If we already know this node, but it is not reachable, and
             * we see a different address in the gossip section, start an
             * handshake with the (possibly) new address: this will result
             * into a node address update if the handshake will be
             * successful. */
            // 如果节点之前处于 PFAIL 或者 FAIL 状态
            // 并且该节点的 IP 或者端口号已经发生变化
            // 那么可能是节点换了新地址，尝试对它进行握手
            if (node->flags & (REDIS_NODE_FAIL|REDIS_NODE_PFAIL) &&
                (strcasecmp(node->ip,g->ip) || node->port != ntohs(g->port)))
            {
                clusterStartHandshake(g->ip,ntohs(g->port));
            }

        // 当前节点不认识 node
        } else {
            /* If it's not in NOADDR state and we don't have it, we
             * start a handshake process against this IP/PORT pairs.
             *
             * 如果 node 不在 NOADDR 状态，并且当前节点不认识 node 
             * 那么向 node 发送 HANDSHAKE 消息。
             *
             * Note that we require that the sender of this gossip message
             * is a well known node in our cluster, otherwise we risk
             * joining another cluster.
             *
             * 注意，当前节点必须保证 sender 是本集群的节点，
             * 否则我们将有加入了另一个集群的风险。
             */
            if (sender &&
                !(flags & REDIS_NODE_NOADDR) &&
                !clusterBlacklistExists(g->nodename))
            {
                clusterStartHandshake(g->ip,ntohs(g->port));
            }
        }

        /* Next node */
        // 处理下个节点的信息
        g++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzwl 0xe(%rax), %edi
callq 0x1f560
movw %ax, -0x12(%rbp)
movq -0x8(%rbp), %rax
addq $0x8a0, %rax            # imm = 0x8A0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6ab8b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x6ab9c
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
callq 0x689b0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movw -0x12(%rbp), %ax
movw %ax, %cx
addw $-0x1, %cx
movw %cx, -0x12(%rbp)
cmpw $0x0, %ax
je 0x6af02
callq 0x2c0c0
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x60(%rax), %edi
callq 0x1f560
movw %ax, -0x32(%rbp)
movzwl -0x32(%rbp), %eax
cmpl $0x0, %eax
jne 0x6abf4
movq -0x30(%rbp), %rdi
leaq 0x7b555(%rip), %rsi     # 0xe6140
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6ac14
movq -0x30(%rbp), %rdi
leaq 0x7b53e(%rip), %rsi     # 0xe6149
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6ac34
movq -0x30(%rbp), %rdi
leaq 0x7b526(%rip), %rsi     # 0xe6151
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6ac54
movq -0x30(%rbp), %rdi
leaq 0x7b50e(%rip), %rsi     # 0xe6159
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x6ac74
movq -0x30(%rbp), %rdi
leaq 0x7b4f5(%rip), %rsi     # 0xe6160
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x6ac94
movq -0x30(%rbp), %rdi
leaq 0x7b4dc(%rip), %rsi     # 0xe6167
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x6acb4
movq -0x30(%rbp), %rdi
leaq 0x7b4c2(%rip), %rsi     # 0xe616d
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6acd4
movq -0x30(%rbp), %rdi
leaq 0x7b4ad(%rip), %rsi     # 0xe6178
callq 0x2c5b0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x67ee0
movq %rax, %rcx
movq -0x50(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2c, %eax
jne 0x6ad19
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x67ee0
movq %rax, %rcx
movq -0x58(%rbp), %rax
subq $0x1, %rcx
movb $0x20, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x5e(%rax), %edi
callq 0x1f560
movq -0x68(%rbp), %rdx
movq -0x60(%rbp), %rcx
movzwl %ax, %r8d
movq -0x30(%rbp), %r9
xorl %edi, %edi
leaq 0x7b42d(%rip), %rsi     # 0xe6180
movb $0x0, %al
callq 0x24fb0
movq -0x30(%rbp), %rdi
callq 0x2c160
movq -0x20(%rbp), %rdi
callq 0x689b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x6aea9
cmpq $0x0, -0x28(%rbp)
je 0x6ae2f
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6ae2f
movq -0x40(%rbp), %rax
cmpq 0xbd1d4(%rip), %rax     # 0x127f78
je 0x6ae2f
movzwl -0x32(%rbp), %eax
andl $0xc, %eax
cmpl $0x0, %eax
je 0x6adf6
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x69fc0
cmpl $0x0, %eax
je 0x6adeb
movq -0x28(%rbp), %rdx
addq $0x8, %rdx
movq -0x40(%rbp), %rcx
addq $0x8, %rcx
movl $0x1, %edi
leaq 0x7b3b2(%rip), %rsi     # 0xe6196
movb $0x0, %al
callq 0x24fb0
movq -0x40(%rbp), %rdi
callq 0x6a670
jmp 0x6ae2d
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6a110
cmpl $0x0, %eax
je 0x6ae2b
movq -0x28(%rbp), %rdx
addq $0x8, %rdx
movq -0x40(%rbp), %rcx
addq $0x8, %rcx
movl $0x1, %edi
leaq 0x7b3a3(%rip), %rsi     # 0xe61c7
movb $0x0, %al
callq 0x24fb0
jmp 0x6ae2d
jmp 0x6ae2f
movq -0x40(%rbp), %rax
movl 0x30(%rax), %eax
andl $0xc, %eax
cmpl $0x0, %eax
je 0x6aea7
movq -0x40(%rbp), %rdi
addq $0x888, %rdi            # imm = 0x888
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x6ae82
movq -0x40(%rbp), %rax
movl 0x8b8(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x5e(%rax), %edi
callq 0x1f560
movw %ax, %cx
movl -0x6c(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x6aea7
movq -0x20(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x5e(%rax), %edi
callq 0x1f560
movq -0x78(%rbp), %rdi
movzwl %ax, %esi
callq 0x6a9d0
jmp 0x6aef1
cmpq $0x0, -0x28(%rbp)
je 0x6aeef
movzwl -0x32(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x6aeef
movq -0x20(%rbp), %rdi
callq 0x6a610
cmpl $0x0, %eax
jne 0x6aeef
movq -0x20(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x5e(%rax), %edi
callq 0x1f560
movq -0x80(%rbp), %rdi
movzwl %ax, %esi
callq 0x6a9d0
jmp 0x6aef1
movq -0x20(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x20(%rbp)
jmp 0x6aba4
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)