mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Code cleanups.
No functionality changed.
This commit is contained in:
parent
e05120f74e
commit
24974ef816
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user