Skip to content
Open
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
1 change: 1 addition & 0 deletions other/analysis/run-cppcheck
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CPPCHECK+=("--error-exitcode=1")
CPPCHECK+=("--suppress=unmatchedSuppression")
# We don't cast function pointers, which cppcheck suggests here.
CPPCHECK+=("--suppress=constParameterCallback")
CPPCHECK+=("--suppress=constParameterPointer")
# This disagrees with clang's warnings.
CPPCHECK+=("--suppress=invalidPrintfArgType_uint")
# False positives in switch statements.
Expand Down
4 changes: 4 additions & 0 deletions other/docker/misra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ SUPPRESSIONS += 10.8
#
# Reason: this is needed for generic callbacks to make any sense.
SUPPRESSIONS += 11.5
# A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer.
#
# Reason: we need to cast from _Nullable to _Nonnull.
SUPPRESSIONS += 11.8
# The precedence of operators within expressions should be made explicit.
#
# Reason: this asks us to add a lot of extra parentheses that don't really help
Expand Down
2 changes: 1 addition & 1 deletion other/event_tooling/generate_event_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
// free
f << "void tox_event_" << event_name_l << "_free(Tox_Event_" << event_name << " *" << event_name_l << ", const Memory *mem)\n{\n";
f << " if (" << event_name_l << " != nullptr) {\n";
f << " tox_event_" << event_name_l << "_destruct(" << event_name_l << ", mem);\n }\n";
f << " tox_event_" << event_name_l << "_destruct((Tox_Event_" << event_name << " * _Nonnull)" << event_name_l << ", mem);\n }\n";
f << " mem_delete(mem, " << event_name_l << ");\n}\n\n";

// add
Expand Down
4 changes: 2 additions & 2 deletions testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ int main(int argc, char *argv[])
Messenger_Options options = {0};
options.ipv6enabled = ipv6enabled;
Messenger_Error err;
m = new_messenger(mono_time, mem, os_random(), os_network(), &options, &err);
m = new_messenger(mono_time, mem, (const Random * _Nonnull)os_random(), (const Network * _Nonnull)os_network(), &options, &err);

if (!m) {
fprintf(stderr, "Failed to allocate messenger datastructure: %d\n", err);
fprintf(stderr, "Failed to allocate messenger datastructure: %u\n", err);
exit(0);
}

Expand Down
2 changes: 1 addition & 1 deletion testing/fuzzing/protodump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void RecordBootstrap(const char *init, const char *bootstrap)
[](Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
const char *message, void *user_data) {
// Log to stdout.
std::printf("[%s] %c %s:%d(%s): %s\n", static_cast<Record_System *>(user_data)->name_,
std::printf("[%s] %c %s:%u(%s): %s\n", static_cast<Record_System *>(user_data)->name_,
tox_log_level_name(level), file, line, func, message);
});

Expand Down
2 changes: 1 addition & 1 deletion testing/fuzzing/protodump_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void TestEndToEnd(Fuzz_Data &input)
const char *message, void *user_data) {
// Log to stdout.
if (PROTODUMP_DEBUG) {
std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line,
std::printf("[tox1] %c %s:%u(%s): %s\n", tox_log_level_name(level), file, line,
func, message);
}
});
Expand Down
6 changes: 3 additions & 3 deletions toxav/rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ struct RTPHeader {
uint64_t flags;

/**
* The full 32 bit data offset of the current data chunk. The @ref
* offset_lower data member contains the lower 16 bits of this value. For
* frames smaller than 64KiB, @ref offset_full and @ref offset_lower are
* The full 32 bit data offset of the current data chunk. The
* @ref offset_lower data member contains the lower 16 bits of this value.
* For frames smaller than 64KiB, @ref offset_full and @ref offset_lower are
* equal.
*/
uint32_t offset_full;
Expand Down
71 changes: 43 additions & 28 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
#define KEYS_TIMEOUT 600

typedef struct DHT_Friend_Callback {
dht_ip_cb *ip_callback;
void *data;
dht_ip_cb *_Nullable ip_callback;
void *_Nullable data;
int32_t number;
} DHT_Friend_Callback;

Expand Down Expand Up @@ -88,17 +88,17 @@ const Node_format empty_node_format = {{0}};
static_assert(sizeof(empty_dht_friend.lock_flags) * 8 == DHT_FRIEND_MAX_LOCKS, "Bitfield size and number of locks don't match");

typedef struct Cryptopacket_Handler {
cryptopacket_handler_cb *function;
void *object;
cryptopacket_handler_cb *_Nullable function;
void *_Nullable object;
} Cryptopacket_Handler;

struct DHT {
const Logger *log;
const Network *ns;
Mono_Time *mono_time;
const Memory *mem;
const Random *rng;
Networking_Core *net;
const Logger *_Nonnull log;
const Network *_Nonnull ns;
Mono_Time *_Nonnull mono_time;
const Memory *_Nonnull mem;
const Random *_Nonnull rng;
Networking_Core *_Nonnull net;

bool hole_punching_enabled;
bool lan_discovery_enabled;
Expand All @@ -111,26 +111,26 @@ struct DHT {
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];

DHT_Friend *friends_list;
DHT_Friend *_Nullable friends_list;
uint16_t num_friends;

Node_format *loaded_nodes_list;
Node_format *_Nullable loaded_nodes_list;
uint32_t loaded_num_nodes;
unsigned int loaded_nodes_index;

Shared_Key_Cache *shared_keys_recv;
Shared_Key_Cache *shared_keys_sent;
Shared_Key_Cache *_Nonnull shared_keys_recv;
Shared_Key_Cache *_Nonnull shared_keys_sent;

struct Ping *ping;
Ping_Array *dht_ping_array;
struct Ping *_Nonnull ping;
Ping_Array *_Nonnull dht_ping_array;
uint64_t cur_time;

Cryptopacket_Handler cryptopackethandlers[256];

Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES];
unsigned int num_to_bootstrap;

dht_nodes_response_cb *nodes_response_callback;
dht_nodes_response_cb *_Nullable nodes_response_callback;
};

const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend)
Expand Down Expand Up @@ -734,7 +734,7 @@ int get_close_nodes(
return get_somewhat_close_nodes(
dht->cur_time, public_key, nodes_list,
sa_family, dht->close_clientlist,
dht->friends_list, dht->num_friends,
(const DHT_Friend * _Nonnull)dht->friends_list, dht->num_friends,
is_lan, want_announce);
}

Expand Down Expand Up @@ -849,9 +849,9 @@ static bool store_node_ok(const Client_data *_Nonnull client, uint64_t cur_time,
}

typedef struct Client_data_Cmp {
const Memory *mem;
const Memory *_Nonnull mem;
uint64_t cur_time;
const uint8_t *comp_public_key;
const uint8_t *_Nonnull comp_public_key;
} Client_data_Cmp;

static int client_data_cmp(const Client_data_Cmp *_Nonnull cmp, const Client_data *_Nonnull entry1, const Client_data *_Nonnull entry2)
Expand Down Expand Up @@ -2509,14 +2509,16 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
dht->hole_punching_enabled = hole_punching_enabled;
dht->lan_discovery_enabled = lan_discovery_enabled;

dht->ping = ping_new(mem, mono_time, rng, dht);
struct Ping *temp_ping = ping_new(mem, mono_time, rng, dht);

if (dht->ping == nullptr) {
if (temp_ping == nullptr) {
LOGGER_ERROR(log, "failed to initialise ping");
kill_dht(dht);
return nullptr;
}

dht->ping = temp_ping;

networking_registerhandler(dht->net, NET_PACKET_NODES_REQUEST, &handle_nodes_request, dht);
networking_registerhandler(dht->net, NET_PACKET_NODES_RESPONSE, &handle_nodes_response, dht);
networking_registerhandler(dht->net, NET_PACKET_CRYPTO, &cryptopacket_handle, dht);
Expand All @@ -2529,23 +2531,36 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw

crypto_new_keypair(rng, dht->self_public_key, dht->self_secret_key);

dht->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
dht->shared_keys_sent = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
Shared_Key_Cache *const temp_shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);

if (temp_shared_keys_recv == nullptr) {
LOGGER_ERROR(log, "failed to initialise shared key cache");
kill_dht(dht);
return nullptr;
}

dht->shared_keys_recv = temp_shared_keys_recv;

Shared_Key_Cache *const temp_shared_keys_sent = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);

if (dht->shared_keys_recv == nullptr || dht->shared_keys_sent == nullptr) {
if (temp_shared_keys_sent == nullptr) {
LOGGER_ERROR(log, "failed to initialise shared key cache");
kill_dht(dht);
return nullptr;
}

dht->dht_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
dht->shared_keys_sent = temp_shared_keys_sent;

if (dht->dht_ping_array == nullptr) {
Ping_Array *const temp_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);

if (temp_ping_array == nullptr) {
LOGGER_ERROR(log, "failed to initialise ping array");
kill_dht(dht);
return nullptr;
}

dht->dht_ping_array = temp_ping_array;

for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE];
Expand Down Expand Up @@ -2600,7 +2615,7 @@ void kill_dht(DHT *dht)
networking_registerhandler(dht->net, NET_PACKET_NODES_RESPONSE, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_CRYPTO, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, nullptr, nullptr);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, nullptr, nullptr);
cryptopacket_registerhandler((DHT * _Nonnull)dht, CRYPTO_PACKET_NAT_PING, nullptr, nullptr);

shared_key_cache_free(dht->shared_keys_recv);
shared_key_cache_free(dht->shared_keys_sent);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int unpack_nodes(Node_format *_Nonnull nodes, uint16_t max_num_nodes, uint16_t *
uint16_t length, bool tcp_enabled);
/*----------------------------------------------------------------------------------*/

typedef int cryptopacket_handler_cb(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey,
typedef int cryptopacket_handler_cb(void *_Nullable object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey,
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);

typedef struct DHT DHT;
Expand Down
Loading
Loading