Skip to content

Commit

Permalink
Updating toxcore to 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dvor committed Apr 18, 2018
1 parent 24b8400 commit 67aa70d
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 95 deletions.
2 changes: 1 addition & 1 deletion toxcore-git
Submodule toxcore-git updated 51 files
+2 −2 .travis.yml
+19 −0 CHANGELOG.md
+22 −3 CMakeLists.txt
+0 −5 Makefile.am
+9 −8 auto_tests/TCP_test.c
+2 −1 auto_tests/conference_test.c
+5 −4 auto_tests/crypto_test.c
+45 −29 auto_tests/dht_test.c
+2 −2 auto_tests/file_saving_test.c
+20 −22 auto_tests/messenger_test.c
+51 −21 auto_tests/onion_test.c
+2 −1 auto_tests/save_friend_test.c
+4 −3 auto_tests/simple_conference_test.c
+5 −4 auto_tests/tox_many_tcp_test.c
+3 −2 auto_tests/tox_many_test.c
+3 −2 auto_tests/tox_one_test.c
+2 −2 auto_tests/toxav_many_test.c
+1 −0 cmake/CompileGTest.cmake
+1 −1 configure.ac
+0 −3 dist-build/android-arm.sh
+0 −3 dist-build/android-armv7.sh
+0 −59 dist-build/android-build.sh
+0 −3 dist-build/android-mips.sh
+0 −3 dist-build/android-x86.sh
+2 −2 other/DHT_bootstrap.c
+3 −1 other/bootstrap_daemon/src/config.c
+1 −1 other/bootstrap_daemon/src/tox-bootstrapd.c
+1 −1 other/fun/cracker.c
+2 −2 other/fun/sign.c
+3 −1 other/fun/strkey.c
+1 −1 other/travis/toxcore-linux-install
+2 −2 so.version
+7 −7 testing/DHT_test.c
+2 −2 testing/Messenger_test.c
+3 −1 testing/misc_tools.c
+2 −1 toxav/bwcontroller.c
+2 −1 toxav/rtp.c
+46 −13 toxcore/DHT.c
+4 −22 toxcore/DHT.h
+14 −15 toxcore/Messenger.c
+2 −2 toxcore/ccompat.h
+5 −0 toxcore/crypto_core.api.h
+7 −0 toxcore/crypto_core.c
+5 −0 toxcore/crypto_core.h
+48 −3 toxcore/logger.c
+13 −2 toxcore/logger.h
+7 −0 toxcore/net_crypto.c
+26 −33 toxcore/network.c
+24 −0 toxcore/onion.c
+1 −1 toxcore/tox.api.h
+1 −1 toxcore/tox.h
2 changes: 1 addition & 1 deletion toxcore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "toxcore"
s.version = "0.2.1"
s.version = "0.2.2"
s.summary = "Cocoapods wrapper for toxcore"
s.homepage = "https://github.com/Antidote-for-Tox/toxcore"
s.license = 'GPLv3'
Expand Down
3 changes: 2 additions & 1 deletion toxcore/toxav/bwcontroller.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ void send_update(BWController *bwc)
msg->recv = net_htonl(bwc->cycle.recv);

if (-1 == m_send_custom_lossy_packet(bwc->m, bwc->friend_number, bwc_packet, sizeof(bwc_packet))) {
LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %zu)! std error: %s", sizeof(bwc_packet), strerror(errno));
LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %u)! std error: %s",
(unsigned)sizeof(bwc_packet), strerror(errno));
}
}

Expand Down
3 changes: 2 additions & 1 deletion toxcore/toxav/rtp.m
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length);

if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) {
LOGGER_WARNING(session->m->log, "RTP send failed (len: %zu)! std error: %s", SIZEOF_VLA(rdata), strerror(errno));
LOGGER_WARNING(session->m->log, "RTP send failed (len: %u)! std error: %s",
(unsigned)SIZEOF_VLA(rdata), strerror(errno));
}
} else {
/**
Expand Down
26 changes: 4 additions & 22 deletions toxcore/toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,10 @@ typedef struct {
}
Node_format;

typedef struct {
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
Client_data client_list[MAX_FRIEND_CLIENTS];

/* Time at which the last get_nodes request was sent. */
uint64_t lastgetnode;
/* number of times get_node packets were sent. */
uint32_t bootstrap_times;

/* Symetric NAT hole punching stuff. */
NAT nat;

uint16_t lock_count;
struct {
void (*ip_callback)(void *, int32_t, IP_Port);
void *data;
int32_t number;
} callbacks[DHT_FRIEND_MAX_LOCKS];

Node_format to_bootstrap[MAX_SENT_NODES];
unsigned int num_to_bootstrap;
} DHT_Friend;
typedef struct DHT_Friend DHT_Friend;

const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend);
const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index);

/* Return packet size of packed node with ip_family on success.
* Return -1 on failure.
Expand Down
59 changes: 46 additions & 13 deletions toxcore/toxcore/DHT.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,30 @@
/* Number of get node requests to send to quickly find close nodes. */
#define MAX_BOOTSTRAP_TIMES 5

#define ASSOC_COUNT 2
#define ARRAY_SIZE(ARR) (sizeof (ARR) / sizeof (ARR)[0])

struct DHT_Friend {
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
Client_data client_list[MAX_FRIEND_CLIENTS];

/* Time at which the last get_nodes request was sent. */
uint64_t lastgetnode;
/* number of times get_node packets were sent. */
uint32_t bootstrap_times;

/* Symetric NAT hole punching stuff. */
NAT nat;

uint16_t lock_count;
struct {
void (*ip_callback)(void *, int32_t, IP_Port);
void *data;
int32_t number;
} callbacks[DHT_FRIEND_MAX_LOCKS];

Node_format to_bootstrap[MAX_SENT_NODES];
unsigned int num_to_bootstrap;
};

struct DHT {
Logger *log;
Expand Down Expand Up @@ -94,6 +117,16 @@
unsigned int num_to_bootstrap;
};

const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend)
{
return dht_friend->public_key;
}

const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index)
{
return &dht_friend->client_list[index];
}

const uint8_t *dht_get_self_public_key(const DHT *dht)
{
return dht->self_public_key;
Expand Down Expand Up @@ -1624,9 +1657,9 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
}

const Client_data *const client = &frnd->client_list[client_index];
const IPPTsPng *const assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 };
const IPPTsPng *const assocs[] = { &client->assoc6, &client->assoc4 };

for (size_t i = 0; i < ASSOC_COUNT; i++) {
for (size_t i = 0; i < ARRAY_SIZE(assocs); i++) {
const IPPTsPng *const assoc = assocs[i];

if (!is_timeout(assoc->timestamp, BAD_NODE_TIMEOUT)) {
Expand Down Expand Up @@ -1655,9 +1688,9 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
/* If node is not dead. */
Client_data *client = &list[i];

IPPTsPng *assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 };
IPPTsPng *assocs[] = { &client->assoc6, &client->assoc4 };

for (size_t j = 0; j < ASSOC_COUNT; j++) {
for (size_t j = 0; j < ARRAY_SIZE(assocs); j++) {
IPPTsPng *assoc = assocs[j];

if (!is_timeout(assoc->timestamp, KILL_NODE_TIMEOUT)) {
Expand Down Expand Up @@ -1757,9 +1790,9 @@ static void do_Close(DHT *dht)
for (size_t i = 0; i < LCLIENT_LIST; i++) {
Client_data *const client = &dht->close_clientlist[i];

IPPTsPng *const assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 };
IPPTsPng *const assocs[] = { &client->assoc6, &client->assoc4 };

for (size_t j = 0; j < ASSOC_COUNT; j++) {
for (size_t j = 0; j < ARRAY_SIZE(assocs); j++) {
IPPTsPng *const assoc = assocs[j];

if (assoc->timestamp) {
Expand Down Expand Up @@ -1817,9 +1850,9 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
if (id_equal(public_key, dht->close_clientlist[i].public_key)) {
const Client_data *const client = &dht->close_clientlist[i];
const IPPTsPng *const assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 };
const IPPTsPng *const assocs[] = { &client->assoc6, &client->assoc4 };

for (size_t j = 0; j < ASSOC_COUNT; j++) {
for (size_t j = 0; j < ARRAY_SIZE(assocs); j++) {
const IPPTsPng *const assoc = assocs[j];

if (ip_isset(&assoc->ip_port.ip)) {
Expand Down Expand Up @@ -1942,9 +1975,9 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack
}

const Client_data *const client = &dht_friend->client_list[i];
const IPPTsPng *const assocs[ASSOC_COUNT] = { &client->assoc4, &client->assoc6 };
const IPPTsPng *const assocs[] = { &client->assoc4, &client->assoc6 };

for (size_t j = 0; j < ASSOC_COUNT; j++) {
for (size_t j = 0; j < ARRAY_SIZE(assocs); j++) {
const IPPTsPng *const assoc = assocs[j];

/* If ip is not zero and node is good. */
Expand Down Expand Up @@ -1984,9 +2017,9 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *

for (uint32_t i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
const Client_data *const client = &dht_friend->client_list[i];
const IPPTsPng *const assocs[ASSOC_COUNT] = { &client->assoc4, &client->assoc6 };
const IPPTsPng *const assocs[] = { &client->assoc4, &client->assoc6 };

for (size_t j = 0; j < ASSOC_COUNT; j++) {
for (size_t j = 0; j < ARRAY_SIZE(assocs); j++) {
const IPPTsPng *assoc = assocs[j];

/* If ip is not zero and node is good. */
Expand Down
29 changes: 14 additions & 15 deletions toxcore/toxcore/Messenger.m
Original file line number Diff line number Diff line change
Expand Up @@ -1977,26 +1977,24 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
return nullptr;
}

Logger *log = nullptr;
m->log = logger_new();

if (options->log_callback) {
log = logger_new();

if (log != nullptr) {
logger_callback_log(log, options->log_callback, m, options->log_user_data);
}
if (m->log == nullptr) {
friendreq_kill(m->fr);
free(m);
return nullptr;
}

m->log = log;
logger_callback_log(m->log, options->log_callback, m, options->log_user_data);

unsigned int net_err = 0;

if (options->udp_disabled) {
m->net = new_networking_no_udp(log);
m->net = new_networking_no_udp(m->log);
} else {
IP ip;
ip_init(&ip, options->ipv6enabled);
m->net = new_networking_ex(log, ip, options->port_range[0], options->port_range[1], &net_err);
m->net = new_networking_ex(m->log, ip, options->port_range[0], options->port_range[1], &net_err);
}

if (m->net == nullptr) {
Expand Down Expand Up @@ -2702,15 +2700,16 @@ void do_messenger(Messenger *m, void *userdata)
} else {
char id_str[IDSTRING_LEN];
LOGGER_TRACE(m->log, "F[--:%2u] %s", friend_idx,
id_to_string(dhtfptr->public_key, id_str, sizeof(id_str)));
id_to_string(dht_friend_public_key(dhtfptr), id_str, sizeof(id_str)));
}

for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
Client_data *cptr = &dhtfptr->client_list[client];
IPPTsPng *assoc = nullptr;
uint32_t a;
const Client_data *cptr = dht_friend_client(dhtfptr, client);
const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6};

for (size_t a = 0; a < sizeof(assocs) / sizeof(assocs[0]); a++) {
const IPPTsPng *const assoc = assocs[a];

for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
if (ip_isset(&assoc->ip_port.ip)) {
last_pinged = m->lastdump - assoc->last_pinged;

Expand Down
4 changes: 2 additions & 2 deletions toxcore/toxcore/ccompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#endif

#ifdef __GNUC__
#define GNU_PRINTF __attribute__((__format__(__printf__, 6, 7)))
#define GNU_PRINTF(f, a) __attribute__((__format__(__printf__, f, a)))
#else
#define GNU_PRINTF
#define GNU_PRINTF(f, a)
#endif

#endif /* CCOMPAT_H */
5 changes: 5 additions & 0 deletions toxcore/toxcore/crypto_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length);
*/
int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2);

/**
* Return a random 8 bit integer.
*/
uint8_t random_u08(void);

/**
* Return a random 16 bit integer.
*/
Expand Down
7 changes: 7 additions & 0 deletions toxcore/toxcore/crypto_core.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2)
return crypto_verify_32(pk1, pk2);
}

uint8_t random_u08(void)
{
uint8_t randnum;
randombytes(&randnum, 1);
return randnum;
}

uint16_t random_u16(void)
{
uint16_t randnum;
Expand Down
15 changes: 13 additions & 2 deletions toxcore/toxcore/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ typedef void logger_cb(void *context, LOGGER_LEVEL level, const char *file, int
*/
Logger *logger_new(void);

/**
* Frees all resources associated with the logger.
*/
void logger_kill(Logger *log);

/**
Expand All @@ -59,10 +62,18 @@ void logger_kill(Logger *log);
void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata);

/**
* Main write function. If logging disabled does nothing.
* Main write function. If logging is disabled, this does nothing.
*
* If the logger is NULL, this writes to stderr. This behaviour should not be
* used in production code, but can be useful for temporarily debugging a
* function that does not have a logger available. It's essentially
* fprintf(stderr, ...), but with timestamps and source location. Toxcore must
* be built with -DUSE_STDERR_LOGGER for this to work. It will cause an
* assertion failure otherwise.
*/
void logger_write(
Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format, ...) GNU_PRINTF;
const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func,
const char *format, ...) GNU_PRINTF(6, 7);


#define LOGGER_WRITE(log, level, ...) \
Expand Down
51 changes: 48 additions & 3 deletions toxcore/toxcore/logger.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "logger.h"

#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -38,6 +39,42 @@
void *userdata;
};

#ifdef USE_STDERR_LOGGER
static const char *logger_level_name(LOGGER_LEVEL level)
{
switch (level) {
case LOG_TRACE:
return "TRACE";

case LOG_DEBUG:
return "DEBUG";

case LOG_INFO:
return "INFO";

case LOG_WARNING:
return "WARNING";

case LOG_ERROR:
return "ERROR";
}

return "<unknown>";
}

static void logger_stderr_handler(void *context, LOGGER_LEVEL level, const char *file, int line, const char *func,
const char *message, void *userdata)
{
// GL stands for "global logger".
fprintf(stderr, "[GL] %s %s:%d(%s): %s\n", logger_level_name(level), file, line, func, message);
}

static const Logger logger_stderr = {
logger_stderr_handler,
nullptr,
nullptr,
};
#endif

/**
* Public Functions
Expand All @@ -59,10 +96,18 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
log->userdata = userdata;
}

void logger_write(Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format,
...)
void logger_write(const Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func,
const char *format, ...)
{
if (!log || !log->callback) {
if (!log) {
#ifdef USE_STDERR_LOGGER
log = &logger_stderr;
#else
assert(!"NULL logger not permitted");
#endif
}

if (!log->callback) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions toxcore/toxcore/net_crypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -2755,6 +2755,13 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
*
* return -1 on failure.
* return 0 on success.
*
* Note: The condition `buffer_end - buffer_start < packet_number - buffer_start` is
* a trick which handles situations `buffer_end >= buffer_start` and
* `buffer_end < buffer_start`(when buffer_end overflowed) both correctly
*
* It CANNOT be simplified to `packet_number < buffer_start`, as it will fail
* when `buffer_end < buffer_start`.
*/
int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number)
{
Expand Down
Loading

0 comments on commit 67aa70d

Please sign in to comment.