Esempio n. 1
0
File: DHT.c Progetto: nypox/nctox
//Ping each client in the close nodes list every 60 seconds.
//Send a get nodes request every 20 seconds to a random good node in the list.
void doClose()//tested
{
    uint32_t i;
    uint32_t temp_time = unix_time();
    uint32_t num_nodes = 0;
    uint32_t rand_node;
    uint32_t index[LCLIENT_LIST];
    
    for(i = 0; i < LCLIENT_LIST; i++)
    {
        if(close_clientlist[i].timestamp + Kill_NODE_TIMEOUT > temp_time)//if node is not dead.
        {
            //TODO: Make this better, it only works if the function is called more than once per second.
            if((temp_time - close_clientlist[i].timestamp) % PING_INTERVAL == 0)
            {
                pingreq(close_clientlist[i].ip_port);
            }
            if(close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time)//if node is good.
            {
                index[num_nodes] = i;
                num_nodes++;
            }
        }   
    }
    
    if(close_lastgetnodes + GET_NODE_INTERVAL <= temp_time && num_nodes != 0)
    {
        rand_node = rand() % num_nodes;
        getnodes(close_clientlist[index[rand_node]].ip_port, 
        close_clientlist[index[rand_node]].client_id);
        close_lastgetnodes = temp_time;
    }
    
}
Esempio n. 2
0
File: DHT.c Progetto: nypox/nctox
void doFriends()
{
    uint32_t i, j;
    uint32_t temp_time = unix_time();
    uint32_t num_nodes = 0;
    uint32_t rand_node;
    uint32_t index[MAX_FRIEND_CLIENTS];
    
    for(i = 0; i < num_friends; i++)
    {
        for(j = 0; j < MAX_FRIEND_CLIENTS; j++)
        {
            if(friends_list[i].client_list[j].timestamp + Kill_NODE_TIMEOUT > temp_time)//if node is not dead.
            {
                //TODO: Make this better, it only works if the function is called more than once per second.
                if((temp_time - friends_list[i].client_list[j].timestamp) % PING_INTERVAL == 0)
                {
                    pingreq(friends_list[i].client_list[j].ip_port);
                }
                if(friends_list[i].client_list[j].timestamp + BAD_NODE_TIMEOUT > temp_time)//if node is good.
                {
                    index[num_nodes] = j;
                    num_nodes++;
                }
            }
        }
        if(friend_lastgetnode[i] + GET_NODE_INTERVAL <= temp_time && num_nodes != 0)
        {
            rand_node = rand() % num_nodes;
            getnodes(friends_list[i].client_list[index[rand_node]].ip_port, 
            friends_list[i].client_list[index[rand_node]].client_id);
            friend_lastgetnode[i] = temp_time;
        }
    }
}
Esempio n. 3
0
//Ping each client in the close nodes list every 60 seconds.
//Send a get nodes request every 20 seconds to a random good node in the list.
void doClose()//tested
{
    uint32_t i;
    uint32_t temp_time = unix_time();
    uint32_t num_nodes = 0;
    uint32_t rand_node;
    uint32_t index[LCLIENT_LIST];
    
    for(i = 0; i < LCLIENT_LIST; i++)
    {
        if(close_clientlist[i].timestamp + Kill_NODE_TIMEOUT > temp_time)//if node is not dead.
        {
            if((close_clientlist[i].last_pinged + PING_INTERVAL) <= temp_time)
            {
                pingreq(close_clientlist[i].ip_port, close_clientlist[i].client_id);
                close_clientlist[i].last_pinged = temp_time;
            }
            if(close_clientlist[i].timestamp + BAD_NODE_TIMEOUT > temp_time)//if node is good.
            {
                index[num_nodes] = i;
                num_nodes++;
            }
        }   
    }
    
    if(close_lastgetnodes + GET_NODE_INTERVAL <= temp_time && num_nodes != 0)
    {
        rand_node = rand() % num_nodes;
        getnodes(close_clientlist[index[rand_node]].ip_port, 
                 close_clientlist[index[rand_node]].client_id, 
                 self_public_key);
        close_lastgetnodes = temp_time;
    }
    
}
Esempio n. 4
0
void doDHTFriends()
{
    uint32_t i, j;
    uint32_t temp_time = unix_time();
    uint32_t num_nodes = 0;
    uint32_t rand_node;
    uint32_t index[MAX_FRIEND_CLIENTS];
    
    for(i = 0; i < num_friends; i++)
    {
        for(j = 0; j < MAX_FRIEND_CLIENTS; j++)
        {
            if(friends_list[i].client_list[j].timestamp + Kill_NODE_TIMEOUT > temp_time)//if node is not dead.
            {
                if((friends_list[i].client_list[j].last_pinged + PING_INTERVAL) <= temp_time)
                {
                    pingreq(friends_list[i].client_list[j].ip_port, friends_list[i].client_list[j].client_id);
                    friends_list[i].client_list[j].last_pinged = temp_time;
                }
                if(friends_list[i].client_list[j].timestamp + BAD_NODE_TIMEOUT > temp_time)//if node is good.
                {
                    index[num_nodes] = j;
                    num_nodes++;
                }
            }
        }
        if(friends_list[i].lastgetnode + GET_NODE_INTERVAL <= temp_time && num_nodes != 0)
        {
            rand_node = rand() % num_nodes;
            getnodes(friends_list[i].client_list[index[rand_node]].ip_port, 
                     friends_list[i].client_list[index[rand_node]].client_id, 
                     friends_list[i].client_id);
            friends_list[i].lastgetnode = temp_time;
        }
    }
}
Esempio n. 5
0
File: DHT.c Progetto: nypox/nctox
uint8_t bootstrap(IP_Port ip_port)
{
    return getnodes(ip_port, self_client_id) > 0;
}
Esempio n. 6
0
void DHT_bootstrap(IP_Port ip_port, uint8_t * public_key)
{

    getnodes(ip_port, public_key, self_public_key);
    
}