Exemple #1
0
//! @brief rpc server core function
//! @param *p The argument received from the client
//! @return The result of the argument process
char* register_on_server(request_t *p)
{
    static response_t response;	// A structure that handle the response

    if(strlen(p->name) <= MAX_NAME_SIZE && p->port > 0 && p-> port < 65535)
    {   /* We received a valid connection attempt */
        if(nb_clients < MAX_CLIENTS)
        {   /* We can handle more clients */
            printf("Received advertisement from client \"%s\" at port %d.\n", p->name, p->port);
            /* Storing information received from client */
            strcpy(clients[nb_clients].name, p->name);
            clients[nb_clients].port = p->port;
            /* compiling result */
            response.nb_clients = ++nb_clients;
            response.port = p->port;
            /* was it the last client we were waiting for? */
            if(nb_clients == MAX_CLIENTS)
                advertise_all();
        }
        else
        {   /* We can't handle any more client */
            fprintf(stderr, "Cannot handle any more client : \"%s\" at port %d.\n", p->name, p->port);
            response.nb_clients = 0;
            response.port = 100;
        }
    }
    else
    {   /* We received an invalid connection attempt */
        fprintf(stderr, "Invalid arguments received from client \"%s\" at port %d.\n", p->name, p->port);
        response.nb_clients = 0;
        response.port = 200;
    }

    return ((char*)&response);
}
Exemple #2
0
static void communities_discovery(n2n_sn_t *sss, time_t nowTime)
{
    if (nowTime - sss->start_time < N2N_SUPER_DISCOVERY_INTERVAL)
    {
        return;
    }

    if (sss->snm_discovery_state == N2N_SNM_STATE_DISCOVERY)
    {
        struct comm_info *tmp_list = sss->communities.list_head;   /* queried communities */
        int comm_num = comm_list_size(sss->communities.persist);

        /* add new communities */
        struct comm_info *p = tmp_list;

        sss->communities.list_head = sss->communities.persist;

        while (comm_num < N2N_MAX_COMM_PER_SN && p != NULL)
        {
            if (p->sn_num < N2N_MIN_SN_PER_COMM)
            {
                /* add new community without setting supernodes */
                if (add_new_community(&sss->communities, p->community_name, NULL))
                    comm_num++;
            }

            p = p->next;
        }
        clear_comm_list(&tmp_list);

        /* send ADV to all */
        advertise_all(sss);

        sss->snm_discovery_state = N2N_SNM_STATE_READY;
    }
}