/**
 * Function to process pollout
 *
 * @param fd
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uns32 dtm_internode_process_pollout(int fd)
{
	DTM_NODE_DB *node = NULL;

	TRACE_ENTER();
	node = dtm_node_get_by_comm_socket((uns32)fd);
	if (NULL == node) {
		TRACE("DTM :No node matching the fd for pollout, delete this fd from fd list ");
		assert(0);
		return NCSCC_RC_FAILURE;
	} else {
		/* Get the unsent messages from the list and send them */
		DTM_INTERNODE_UNSENT_MSGS *hdr = node->msgs_hdr;
		if (NULL == hdr) {
			/* No messages to be sent, reset the POLLOUT event on this fd */
			dtm_internode_reset_poll_fdlist(node->comm_socket);
		} else {
			dtm_internode_snd_unsent_msg(node);
		}
	}
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
示例#2
0
/**
 * Function to process the node info hdr
 *
 * @param dtms_cb stream_sock buffer node_info_hrd buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_process_node_info(DTM_INTERNODE_CB * dtms_cb, int stream_sock, uint8_t *buffer, uint8_t *node_info_hrd,
			    int buffer_len)
{
	uint32_t node_id;
	DTM_NODE_DB *node;
	uint32_t nodename_len;
	char nodename[MAX_NAME_LENGTH];
	int rc = 0;
	uint8_t *data = buffer;
	TRACE_ENTER();

	node_id = ncs_decode_32bit(&data);
	nodename_len = ncs_decode_32bit(&data);
	strncpy((char *)nodename, (char *)data, nodename_len);

	node = dtm_node_get_by_comm_socket(stream_sock);

	if (node == NULL) {
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	if (!node->comm_status) {

		/*****************************************************/
		/* nodeinfo data back to the client  NODE is still */
		/*****************************************************/

		if (node->node_id == 0) {
			node->node_id = node_id;
			strncpy((char *)&node->node_name, nodename, nodename_len);
			node->comm_status = true;
			if (dtm_node_add(node, 0) != NCSCC_RC_SUCCESS) {
				LOG_ER("DTM:  Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");				
				osafassert(0);
			
			}

		} else if (node->node_id == node_id) {
			strncpy((char *)&node->node_name, nodename, nodename_len);
			rc = dtm_comm_socket_send(stream_sock, node_info_hrd, buffer_len);
			if (rc != NCSCC_RC_SUCCESS) {

				LOG_ER("DTM: dtm_comm_socket_send() failed rc : %d", rc);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}
			node->comm_status = true;

		} else {
			LOG_ER("DTM: Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");
			osafassert(0);
		}

		TRACE("DTM: dtm_process_node_info node_ip:%s, node_id:%u i_addr_family:%d ", node->node_ip, node->node_id, node->i_addr_family);
		rc = dtm_process_node_up_down(node->node_id, node->node_name, node->node_ip , node->i_addr_family, node->comm_status);

		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("DTM: dtm_process_node_up_down() failed rc : %d ", rc);
			rc = NCSCC_RC_FAILURE;
		}
	} else {
		LOG_ER("DTM: Node down already  received  for this node ");
		osafassert(0);
	}

 done:
	TRACE_LEAVE();
	return rc;
}
示例#3
0
/**
 * Function to process internode poll and rcv message
 *
 * @param fd close_conn node_info_hrd node_info_buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
void dtm_internode_process_poll_rcv_msg(int fd, int *close_conn, uint8_t *node_info_hrd, uint16_t node_info_buffer_len)
{
	DTM_NODE_DB *node = NULL;
	TRACE_ENTER();

	node = dtm_node_get_by_comm_socket(fd);

	if (NULL == node) {
		LOG_ER("DTM: database mismatch");
		osafassert(0);
	}
	if (0 == node->bytes_tb_read) {
		if (0 == node->num_by_read_for_len_buff) {
			uint8_t *data;
			int recd_bytes = 0;

			/*******************************************************/
			/* Receive all incoming data on this socket */
			/*******************************************************/

			recd_bytes = recv(fd, node->len_buff, 2, 0);
			if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else if (2 == recd_bytes) {
				uint16_t local_len_buf = 0;

				data = node->len_buff;
				local_len_buf = ncs_decode_16bit(&data);
				node->buff_total_len = local_len_buf;
				node->num_by_read_for_len_buff = 2;

				if (NULL == (node->buffer = calloc(1, (local_len_buf + 3)))) {
					/* Length + 2 is done to reuse the same buffer 
					   while sending to other nodes */
					LOG_ER("\nMemory allocation failed in dtm_internode_processing");
					return;
				}
				recd_bytes = recv(fd, &node->buffer[2], local_len_buf, 0);

				if (recd_bytes < 0) {
					return;
				} else if (0 == recd_bytes) {
					*close_conn = true;
					return;
				} else if (local_len_buf > recd_bytes) {
					/* can happen only in two cases, system call interrupt or half data, */
					TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes,
					       local_len_buf);
					node->bytes_tb_read = node->buff_total_len - recd_bytes;
					return;
				} else if (local_len_buf == recd_bytes) {
					/* Call the common rcv function */
					dtm_internode_process_poll_rcv_msg_common(node, local_len_buf, node_info_hrd,
										  node_info_buffer_len, fd, close_conn);
				} else {
					LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
					osafassert(0);
				}
			} else {
				/* we had recd some bytes */
				if (recd_bytes < 0) {
					/* This can happen due to system call interrupt */
					return;
				} else if (1 == recd_bytes) {
					/* We recd one byte of the length part */
					node->num_by_read_for_len_buff = recd_bytes;
				} else {
					LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
					osafassert(0);
				}
			}
		} else if (1 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			recd_bytes = recv(fd, &node->len_buff[1], 1, 0);
			if (recd_bytes < 0) {
				/* This can happen due to system call interrupt */
				return;
			} else if (1 == recd_bytes) {
				/* We recd one byte(remaining) of the length part */
				uint8_t *data = node->len_buff;
				node->num_by_read_for_len_buff = 2;
				node->buff_total_len = ncs_decode_16bit(&data);
				return;
			} else if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else {
				LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
				osafassert(0);	/* This should never occur */
			}
		} else if (2 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			if (NULL == (node->buffer = calloc(1, (node->buff_total_len + 3)))) {
				/* Length + 2 is done to reuse the same buffer 
				   while sending to other nodes */
				LOG_ER("DTM :Memory allocation failed in dtm_internode_processing \n");
				return;
			}
			recd_bytes = recv(fd, &node->buffer[2], node->buff_total_len, 0);

			if (recd_bytes < 0) {
				return;
			} else if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else if (node->buff_total_len > recd_bytes) {
				/* can happen only in two cases, system call interrupt or half data, */
				TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes,
				       node->buff_total_len);
				node->bytes_tb_read = node->buff_total_len - recd_bytes;
				return;
			} else if (node->buff_total_len == recd_bytes) {
				/* Call the common rcv function */
				dtm_internode_process_poll_rcv_msg_common(node, node->buff_total_len, node_info_hrd,
									  node_info_buffer_len, fd, close_conn);
			} else {
				LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
				osafassert(0);
			}
		} else {
			LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
			osafassert(0);
		}

	} else {
		/* Partial data already read */
		int recd_bytes = 0;

		recd_bytes =
		    recv(fd, &node->buffer[2 + (node->buff_total_len - node->bytes_tb_read)], node->bytes_tb_read, 0);

		if (recd_bytes < 0) {
			return;
		} else if (0 == recd_bytes) {
			*close_conn = true;
			return;
		} else if (node->bytes_tb_read > recd_bytes) {
			/* can happen only in two cases, system call interrupt or half data, */
			TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes, node->bytes_tb_read);
			node->bytes_tb_read = node->bytes_tb_read - recd_bytes;
			return;
		} else if (node->bytes_tb_read == recd_bytes) {
			/* Call the common rcv function */
			dtm_internode_process_poll_rcv_msg_common(node, node->buff_total_len, node_info_hrd,
								  node_info_buffer_len, fd, close_conn);
		} else {
			LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
			osafassert(0);
		}
	}
	TRACE_LEAVE();
	return;
}
示例#4
0
/**
 * Function to process the node info hdr
 *
 * @param dtms_cb stream_sock buffer node_info_hrd buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uns32 dtm_process_node_info(DTM_INTERNODE_CB * dtms_cb, int stream_sock, uns8 *buffer, uns8 *node_info_hrd,
			    int buffer_len)
{
	uns32 node_id;
	DTM_NODE_DB *node;
	uns32 nodename_len;
	char nodename[MAX_NAME_LENGTH];
	int rc = 0;
	uns8 *data = buffer;
	TRACE_ENTER();

	node_id = ncs_decode_32bit(&data);
	nodename_len = ncs_decode_32bit(&data);
	strncpy((char *)nodename, (char *)data, nodename_len);

	node = dtm_node_get_by_comm_socket(stream_sock);

	if (node == NULL) {
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	if (!node->comm_status) {

		/*****************************************************/
		/* nodeinfo data back to the client  NODE is still */
		/*****************************************************/

		if (node->node_id == 0) {
			node->node_id = node_id;
			strncpy((char *)&node->node_name, nodename, nodename_len);
			node->comm_status = TRUE;
			if (dtm_node_add(node, 0) != NCSCC_RC_SUCCESS) {
				assert(0);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}

		} else if (node->node_id == node_id) {
			strncpy((char *)&node->node_name, nodename, nodename_len);
			rc = dtm_comm_socket_send(stream_sock, node_info_hrd, buffer_len);
			if (rc != NCSCC_RC_SUCCESS) {

				LOG_ER("DTM: dtm_comm_socket_send() failed rc : %d", rc);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}
			node->comm_status = TRUE;

		} else
			assert(0);

		rc = dtm_process_node_up_down(node->node_id, node->node_name, node->comm_status);

		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("DTM: dtm_process_node_up_down() failed rc : %d ", rc);
			rc = NCSCC_RC_FAILURE;
		}
	} else {
		LOG_ER(" conn details msg recd when conn_status is true");
		assert(0);
	}

 done:
	TRACE_LEAVE();
	return rc;
}