// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/src/cl_cluster.c
// Function: cluster_ping_node
static void
cluster_ping_node(cl_cluster *asc, cl_cluster_node *cn, cf_vector *services_v)
{
	// cf_debug("cluster ping node: %s",cn->name);

	bool update_partitions = false;

	// for all elements in the sockaddr_in list - ping and add hosts.
	for (uint i=0;i<cf_vector_size(&cn->sockaddr_in_v);i++) {
		struct sockaddr_in *sa_in = cf_vector_getp(&cn->sockaddr_in_v, i);
		cl_node_info node_info;

		if (cl_get_node_info(cn->name, sa_in, &node_info) != 0) {
			// todo: this address is no longer right for this node, update the node's list
			// and if there's no addresses left, dun node
			cf_debug("Info request failed for %s", cn->name);
			cl_cluster_node_dun(cn, NODE_DUN_INFO_ERR);
			continue;
		}

		if (node_info.dun) {
			cl_cluster_node_dun(cn, NODE_DUN_INFO_ERR);
			cl_node_info_free(&node_info);
			break;
		}

		cl_cluster_node_ok(cn);

		if (strcmp(node_info.node_name, cn->name) != 0) {
			// node name has changed. Dun is easy, would be better to remove the address
			// from the list of addresses for this node, and only dun if there
			// are no addresses left
			cf_info("node name has changed! old='%s' new='%s'", cn->name, node_info.node_name);
			cl_cluster_node_dun(cn, NODE_DUN_NAME_CHG);
		}

		if (cn->partition_generation != node_info.partition_generation) {
			update_partitions = true;
			cn->partition_generation = node_info.partition_generation;
		}

		cluster_services_parse(asc, node_info.services, services_v);
		cl_node_info_free(&node_info);
		break;
	}
	
	if (update_partitions) {
		// cf_debug("node %s: partitions have changed, need update", cn->name);

		// remove all current values, then add up-to-date values
		pthread_mutex_lock(&asc->LOCK);
		cl_partition_table_remove_node(asc, cn);
		pthread_mutex_unlock(&asc->LOCK);

		for (uint i=0;i<cf_vector_size(&cn->sockaddr_in_v);i++) {
			struct sockaddr_in *sa_in = cf_vector_getp(&cn->sockaddr_in_v, i);
			cl_replicas replicas;

			if (cl_get_replicas(cn->name, sa_in, &replicas) != 0) {
				continue;
			}

			if (replicas.write_replicas) {
				cluster_partitions_process(asc, cn, replicas.write_replicas, true);
			}

			if (replicas.read_replicas) {
				cluster_partitions_process(asc, cn, replicas.read_replicas, false);
			}

			cl_replicas_free(&replicas);
			break;
		}
	}
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movb $0x0, 0x6f(%rsp)
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
callq 0x9da0
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jae 0xc7d2
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
movl 0x68(%rsp), %esi
callq 0x17340
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rdi
movq 0x60(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x12400
cmpl $0x0, %eax
je 0xc6ef
leaq 0x11c27(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jg 0xc6db
leaq 0x11c1d(%rip), %rax     # 0x1e2e0
movq (%rax), %rcx
movq 0x78(%rsp), %rdx
movl $0x3, %edi
leaq 0xc474(%rip), %rsi      # 0x18b4b
movb $0x0, %al
callq *%rcx
movq 0x78(%rsp), %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0xbe50
jmp 0xc7c2
testb $0x1, 0x5c(%rsp)
je 0xc714
movq 0x78(%rsp), %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0xbe50
leaq 0x30(%rsp), %rdi
callq 0x12770
jmp 0xc7d2
movq 0x78(%rsp), %rdi
callq 0xbed0
leaq 0x30(%rsp), %rdi
addq $0x8, %rdi
movq 0x78(%rsp), %rsi
callq 0x2380
cmpl $0x0, %eax
je 0xc780
leaq 0x11b9b(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
movl $0x2, %eax
cmpl %ecx, %eax
jg 0xc771
leaq 0x11b91(%rip), %rax     # 0x1e2e0
movq (%rax), %r8
movq 0x78(%rsp), %rdx
leaq 0x30(%rsp), %rcx
addq $0x8, %rcx
movl $0x2, %edi
leaq 0xc3fa(%rip), %rsi      # 0x18b66
movb $0x0, %al
callq *%r8
movq 0x78(%rsp), %rdi
movl $0x321, %esi            # imm = 0x321
callq 0xbe50
movq 0x78(%rsp), %rax
movl 0x68(%rax), %eax
cmpl 0x58(%rsp), %eax
je 0xc79f
movb $0x1, 0x6f(%rsp)
movl 0x58(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x68(%rax)
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0xc8e0
leaq 0x30(%rsp), %rdi
callq 0x12770
jmp 0xc7d2
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0xc656
testb $0x1, 0x6f(%rsp)
je 0xc8d6
movq 0x80(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x23e0
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0xce50
movq 0x80(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x21c0
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, (%rsp)
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
callq 0x9da0
movl %eax, %ecx
movl (%rsp), %eax
cmpl %ecx, %eax
jae 0xc8d4
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
movl 0x2c(%rsp), %esi
callq 0x17340
movq %rax, 0x20(%rsp)
movq 0x78(%rsp), %rdi
movq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x12790
cmpl $0x0, %eax
je 0xc873
jmp 0xc8c4
cmpq $0x0, 0x10(%rsp)
je 0xc897
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl $0x1, %ecx
callq 0xca60
cmpq $0x0, 0x18(%rsp)
je 0xc8b8
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0xca60
leaq 0x8(%rsp), %rdi
callq 0x12a20
jmp 0xc8d4
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xc81f
jmp 0xc8d6
addq $0x88, %rsp
retq
nop