/** 
 * initialize the Portscan Tracker.
 *
 * This takes several arguments, all, on the PS_CONFIG structure.
 * 
 * @param trackerp tracker object to initialize
 * @param configp well-formed configuration to initialize this object
 * 
 * @return FLOW_SUCCESS on success
 */
int flowps_init(PS_TRACKER *trackerp, PS_CONFIG *configp)
{
    int ret;
    
    if(!trackerp || !configp)
        return FLOW_ENULL;

    /* we should validate this threshold object somewhat */
    memcpy(&trackerp->config, configp, sizeof(PS_CONFIG));    

    ret = scoreboard_init(&trackerp->table_active,            /* table */
                          "Active Talkers",                   /* description */
                          TRACKER_ACTIVE,                     /* position */
                          trackerp->config.sb_rows_talker,    /* node count */
                          trackerp->config.sb_memcap_talker); /* memcap */

    if(ret != FLOW_SUCCESS)
    {
        return ret;
    }
    
    ret = scoreboard_init(&trackerp->table_scanner,            /* table */
                          "Portscanners",                      /* description */
                          TRACKER_SCANNER,                     /* position */
                          trackerp->config.sb_rows_scanner,    /* node count */
                          trackerp->config.sb_memcap_scanner); /* memcap */

    if(ret != FLOW_SUCCESS)
    {
        scoreboard_destroy(&trackerp->table_active);
        return ret;
    }

    /* setup the unique talkers table */
    ret = ut_init(&trackerp->unique_tracker,trackerp->config.ut_rows, trackerp->config.ut_memcap);

    if(ret != FLOW_SUCCESS)
    {
        scoreboard_destroy(&trackerp->table_active);
        scoreboard_destroy(&trackerp->table_scanner);
        return ret;
    }

    /* the watchnet stuff is optional */
    if(flowps_server_stats_enabled(trackerp) == FLOW_SUCCESS)
    {
        ret = server_stats_init(&trackerp->server_stats,
                                trackerp->config.server_watchnet_ipv4,
                                trackerp->config.server_rows,
                                trackerp->config.server_memcap);

        if(ret != FLOW_SUCCESS)
        {
            scoreboard_destroy(&trackerp->table_active);
            scoreboard_destroy(&trackerp->table_scanner);
            ut_destroy(&trackerp->unique_tracker);
            return ret;
        }
    }    

    s_enabled = 1;
    
    return FLOW_SUCCESS;
}
Example #2
0
void server_init( char* conf_file_name, int map_szx, int map_szy, int tdepth, int speed_min, int speed_max,
					int apple_map_ratio, int apple_pl_ratio, int wall_map_ratio, int wall_pl_ratio, char* balname )
{
	int i;

	rand_seed = (unsigned int) time( NULL );
	srand( (unsigned int) time( NULL ) );

	conf_t* c = conf_create();	assert(c);
	conf_parse_file( c, conf_file_name );

	/* server */
	sv.port = conf_get_int( c, "server.port" );
	//sv.num_threads		= conf_get_int( c, "server.number_of_threads" );
	sv.update_interval = conf_get_int( c, "server.update_interval" );
	sv.stats_interval = conf_get_int( c, "server.stats_interval" );

	assert( sv.port > 1023 );
	assert( sv.num_threads > 0 && sv.num_threads <= MAX_THREADS );
	assert( sv.update_interval > 0 );
	assert( sv.stats_interval > 0 );

	/* quests */
	sv.quest_between = conf_get_int( c, "server.quest_between" );
	sv.quest_length = conf_get_int( c, "server.quest_length" );

	assert( sv.quest_between > 0 && sv.quest_length > 0 );
	assert( sv.quest_between > sv.update_interval && sv.quest_length > sv.update_interval );

	/* initialize clients array */
	sv.n_clients = 0;
	sv.clients = new tm_p_tm_sv_client_t[MAX_ENTITIES];
	assert( sv.clients );

	/* initialize world */
	server_traces_init();
	actions_init( c );
	server_init_multiple_actions();

	entity_types_init( c );
	// override the speed settings read from the config file
	entity_types[ ET_PLAYER ]->attr_types[ PL_SPEED ].min = speed_min;
	entity_types[ ET_PLAYER ]->attr_types[ PL_SPEED ].max = speed_max;
	// override the ratio settings read from the config file
	entity_types[ ET_APPLE ]->ratio    = apple_map_ratio;
	entity_types[ ET_APPLE ]->pl_ratio = apple_pl_ratio;
	entity_types[ ET_WALL ]->ratio    = wall_map_ratio;
	entity_types[ ET_WALL ]->pl_ratio = wall_pl_ratio;

	tm_worldmap_init( c, map_szx, map_szy, tdepth );
	server_init_quests();

	tm_worldmap_generate();
	tm_worldmap_is_valid();
/*
        //burceam: if heuristic1 is turned on, allocate structures for feedback/info
        sv.h1_dbg_num_ent = NULL;
        sv.h1_dbg_num_set = NULL;
        //temporarily turned it always on, for potential study; 
        //if (sv.heuristic1 != 0) 
        {
           sv.h1_dbg_num_ent = (int *) malloc (sv.wl_cycles * sizeof (int));
           sv.h1_dbg_num_set = (int *) malloc (sv.wl_cycles * sizeof (int));
           assert ((sv.h1_dbg_num_ent != NULL) && (sv.h1_dbg_num_set != NULL));
           int i;
           for (i = 0; i < sv.wl_cycles; i++) {
              sv.h1_dbg_num_ent [i] = 0;
              sv.h1_dbg_num_set [i] = 0;
           }
        }
        
        //burceam: for heuristic 2, hopefully temporary
        //note that this may need to be resized at some point: new players may join,
        //and existing players can drop out.
        //change_grain_to_entity_for_h3 is obviously meant to be used by heuristic h3.
        {
           sv.change_grain_to_entity = (unsigned char *) malloc (sv.wl_client_count * sizeof (unsigned char));
           sv.change_grain_to_entity_for_h3 = (unsigned char *) malloc (sv.wl_client_count * sizeof (unsigned char));
           int i;
           for (i = 0; i < sv.wl_client_count; i ++) {
              sv.change_grain_to_entity [i] = 0;
              sv.change_grain_to_entity_for_h3 [i] = 0;
           }
        }
        
        //burceam: this field is used for debugging
        sv.num_invocations_collision_detection [0] = 0;
        sv.num_invocations_collision_detection [1] = 0;
        sv.num_invocations_collision_detection [2] = 0;
        sv.num_invocations_collision_detection [3] = 0;
        
        //burceam: create and initialize the list of area node h_meta pointers.
        //this MUST be done after tm_worldmap_init(), where I think the area node tree is created
        //and initialized. We need the depth here.
        {
           int i, num_area_nodes = 1;
           //IMPORTANT: the _actual_ depth of the tree is tdepth+1 !! 
           //root is level "depth", and they keep building until level reaches 0, including for 0!
           //(nodes at level 0 are the leaves). So for depth=8 entered on cmd line, we really have 9 levels.
           num_area_nodes = 1 << (tm_wm.depth + 1);
           sv.hmeta_list = (ptr_t *) malloc (num_area_nodes * sizeof (ptr_t));
           for (i = 0; i < num_area_nodes; i++) 
              sv.hmeta_list [i] = NULL;
        }
*/
	/* initialize synthetic workload */
	server_generate_workload();
	tm_worldmap_is_valid();

	loadb_init( balname );

	/* initialize syncronization & server threads */
	barrier_init( &sv.barrier, sv.num_threads );
	server_stats_init();
	sv.done = 0;

	svts = (server_thread_t*) malloc( sv.num_threads * sizeof(server_thread_t) );
	for( i = 0; i < sv.num_threads; ++i )		server_thread_init( &svts[i], i );

	log_info( "[I] Server init done.\n" );
}