Exemple #1
0
/**
 * \brief This function loads current context from Mongo database
 *
 * This function has to be called during start of Verse server, when no client
 * is connected yet. This function doesn't restore whole verse server context,
 * but it only loads nodes shared in parent node of scene nodes. Thus system
 * nodes like avatar nodes, user nodes are not loaded. Finally, there has to be
 * basic nodes structure (nodes: 1, 2, 3). The node 3 will be removed with node
 * from MongoDB.
 *
 * \param[in] *vs_ctx The pointer at current verse server context
 */
int vs_mongo_context_load(struct VS_CTX *vs_ctx)
{
	/* Try to find parent of scene nodes in MongoDB */
	if(vs_mongo_node_node_exist(vs_ctx, VRS_SCENE_PARENT_NODE_ID) == 1) {

		/* When node exist, then destroy existing parent node of scene nodes */
		vs_node_destroy_branch(vs_ctx, vs_ctx->data.scene_node, 0);

		/* Try to load node from database and all child nodes */
		vs_ctx->data.scene_node = vs_mongo_node_load_linked(vs_ctx,
				vs_ctx->data.root_node,
				VRS_SCENE_PARENT_NODE_ID,
				-1);

		/* When loading of node failed, then recreate new default parent node
		 * of scene nodes */
		if(vs_ctx->data.scene_node == NULL) {
			v_print_log(VRS_PRINT_ERROR,
					"Restoring data from MongoDB: %s Failed\n",
					vs_ctx->mongodb_db_name);
			vs_ctx->data.scene_node = vs_node_create_scene_parent(vs_ctx);
		} else {
			v_print_log(VRS_PRINT_DEBUG_MSG,
					"Data restored from MongoDB: %s\n",
					vs_ctx->mongodb_db_name);
		}
	}

	return 1;
}
Exemple #2
0
/**
 * \brief This function destroy branch of nodes
 */
int vs_node_destroy_branch(struct VS_CTX *vs_ctx,
		struct VSNode *node,
		uint8 send)
{
	struct VSNode *child_node;
	struct VSEntityFollower *node_follower;
	struct VSLink *link, *next_link;
	int ret = 0;

	link = node->children_links.first;

	/* Remove all sub-branches */
	while(link != NULL) {
		child_node = link->child;
		next_link = link->next;
		vs_node_destroy_branch(vs_ctx, child_node, send);
		link = next_link;
	}

	node_follower = node->node_folls.first;
	if(node_follower != NULL && send == 1) {
		/* Send node_destroy command to all clients that knows about this node */
		ret = vs_node_send_destroy(node);

		/* Own node will be destroyed, when verse server receive confirmation
		 * of receiving node_destroy command */
	} else {
		/* When all clients consider this node as destroyed, then it is
		 * possible to remove it from server */
		ret = vs_node_destroy(vs_ctx, node);
	}

	return ret;
}
Exemple #3
0
/**
 * \brief Destroy Verse server context
 *
 * \param[in]	vs_ctx	The Verse server context.
 */
static void vs_destroy_ctx(struct VS_CTX *vs_ctx)
{
	struct VSUser *user;
	int i;

	/* Free all data shared at verse server */
	vs_node_destroy_branch(vs_ctx, vs_ctx->data.root_node, 0);

	/* Destroy hashed array of nodes */
	v_hash_array_destroy(&vs_ctx->data.nodes);

	/* Destroy list of connections */
	for (i=0; i<vs_ctx->max_sessions; i++) {
		if(vs_ctx->vsessions[i] != NULL) {
			v_destroy_session(vs_ctx->vsessions[i]);
			free(vs_ctx->vsessions[i]);
			vs_ctx->vsessions[i] = NULL;
		}
	}

	free(vs_ctx->vsessions); vs_ctx->vsessions = NULL;

	free(vs_ctx->port_list); vs_ctx->port_list = NULL;

	free(vs_ctx->tcp_io_ctx.buf); vs_ctx->tcp_io_ctx.buf = NULL;

	free(vs_ctx->private_cert_file); vs_ctx->private_cert_file = NULL;
	if(vs_ctx->ca_cert_file != NULL) {
		free(vs_ctx->ca_cert_file);
		vs_ctx->ca_cert_file = NULL;
	}
	free(vs_ctx->public_cert_file); vs_ctx->public_cert_file = NULL;

	free(vs_ctx->hostname); vs_ctx->hostname = NULL;

	free(vs_ctx->ded); vs_ctx->ded = NULL;

	if(vs_ctx->csv_user_file != NULL) {
		free(vs_ctx->csv_user_file);
		vs_ctx->csv_user_file = NULL;
	}

	user = (struct VSUser*)vs_ctx->users.first;
	while(user != NULL) {
		vs_user_free(user);
		user = user->next;
	}
	v_list_free(&vs_ctx->users);

#ifdef WITH_OPENSSL
	vs_destroy_stream_ctx(vs_ctx);
#endif
}