Beispiel #1
0
//send a getnodes request
static int getnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id)
{
    if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0)//check if packet is gonna be sent to ourself
    {
        return 1;
    }
    
    if(is_gettingnodes(ip_port, 0))
    {
        return 1;
    }
    
    uint64_t ping_id = add_gettingnodes(ip_port);
    
    if(ping_id == 0)
    {
        return 1;
    }
    
    uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING];
    uint8_t plain[sizeof(ping_id) + CLIENT_ID_SIZE];
    uint8_t encrypt[sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING];
    uint8_t nonce[crypto_box_NONCEBYTES];
    random_nonce(nonce);
    
    memcpy(plain, &ping_id, sizeof(ping_id));
    memcpy(plain + sizeof(ping_id), client_id, CLIENT_ID_SIZE);
    
    int len = encrypt_data(public_key, self_secret_key, nonce, plain, sizeof(ping_id) + CLIENT_ID_SIZE, encrypt);
    
    if(len != sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING)
    {
        return -1;
    }
    data[0] = 2;
    memcpy(data + 1, self_public_key, CLIENT_ID_SIZE);
    memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
    memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
    return sendpacket(ip_port, data, sizeof(data));
    
}
Beispiel #2
0
Datei: DHT.c Projekt: nypox/nctox
//send a getnodes request
unsigned int getnodes(IP_Port ip_port, char * client_id)
{
    if(is_gettingnodes(ip_port, 0))
    {
        return 0;
    }
    
    int ping_id = add_gettingnodes(ip_port);
    
    if(ping_id == 0)
    {
        return 0;
    }
    
    char data[5 + CLIENT_ID_SIZE*2];
    data[0] = 2;
    
    memcpy(data + 1, &ping_id, 4);
    memcpy(data + 5, self_client_id, CLIENT_ID_SIZE);
    memcpy(data + 5 + CLIENT_ID_SIZE, client_id, CLIENT_ID_SIZE);

    return sendpacket(ip_port, data, sizeof(data));
}