@@ -168,8 +168,6 @@ non_null() static void group_delete(GC_Session *c, GC_Chat *chat);
168168non_null () static void group_cleanup (const GC_Session * c , GC_Chat * chat );
169169non_null () static bool group_exists (const GC_Session * c , const uint8_t * chat_id );
170170non_null () static void add_tcp_relays_to_chat (const GC_Session * c , GC_Chat * chat );
171- non_null (1 , 2 ) nullable (4 )
172- static bool peer_delete (const GC_Session * c , GC_Chat * chat , uint32_t peer_number , void * userdata );
173171non_null () static void create_gc_session_keypair (const Logger * log , const Random * rng , uint8_t * public_key ,
174172 uint8_t * secret_key );
175173non_null () static size_t load_gc_peers (GC_Chat * chat , const GC_SavedPeerInfo * addrs , uint16_t num_addrs );
@@ -837,6 +835,21 @@ static int saved_peer_index(const GC_Chat *chat, const uint8_t *public_key)
837835 return -1 ;
838836}
839837
838+ /** @brief Removes entry containing `public_key` from the saved peers list. */
839+ non_null ()
840+ static void saved_peers_remove_entry (GC_Chat * chat , const uint8_t * public_key )
841+ {
842+ const int idx = saved_peer_index (chat , public_key );
843+
844+ if (idx < 0 ) {
845+ return ;
846+ }
847+
848+ chat -> saved_peers [idx ] = (GC_SavedPeerInfo ) {
849+ 0
850+ };
851+ }
852+
840853/** @brief Returns the index of the first vacant entry in saved peers list.
841854 *
842855 * If `public_key` is non-null and already exists in the list, its index will be returned.
@@ -6701,6 +6714,7 @@ void gc_callback_rejected(const Messenger *m, gc_rejected_cb *function)
67016714 *
67026715 * Return true on success.
67036716 */
6717+ non_null (1 , 2 ) nullable (4 )
67046718static bool peer_delete (const GC_Session * c , GC_Chat * chat , uint32_t peer_number , void * userdata )
67056719{
67066720 GC_Peer * peer = get_gc_peer (chat , peer_number );
@@ -6709,17 +6723,23 @@ static bool peer_delete(const GC_Session *c, GC_Chat *chat, uint32_t peer_number
67096723 return false;
67106724 }
67116725
6726+ GC_Connection * gconn = & peer -> gconn ;
6727+
67126728 // We need to save some peer info for the callback before deleting it
6713- const bool peer_confirmed = peer -> gconn . confirmed ;
6729+ const bool peer_confirmed = gconn -> confirmed ;
67146730 const GC_Peer_Id peer_id = peer -> peer_id ;
67156731 uint8_t nick [MAX_GC_NICK_SIZE ];
67166732 const uint16_t nick_length = peer -> nick_length ;
6717- const GC_Exit_Info exit_info = peer -> gconn . exit_info ;
6733+ const GC_Exit_Info exit_info = gconn -> exit_info ;
67186734
67196735 assert (nick_length <= MAX_GC_NICK_SIZE );
67206736 memcpy (nick , peer -> nick , nick_length );
67216737
6722- gcc_peer_cleanup (chat -> mem , & peer -> gconn );
6738+ if (exit_info .exit_type == GC_EXIT_TYPE_KICKED ) {
6739+ saved_peers_remove_entry (chat , gconn -> addr .public_key .enc );
6740+ }
6741+
6742+ gcc_peer_cleanup (chat -> mem , gconn );
67236743
67246744 -- chat -> numpeers ;
67256745
0 commit comments