Skip to content

Conversation

iphydf
Copy link
Member

@iphydf iphydf commented Feb 5, 2025

Instead of transitively loading them from dependencies, we should be explicit about what each object needs. The downside of this is that it's not clear whether the object and its dependency use the same common dependency. The upside is that we don't expose those getters of internal dependencies.


This change is Reviewable

@iphydf iphydf added this to the v0.2.22 milestone Feb 5, 2025
@github-actions github-actions bot added the refactor Refactoring production code, eg. renaming a variable, not affecting semantics label Feb 5, 2025
@iphydf iphydf force-pushed the getters branch 5 times, most recently from 45d8e7d to e0f5168 Compare February 8, 2025 11:48
@iphydf iphydf marked this pull request as ready for review February 8, 2025 11:58
@Green-Sky Green-Sky modified the milestones: v0.2.22, v0.2.23 Oct 1, 2025
@iphydf iphydf modified the milestones: v0.2.23, v0.2.22 Oct 5, 2025
@iphydf iphydf force-pushed the getters branch 2 times, most recently from ce14a79 to 1a89f24 Compare October 5, 2025 20:04
@Green-Sky
Copy link
Member

Green-Sky commented Oct 19, 2025

@iphydf needs restyled:

diff --git a/toxcore/announce.h b/toxcore/announce.h
index f263584..2c1183c 100644
--- a/toxcore/announce.h
+++ b/toxcore/announce.h
@@ -24,7 +24,8 @@ uint8_t announce_response_of_request_type(uint8_t request_type);
 
 typedef struct Announcements Announcements;
 
-Announcements *_Nullable new_announcements(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Forwarding *_Nonnull forwarding, DHT *_Nonnull dht, Networking_Core *_Nonnull net);
+Announcements *_Nullable new_announcements(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Forwarding *_Nonnull forwarding,
+        DHT *_Nonnull dht, Networking_Core *_Nonnull net);
 
 /**
  * @brief If data is stored, run `on_retrieve_callback` on it.
diff --git a/toxcore/forwarding.c b/toxcore/forwarding.c
index 776d2de..5b29c8e 100644
--- a/toxcore/forwarding.c
+++ b/toxcore/forwarding.c
@@ -344,7 +344,7 @@ void set_callback_forward_reply(Forwarding *forwarding, forward_reply_cb *functi
 }
 
 Forwarding *_Nullable new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht,
-                           Networking_Core *net)
+                                     Networking_Core *net)
 {
     if (log == nullptr || mono_time == nullptr || dht == nullptr) {
         return nullptr;
diff --git a/toxcore/forwarding.h b/toxcore/forwarding.h
index bdb8499..8cef884 100644
--- a/toxcore/forwarding.h
+++ b/toxcore/forwarding.h
@@ -99,7 +99,7 @@ typedef bool forward_reply_cb(void *_Nullable object, const uint8_t *_Nullable s
  */
 void set_callback_forward_reply(Forwarding *_Nonnull forwarding, forward_reply_cb *_Nullable function, void *_Nullable object);
 Forwarding *_Nullable new_forwarding(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, DHT *_Nonnull dht,
-                           Networking_Core *_Nonnull net);
+                                     Networking_Core *_Nonnull net);
 
 void kill_forwarding(Forwarding *_Nullable forwarding);
 #ifdef __cplusplus
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h
index aba378f..a6d09f0 100644
--- a/toxcore/friend_connection.h
+++ b/toxcore/friend_connection.h
@@ -146,7 +146,7 @@ void set_friend_request_callback(Friend_Connections *_Nonnull fr_c, fr_request_c
 /** Create new friend_connections instance. */
 Friend_Connections *_Nullable new_friend_connections(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, const Network *_Nonnull ns,
         Onion_Client *_Nonnull onion_c, DHT *_Nonnull dht, Net_Crypto *_Nonnull net_crypto, Networking_Core *_Nonnull net,
-    bool local_discovery_enabled);
+        bool local_discovery_enabled);
 
 /** main friend_connections loop. */
 void do_friend_connections(Friend_Connections *_Nonnull fr_c, void *_Nonnull userdata);
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index b484078..f3270ad 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -368,7 +368,8 @@ void load_secret_key(Net_Crypto *_Nonnull c, const uint8_t *_Nonnull sk);
 /** @brief Create new instance of Net_Crypto.
  * Sets all the global connection variables to their default values.
  */
-Net_Crypto *_Nullable new_net_crypto(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time, Networking_Core *_Nonnull net, DHT *_Nonnull dht,
+Net_Crypto *_Nullable new_net_crypto(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time,
+                                     Networking_Core *_Nonnull net, DHT *_Nonnull dht,
                                      const TCP_Proxy_Info *_Nonnull proxy_info, Net_Profile *_Nonnull tcp_np);
 
 /** return the optimal interval in ms for running do_net_crypto. */
diff --git a/toxcore/onion_announce.h b/toxcore/onion_announce.h
index 6082be9..fca6798 100644
--- a/toxcore/onion_announce.h
+++ b/toxcore/onion_announce.h
@@ -125,7 +125,7 @@ typedef int pack_extra_data_cb(void *_Nonnull object, const Logger *_Nonnull log
 void onion_announce_extra_data_callback(Onion_Announce *_Nonnull onion_a, uint16_t extra_data_max_size, pack_extra_data_cb *_Nonnull extra_data_callback, void *_Nonnull extra_data_object);
 
 Onion_Announce *_Nullable new_onion_announce(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, DHT *_Nonnull dht,
-                                   Networking_Core *_Nonnull net);
+        Networking_Core *_Nonnull net);
 
 void kill_onion_announce(Onion_Announce *_Nullable onion_a);
 #endif /* C_TOXCORE_TOXCORE_ONION_ANNOUNCE_H */
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 4b95572..a61e9ac 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -191,7 +191,8 @@ typedef bool onion_group_announce_cb(Onion_Client *_Nonnull onion_c, uint32_t se
 void onion_group_announce_register(Onion_Client *_Nonnull onion_c, onion_group_announce_cb *_Nullable func, void *_Nullable user_data);
 void do_onion_client(Onion_Client *_Nonnull onion_c);
 
-Onion_Client *_Nullable new_onion_client(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Net_Crypto *_Nonnull c, DHT *_Nonnull dht, Networking_Core *_Nonnull net);
+Onion_Client *_Nullable new_onion_client(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Net_Crypto *_Nonnull c,
+        DHT *_Nonnull dht, Networking_Core *_Nonnull net);
 
 void kill_onion_client(Onion_Client *_Nullable onion_c);
 typedef enum Onion_Connection_Status {

Instead of transitively loading them from dependencies, we should be
explicit about what each object needs. The downside of this is that it's
not clear whether the object and its dependency use the same common
dependency. The upside is that we don't expose those getters of internal
dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring production code, eg. renaming a variable, not affecting semantics

Development

Successfully merging this pull request may close these issues.

3 participants