Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Mark Mono_Time const where possible. #2199

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ static inline IP get_loopback(void)
#endif
return ip;
}
static void do_onion(Onion *onion)
static void do_onion(Mono_Time *mono_time, Onion *onion)
{
mono_time_update(onion->mono_time);
mono_time_update(mono_time);

networking_poll(onion->net, nullptr);
do_dht(onion->dht);
Expand Down Expand Up @@ -229,16 +229,16 @@ static void test_basic(void)
handled_test_1 = 0;

do {
do_onion(onion1);
do_onion(onion2);
do_onion(mono_time1, onion1);
do_onion(mono_time2, onion2);
} while (handled_test_1 == 0);

networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE_OLD, &handle_test_2, onion1);
handled_test_2 = 0;

do {
do_onion(onion1);
do_onion(onion2);
do_onion(mono_time1, onion1);
do_onion(mono_time2, onion2);
} while (handled_test_2 == 0);

Onion_Announce *onion1_a = new_onion_announce(log1, mono_time1, onion1->dht);
Expand All @@ -260,8 +260,8 @@ static void test_basic(void)
handled_test_3 = 0;

do {
do_onion(onion1);
do_onion(onion2);
do_onion(mono_time1, onion1);
do_onion(mono_time2, onion2);
c_sleep(50);
} while (handled_test_3 == 0);

Expand All @@ -278,8 +278,8 @@ static void test_basic(void)
dht_get_self_public_key(onion1->dht), s);

do {
do_onion(onion1);
do_onion(onion2);
do_onion(mono_time1, onion1);
do_onion(mono_time2, onion2);
c_sleep(50);
} while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2),
dht_get_self_public_key(onion1->dht),
Expand All @@ -303,8 +303,8 @@ static void test_basic(void)
handled_test_4 = 0;

do {
do_onion(onion1);
do_onion(onion2);
do_onion(mono_time1, onion1);
do_onion(mono_time2, onion2);
c_sleep(50);
} while (handled_test_4 == 0);

Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *o
onion->callback_object = object;
}

Onion *new_onion(const Logger *log, Mono_Time *mono_time, DHT *dht)
Onion *new_onion(const Logger *log, const Mono_Time *mono_time, DHT *dht)
{
if (dht == nullptr) {
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions toxcore/onion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef int onion_recv_1_cb(void *object, const IP_Port *dest, const uint8_t *da

typedef struct Onion {
const Logger *log;
Mono_Time *mono_time;
const Mono_Time *mono_time;
DHT *dht;
Networking_Core *net;
uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
Expand Down Expand Up @@ -143,7 +143,7 @@ non_null(1) nullable(2, 3)
void set_callback_handle_recv_1(Onion *onion, onion_recv_1_cb *function, void *object);

non_null()
Onion *new_onion(const Logger *log, Mono_Time *mono_time, DHT *dht);
Onion *new_onion(const Logger *log, const Mono_Time *mono_time, DHT *dht);

non_null()
void kill_onion(Onion *onion);
Expand Down
4 changes: 2 additions & 2 deletions toxcore/onion_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct Onion_Announce_Entry {

struct Onion_Announce {
const Logger *log;
Mono_Time *mono_time;
const Mono_Time *mono_time;
DHT *dht;
Networking_Core *net;
Onion_Announce_Entry entries[ONION_ANNOUNCE_MAX_ENTRIES];
Expand Down Expand Up @@ -648,7 +648,7 @@ static int handle_data_request(void *object, const IP_Port *source, const uint8_
return 0;
}

Onion_Announce *new_onion_announce(const Logger *log, Mono_Time *mono_time, DHT *dht)
Onion_Announce *new_onion_announce(const Logger *log, const Mono_Time *mono_time, DHT *dht)
{
if (dht == nullptr) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_announce.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void onion_announce_extra_data_callback(Onion_Announce *onion_a, uint16_t extra_
pack_extra_data_cb *extra_data_callback, void *extra_data_object);

non_null()
Onion_Announce *new_onion_announce(const Logger *log, Mono_Time *mono_time, DHT *dht);
Onion_Announce *new_onion_announce(const Logger *log, const Mono_Time *mono_time, DHT *dht);

non_null()
void kill_onion_announce(Onion_Announce *onion_a);
Expand Down
4 changes: 2 additions & 2 deletions toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ typedef struct Onion_Data_Handler {
} Onion_Data_Handler;

struct Onion_Client {
Mono_Time *mono_time;
const Mono_Time *mono_time;
const Logger *logger;

DHT *dht;
Expand Down Expand Up @@ -1920,7 +1920,7 @@ void do_onion_client(Onion_Client *onion_c)
onion_c->last_run = mono_time_get(onion_c->mono_time);
}

Onion_Client *new_onion_client(const Logger *logger, Mono_Time *mono_time, Net_Crypto *c)
Onion_Client *new_onion_client(const Logger *logger, const Mono_Time *mono_time, Net_Crypto *c)
{
if (c == nullptr) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ non_null()
void do_onion_client(Onion_Client *onion_c);

non_null()
Onion_Client *new_onion_client(const Logger *logger, Mono_Time *mono_time, Net_Crypto *c);
Onion_Client *new_onion_client(const Logger *logger, const Mono_Time *mono_time, Net_Crypto *c);

non_null()
void kill_onion_client(Onion_Client *onion_c);
Expand Down