Code cleanups.

No functionality changed.
This commit is contained in:
irungentoo 2013-12-15 18:57:10 -05:00
parent e05120f74e
commit 24974ef816
6 changed files with 11 additions and 21 deletions

View File

@ -1177,7 +1177,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id)
memset(&dht->friends_list[dht->num_friends], 0, sizeof(DHT_Friend));
memcpy(dht->friends_list[dht->num_friends].client_id, client_id, CLIENT_ID_SIZE);
dht->friends_list[dht->num_friends].nat.NATping_id = ((uint64_t)random_int() << 32) + random_int();
dht->friends_list[dht->num_friends].nat.NATping_id = random_64b();
++dht->num_friends;
if (dht->assoc) {
@ -1689,7 +1689,7 @@ static int handle_NATping(void *object, IP_Port source, uint8_t *source_pubkey,
return 0;
} else if (packet[0] == NAT_PING_RESPONSE) {
if (friend->nat.NATping_id == ping_id) {
friend->nat.NATping_id = ((uint64_t)random_int() << 32) + random_int();
friend->nat.NATping_id = random_64b();
friend->nat.hole_punching = 1;
return 0;
}

View File

@ -323,7 +323,7 @@ static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
return -1;
getnodes_data contents;
contents.pingid = ((uint64_t)random_int() << 32) + random_int();
contents.pingid = random_64b();
chat->group[peernum].last_pinged = unix_time();
chat->group[peernum].pingid = contents.pingid;

View File

@ -133,14 +133,16 @@ uint64_t current_time(void)
*/
uint32_t random_int(void)
{
#ifndef VANILLA_NACL
/* NOTE: this function comes from libsodium. */
return randombytes_random();
#else
uint32_t randnum;
randombytes((uint8_t *)&randnum , sizeof(randnum));
return randnum;
#endif
}
uint64_t random_64b(void)
{
uint64_t randnum;
randombytes((uint8_t *)&randnum, sizeof(randnum));
return randnum;
}
#ifdef LOGGING

View File

@ -253,6 +253,7 @@ uint64_t current_time(void);
/* return a random number.
*/
uint32_t random_int(void);
uint64_t random_64b(void);
/* Basic network functions: */

View File

@ -33,17 +33,6 @@
#include "util.h"
uint64_t random_64b()
{
uint64_t r;
/* This is probably not random enough? */
r = random_int();
r <<= 32;
r |= random_int();
return r;
}
/* don't call into system billions of times for no reason */
static uint64_t unix_time_value;

View File

@ -28,8 +28,6 @@
#include <stdbool.h>
#include <stdint.h>
uint64_t random_64b();
void unix_time_update();
uint64_t unix_time();
int is_timeout(uint64_t timestamp, uint64_t timeout);