@@ -2016,7 +2016,7 @@ static bool send_gc_tcp_relays(const GC_Chat *chat, GC_Connection *gconn)
20162016
20172017 for (uint32_t i = 0 ; i < n ; ++ i ) {
20182018 add_tcp_relay_connection (chat -> tcp_conn , gconn -> tcp_connection_num , & tcp_relays [i ].ip_port ,
2019- tcp_relays [i ].public_key );
2019+ tcp_relays [i ].public_key );
20202020 }
20212021
20222022 const int nodes_len = pack_nodes (chat -> log , data , sizeof (data ), tcp_relays , n );
@@ -7050,9 +7050,10 @@ static void do_gc_tcp(const GC_Session *c, GC_Chat *chat, void *userdata)
70507050 set_tcp_connection_to_status (chat -> tcp_conn , gconn -> tcp_connection_num , tcp_set );
70517051 }
70527052
7053- if (mono_time_is_timeout (chat -> mono_time , chat -> last_checked_tcp_relays , TCP_RELAYS_CHECK_INTERVAL ) &&
7054- tcp_connected_relays_count (chat -> tcp_conn ) != chat -> tcp_connections ) {
7053+ if (mono_time_is_timeout (chat -> mono_time , chat -> last_checked_tcp_relays , TCP_RELAYS_CHECK_INTERVAL )
7054+ && tcp_connected_relays_count (chat -> tcp_conn ) != chat -> connected_tcp_relays ) {
70557055 add_tcp_relays_to_chat (c , chat );
7056+ chat -> connected_tcp_relays = tcp_connected_relays_count (chat -> tcp_conn );
70567057 chat -> last_checked_tcp_relays = mono_time_get (chat -> mono_time );
70577058 }
70587059}
@@ -7061,27 +7062,27 @@ static void do_gc_tcp(const GC_Session *c, GC_Chat *chat, void *userdata)
70617062 * Updates our TCP and UDP connection status and flags a new announcement if our connection has
70627063 * changed and we have either a UDP or TCP connection.
70637064 */
7064- #define GC_SELF_CONNECTION_CHECK_INTERVAL 2
7065+ #define GC_SELF_CONNECTION_CHECK_INTERVAL 5 // how often in seconds we should run this function
7066+ #define GC_SELF_REFRESH_ANNOUNCE_INTERVAL (60 * 20) // how often in seconds we force refresh our group announcement
70657067non_null ()
70667068static void do_self_connection (const GC_Session * c , GC_Chat * chat )
70677069{
70687070 if (!mono_time_is_timeout (chat -> mono_time , chat -> last_self_announce_check , GC_SELF_CONNECTION_CHECK_INTERVAL )) {
70697071 return ;
70707072 }
70717073
7072- const uint32_t tcp_connections = tcp_connected_relays_count (chat -> tcp_conn );
7073-
7074- const Messenger * m = c -> messenger ;
7075- const unsigned int self_udp_status = ipport_self_copy (m -> dht , & chat -> self_ip_port );
7076-
7074+ const unsigned int self_udp_status = ipport_self_copy (c -> messenger -> dht , & chat -> self_ip_port );
70777075 const bool udp_change = (chat -> self_udp_status != self_udp_status ) && (self_udp_status != SELF_UDP_STATUS_NONE );
7078- const bool tcp_change = tcp_connections != chat -> tcp_connections ;
70797076
7080- if (is_public_chat (chat ) && (udp_change || tcp_change )) {
7077+ // We flag a group announce if our UDP status has changed since last run, or if our last announced TCP
7078+ // relay is no longer valid. Additionally, we will always flag an announce in the specified interval
7079+ // regardless of the prior conditions. Private groups are never announced.
7080+ if (is_public_chat (chat ) &&
7081+ ((udp_change || !tcp_relay_is_valid (chat -> tcp_conn , chat -> announced_tcp_relay_pk ))
7082+ || mono_time_is_timeout (chat -> mono_time , chat -> last_time_self_announce , GC_SELF_REFRESH_ANNOUNCE_INTERVAL ))) {
70817083 chat -> update_self_announces = true;
70827084 }
70837085
7084- chat -> tcp_connections = tcp_connections ;
70857086 chat -> self_udp_status = (Self_UDP_Status ) self_udp_status ;
70867087 chat -> last_self_announce_check = mono_time_get (chat -> mono_time );
70877088}
0 commit comments