blob: 1728ea21fca210511c8eab184cc90cb86a10fe98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*
* util.c -- Utilities.
*
* This file is donated to the Tox Project.
* Copyright 2013 plutooo
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <time.h>
#include <stdint.h>
#include <stdbool.h>
#include "DHT.h"
uint64_t now()
{
return time(NULL);
}
uint64_t random_64b()
{
uint64_t r;
// This is probably not random enough?
r = random_int();
r <<= 32;
r |= random_int();
return r;
}
bool ipp_eq(IP_Port a, IP_Port b)
{
return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
}
bool id_eq(uint8_t *dest, uint8_t *src)
{
return memcmp(dest, src, CLIENT_ID_SIZE) == 0;
}
void id_cpy(uint8_t *dest, uint8_t *src)
{
memcpy(dest, src, CLIENT_ID_SIZE);
}
|