mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Add logger to onion and onion announce objects
This will be used in the future
This commit is contained in:
parent
51a2acd1f5
commit
edf9d66717
|
@ -179,8 +179,8 @@ static void test_basic(void)
|
||||||
Mono_Time *mono_time2 = mono_time_new();
|
Mono_Time *mono_time2 = mono_time_new();
|
||||||
|
|
||||||
IP ip = get_loopback();
|
IP ip = get_loopback();
|
||||||
Onion *onion1 = new_onion(mono_time1, new_dht(log1, mono_time1, new_networking(log1, ip, 36567), true));
|
Onion *onion1 = new_onion(log1, mono_time1, new_dht(log1, mono_time1, new_networking(log1, ip, 36567), true));
|
||||||
Onion *onion2 = new_onion(mono_time2, new_dht(log2, mono_time2, new_networking(log2, ip, 36568), true));
|
Onion *onion2 = new_onion(log2, mono_time2, new_dht(log2, mono_time2, new_networking(log2, ip, 36568), true));
|
||||||
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
|
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
|
||||||
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
|
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
|
||||||
|
|
||||||
|
@ -224,8 +224,8 @@ static void test_basic(void)
|
||||||
do_onion(onion2);
|
do_onion(onion2);
|
||||||
} while (handled_test_2 == 0);
|
} while (handled_test_2 == 0);
|
||||||
|
|
||||||
Onion_Announce *onion1_a = new_onion_announce(mono_time1, onion1->dht);
|
Onion_Announce *onion1_a = new_onion_announce(log1, mono_time1, onion1->dht);
|
||||||
Onion_Announce *onion2_a = new_onion_announce(mono_time2, onion2->dht);
|
Onion_Announce *onion2_a = new_onion_announce(log2, mono_time2, onion2->dht);
|
||||||
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
|
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
|
||||||
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
|
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
|
||||||
uint8_t zeroes[64] = {0};
|
uint8_t zeroes[64] = {0};
|
||||||
|
@ -274,7 +274,7 @@ static void test_basic(void)
|
||||||
|
|
||||||
Mono_Time *mono_time3 = mono_time_new();
|
Mono_Time *mono_time3 = mono_time_new();
|
||||||
|
|
||||||
Onion *onion3 = new_onion(mono_time3, new_dht(log3, mono_time3, new_networking(log3, ip, 36569), true));
|
Onion *onion3 = new_onion(log3, mono_time3, new_dht(log3, mono_time3, new_networking(log3, ip, 36569), true));
|
||||||
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
|
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
|
||||||
|
|
||||||
random_nonce(nonce);
|
random_nonce(nonce);
|
||||||
|
@ -385,7 +385,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
on->onion = new_onion(on->mono_time, dht);
|
on->onion = new_onion(on->log, on->mono_time, dht);
|
||||||
|
|
||||||
if (!on->onion) {
|
if (!on->onion) {
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
|
@ -396,7 +396,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
on->onion_a = new_onion_announce(on->mono_time, dht);
|
on->onion_a = new_onion_announce(on->log, on->mono_time, dht);
|
||||||
|
|
||||||
if (!on->onion_a) {
|
if (!on->onion_a) {
|
||||||
kill_onion(on->onion);
|
kill_onion(on->onion);
|
||||||
|
|
|
@ -142,8 +142,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
Mono_Time *mono_time = mono_time_new();
|
Mono_Time *mono_time = mono_time_new();
|
||||||
DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true);
|
DHT *dht = new_dht(logger, mono_time, new_networking(logger, ip, PORT), true);
|
||||||
Onion *onion = new_onion(mono_time, dht);
|
Onion *onion = new_onion(logger, mono_time, dht);
|
||||||
Onion_Announce *onion_a = new_onion_announce(mono_time, dht);
|
Onion_Announce *onion_a = new_onion_announce(logger, mono_time, dht);
|
||||||
|
|
||||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||||
bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD));
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
|
|
||||||
|
@ -240,7 +241,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
|
||||||
size_t tmp_motd_length = strlen(tmp_motd) + 1;
|
size_t tmp_motd_length = strlen(tmp_motd) + 1;
|
||||||
size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
|
size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
|
||||||
*motd = (char *)malloc(motd_length);
|
*motd = (char *)malloc(motd_length);
|
||||||
strncpy(*motd, tmp_motd, motd_length);
|
snprintf(*motd, motd_length, "%s", tmp_motd);
|
||||||
(*motd)[motd_length - 1] = '\0';
|
(*motd)[motd_length - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ static void handle_signal(int signum)
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
umask(077);
|
umask(077);
|
||||||
char *cfg_file_path;
|
char *cfg_file_path = nullptr;
|
||||||
LOG_BACKEND log_backend;
|
LOG_BACKEND log_backend;
|
||||||
bool run_in_foreground;
|
bool run_in_foreground;
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Onion *onion = new_onion(mono_time, dht);
|
Onion *onion = new_onion(logger, mono_time, dht);
|
||||||
|
|
||||||
if (!onion) {
|
if (!onion) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
|
||||||
|
@ -341,7 +341,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Onion_Announce *onion_a = new_onion_announce(mono_time, dht);
|
Onion_Announce *onion_a = new_onion_announce(logger, mono_time, dht);
|
||||||
|
|
||||||
if (!onion_a) {
|
if (!onion_a) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n");
|
||||||
|
|
|
@ -1959,8 +1959,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m->onion = new_onion(m->mono_time, m->dht);
|
m->onion = new_onion(m->log, m->mono_time, m->dht);
|
||||||
m->onion_a = new_onion_announce(m->mono_time, m->dht);
|
m->onion_a = new_onion_announce(m->log, m->mono_time, m->dht);
|
||||||
m->onion_c = new_onion_client(m->log, m->mono_time, m->net_crypto);
|
m->onion_c = new_onion_client(m->log, m->mono_time, m->net_crypto);
|
||||||
m->fr_c = new_friend_connections(m->log, m->mono_time, m->onion_c, options->local_discovery_enabled);
|
m->fr_c = new_friend_connections(m->log, m->mono_time, m->onion_c, options->local_discovery_enabled);
|
||||||
|
|
||||||
|
|
|
@ -650,7 +650,7 @@ void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *o
|
||||||
onion->callback_object = object;
|
onion->callback_object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
Onion *new_onion(Mono_Time *mono_time, DHT *dht)
|
Onion *new_onion(const Logger *log, Mono_Time *mono_time, DHT *dht)
|
||||||
{
|
{
|
||||||
if (dht == nullptr) {
|
if (dht == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -662,6 +662,7 @@ Onion *new_onion(Mono_Time *mono_time, DHT *dht)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onion->log = log;
|
||||||
onion->dht = dht;
|
onion->dht = dht;
|
||||||
onion->net = dht_get_net(dht);
|
onion->net = dht_get_net(dht);
|
||||||
onion->mono_time = mono_time;
|
onion->mono_time = mono_time;
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
#define C_TOXCORE_TOXCORE_ONION_H
|
#define C_TOXCORE_TOXCORE_ONION_H
|
||||||
|
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
#include "logger.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
|
||||||
typedef int onion_recv_1_cb(void *object, IP_Port dest, const uint8_t *data, uint16_t length);
|
typedef int onion_recv_1_cb(void *object, IP_Port dest, const uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
typedef struct Onion {
|
typedef struct Onion {
|
||||||
|
const Logger *log;
|
||||||
Mono_Time *mono_time;
|
Mono_Time *mono_time;
|
||||||
DHT *dht;
|
DHT *dht;
|
||||||
Networking_Core *net;
|
Networking_Core *net;
|
||||||
|
@ -143,7 +145,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
|
||||||
*/
|
*/
|
||||||
void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *object);
|
void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *object);
|
||||||
|
|
||||||
Onion *new_onion(Mono_Time *mono_time, DHT *dht);
|
Onion *new_onion(const Logger *log, Mono_Time *mono_time, DHT *dht);
|
||||||
|
|
||||||
void kill_onion(Onion *onion);
|
void kill_onion(Onion *onion);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef struct Onion_Announce_Entry {
|
||||||
} Onion_Announce_Entry;
|
} Onion_Announce_Entry;
|
||||||
|
|
||||||
struct Onion_Announce {
|
struct Onion_Announce {
|
||||||
|
const Logger *log;
|
||||||
Mono_Time *mono_time;
|
Mono_Time *mono_time;
|
||||||
DHT *dht;
|
DHT *dht;
|
||||||
Networking_Core *net;
|
Networking_Core *net;
|
||||||
|
@ -485,7 +486,7 @@ static int handle_data_request(void *object, IP_Port source, const uint8_t *pack
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Onion_Announce *new_onion_announce(Mono_Time *mono_time, DHT *dht)
|
Onion_Announce *new_onion_announce(const Logger *log, Mono_Time *mono_time, DHT *dht)
|
||||||
{
|
{
|
||||||
if (dht == nullptr) {
|
if (dht == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -497,6 +498,7 @@ Onion_Announce *new_onion_announce(Mono_Time *mono_time, DHT *dht)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onion_a->log = log;
|
||||||
onion_a->mono_time = mono_time;
|
onion_a->mono_time = mono_time;
|
||||||
onion_a->dht = dht;
|
onion_a->dht = dht;
|
||||||
onion_a->net = dht_get_net(dht);
|
onion_a->net = dht_get_net(dht);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H
|
#ifndef C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H
|
||||||
#define C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H
|
#define C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
#include "onion.h"
|
#include "onion.h"
|
||||||
|
|
||||||
#define ONION_ANNOUNCE_MAX_ENTRIES 160
|
#define ONION_ANNOUNCE_MAX_ENTRIES 160
|
||||||
|
@ -105,7 +106,7 @@ int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest
|
||||||
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length);
|
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
|
|
||||||
Onion_Announce *new_onion_announce(Mono_Time *mono_time, DHT *dht);
|
Onion_Announce *new_onion_announce(const Logger *log, Mono_Time *mono_time, DHT *dht);
|
||||||
|
|
||||||
void kill_onion_announce(Onion_Announce *onion_a);
|
void kill_onion_announce(Onion_Announce *onion_a);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user