5757#define KEYS_TIMEOUT 600
5858
5959typedef struct DHT_Friend_Callback {
60- dht_ip_cb * ip_callback ;
61- void * data ;
60+ dht_ip_cb * _Nullable ip_callback ;
61+ void * _Nullable data ;
6262 int32_t number ;
6363} DHT_Friend_Callback ;
6464
@@ -88,17 +88,17 @@ const Node_format empty_node_format = {{0}};
8888static_assert (sizeof (empty_dht_friend .lock_flags ) * 8 == DHT_FRIEND_MAX_LOCKS , "Bitfield size and number of locks don't match" );
8989
9090typedef struct Cryptopacket_Handler {
91- cryptopacket_handler_cb * function ;
92- void * object ;
91+ cryptopacket_handler_cb * _Nullable function ;
92+ void * _Nullable object ;
9393} Cryptopacket_Handler ;
9494
9595struct DHT {
96- const Logger * log ;
97- const Network * ns ;
98- Mono_Time * mono_time ;
99- const Memory * mem ;
100- const Random * rng ;
101- Networking_Core * net ;
96+ const Logger * _Nonnull log ;
97+ const Network * _Nonnull ns ;
98+ Mono_Time * _Nonnull mono_time ;
99+ const Memory * _Nonnull mem ;
100+ const Random * _Nonnull rng ;
101+ Networking_Core * _Nonnull net ;
102102
103103 bool hole_punching_enabled ;
104104 bool lan_discovery_enabled ;
@@ -111,26 +111,26 @@ struct DHT {
111111 uint8_t self_public_key [CRYPTO_PUBLIC_KEY_SIZE ];
112112 uint8_t self_secret_key [CRYPTO_SECRET_KEY_SIZE ];
113113
114- DHT_Friend * friends_list ;
114+ DHT_Friend * _Nullable friends_list ;
115115 uint16_t num_friends ;
116116
117- Node_format * loaded_nodes_list ;
117+ Node_format * _Nullable loaded_nodes_list ;
118118 uint32_t loaded_num_nodes ;
119119 unsigned int loaded_nodes_index ;
120120
121- Shared_Key_Cache * shared_keys_recv ;
122- Shared_Key_Cache * shared_keys_sent ;
121+ Shared_Key_Cache * _Nonnull shared_keys_recv ;
122+ Shared_Key_Cache * _Nonnull shared_keys_sent ;
123123
124- struct Ping * ping ;
125- Ping_Array * dht_ping_array ;
124+ struct Ping * _Nonnull ping ;
125+ Ping_Array * _Nonnull dht_ping_array ;
126126 uint64_t cur_time ;
127127
128128 Cryptopacket_Handler cryptopackethandlers [256 ];
129129
130130 Node_format to_bootstrap [MAX_CLOSE_TO_BOOTSTRAP_NODES ];
131131 unsigned int num_to_bootstrap ;
132132
133- dht_nodes_response_cb * nodes_response_callback ;
133+ dht_nodes_response_cb * _Nullable nodes_response_callback ;
134134};
135135
136136const uint8_t * dht_friend_public_key (const DHT_Friend * dht_friend )
@@ -734,7 +734,7 @@ int get_close_nodes(
734734 return get_somewhat_close_nodes (
735735 dht -> cur_time , public_key , nodes_list ,
736736 sa_family , dht -> close_clientlist ,
737- dht -> friends_list , dht -> num_friends ,
737+ ( const DHT_Friend * _Nonnull) dht -> friends_list , dht -> num_friends ,
738738 is_lan , want_announce );
739739}
740740
@@ -849,9 +849,9 @@ static bool store_node_ok(const Client_data *_Nonnull client, uint64_t cur_time,
849849}
850850
851851typedef struct Client_data_Cmp {
852- const Memory * mem ;
852+ const Memory * _Nonnull mem ;
853853 uint64_t cur_time ;
854- const uint8_t * comp_public_key ;
854+ const uint8_t * _Nonnull comp_public_key ;
855855} Client_data_Cmp ;
856856
857857static int client_data_cmp (const Client_data_Cmp * _Nonnull cmp , const Client_data * _Nonnull entry1 , const Client_data * _Nonnull entry2 )
@@ -2509,14 +2509,16 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
25092509 dht -> hole_punching_enabled = hole_punching_enabled ;
25102510 dht -> lan_discovery_enabled = lan_discovery_enabled ;
25112511
2512- dht -> ping = ping_new (mem , mono_time , rng , dht );
2512+ struct Ping * temp_ping = ping_new (mem , mono_time , rng , dht );
25132513
2514- if (dht -> ping == nullptr ) {
2514+ if (temp_ping == nullptr ) {
25152515 LOGGER_ERROR (log , "failed to initialise ping" );
25162516 kill_dht (dht );
25172517 return nullptr ;
25182518 }
25192519
2520+ dht -> ping = temp_ping ;
2521+
25202522 networking_registerhandler (dht -> net , NET_PACKET_NODES_REQUEST , & handle_nodes_request , dht );
25212523 networking_registerhandler (dht -> net , NET_PACKET_NODES_RESPONSE , & handle_nodes_response , dht );
25222524 networking_registerhandler (dht -> net , NET_PACKET_CRYPTO , & cryptopacket_handle , dht );
@@ -2529,23 +2531,36 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
25292531
25302532 crypto_new_keypair (rng , dht -> self_public_key , dht -> self_secret_key );
25312533
2532- dht -> shared_keys_recv = shared_key_cache_new (log , mono_time , mem , dht -> self_secret_key , KEYS_TIMEOUT , MAX_KEYS_PER_SLOT );
2533- dht -> shared_keys_sent = shared_key_cache_new (log , mono_time , mem , dht -> self_secret_key , KEYS_TIMEOUT , MAX_KEYS_PER_SLOT );
2534+ 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 );
2535+
2536+ if (temp_shared_keys_recv == nullptr ) {
2537+ LOGGER_ERROR (log , "failed to initialise shared key cache" );
2538+ kill_dht (dht );
2539+ return nullptr ;
2540+ }
2541+
2542+ dht -> shared_keys_recv = temp_shared_keys_recv ;
2543+
2544+ 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 );
25342545
2535- if (dht -> shared_keys_recv == nullptr || dht -> shared_keys_sent == nullptr ) {
2546+ if (temp_shared_keys_sent == nullptr ) {
25362547 LOGGER_ERROR (log , "failed to initialise shared key cache" );
25372548 kill_dht (dht );
25382549 return nullptr ;
25392550 }
25402551
2541- dht -> dht_ping_array = ping_array_new ( mem , DHT_PING_ARRAY_SIZE , PING_TIMEOUT ) ;
2552+ dht -> shared_keys_sent = temp_shared_keys_sent ;
25422553
2543- if (dht -> dht_ping_array == nullptr ) {
2554+ Ping_Array * const temp_ping_array = ping_array_new (mem , DHT_PING_ARRAY_SIZE , PING_TIMEOUT );
2555+
2556+ if (temp_ping_array == nullptr ) {
25442557 LOGGER_ERROR (log , "failed to initialise ping array" );
25452558 kill_dht (dht );
25462559 return nullptr ;
25472560 }
25482561
2562+ dht -> dht_ping_array = temp_ping_array ;
2563+
25492564 for (uint32_t i = 0 ; i < DHT_FAKE_FRIEND_NUMBER ; ++ i ) {
25502565 uint8_t random_public_key_bytes [CRYPTO_PUBLIC_KEY_SIZE ];
25512566 uint8_t random_secret_key_bytes [CRYPTO_SECRET_KEY_SIZE ];
@@ -2600,7 +2615,7 @@ void kill_dht(DHT *dht)
26002615 networking_registerhandler (dht -> net , NET_PACKET_NODES_RESPONSE , nullptr , nullptr );
26012616 networking_registerhandler (dht -> net , NET_PACKET_CRYPTO , nullptr , nullptr );
26022617 networking_registerhandler (dht -> net , NET_PACKET_LAN_DISCOVERY , nullptr , nullptr );
2603- cryptopacket_registerhandler (dht , CRYPTO_PACKET_NAT_PING , nullptr , nullptr );
2618+ cryptopacket_registerhandler (( DHT * _Nonnull) dht , CRYPTO_PACKET_NAT_PING , nullptr , nullptr );
26042619
26052620 shared_key_cache_free (dht -> shared_keys_recv );
26062621 shared_key_cache_free (dht -> shared_keys_sent );
0 commit comments