@ -246,12 +246,12 @@ void etcp_link_enter_reinit(struct ETCP_LINK* link) {
// Send empty keepalive packet (only timestamp, no sections)
static void etcp_link_send_keepalive ( struct ETCP_LINK * link ) {
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_KEEPALIVE , " " ) ;
if ( ! link | | ! link - > etcp | | ! link - > etcp - > instance ) return ;
struct ETCP_DGRAM * dgram = u_malloc ( sizeof ( struct ETCP_DGRAM ) + 4 ) ;
if ( ! dgram ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTION , " etcp_link_send_keepalive: malloc failed " ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_KEEPALIVE , " etcp_link_send_keepalive: malloc failed " ) ;
return ;
}
@ -260,7 +260,7 @@ static void etcp_link_send_keepalive(struct ETCP_LINK* link) {
dgram - > noencrypt_len = 0 ;
dgram - > timestamp = get_current_timestamp ( ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " [%s] Sending keepalive on link %p (local_id=%d) " ,
DEBUG_DEBUG ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Sending keepalive on link %p (local_id=%d) " ,
link - > etcp - > log_name , link , link - > local_link_id ) ;
link - > keepalive_sent_count + + ;
@ -293,16 +293,16 @@ static void start_keepalive_timer(struct ETCP_LINK* link) {
if ( link - > keepalive_timer = = NULL ) {
link - > keepalive_timer = uasync_set_timeout ( link - > etcp - > instance - > ua , link - > keepalive_interval * 10 , link , keepalive_timer_cb , " link_keepalive " ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " [%s] Keepalive timer started on link %p (interval=%d ms) " , link - > etcp - > log_name , link , link - > keepalive_interval ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Keepalive timer started on link %p (interval=%d ms) " , link - > etcp - > log_name , link , link - > keepalive_interval ) ;
}
}
// Keepalive timer callback
static void keepalive_timer_cb ( void * arg ) {
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_KEEPALIVE , " " ) ;
struct ETCP_LINK * link = ( struct ETCP_LINK * ) arg ;
if ( ! link | | ! link - > etcp | | ! link - > etcp - > instance ) {
DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTION , " KEEPALIVE NULL !!!!!!!! " ) ;
DEBUG_ERROR ( DEBUG_CATEGORY_KEEPALIVE , " KEEPALIVE NULL !!!!!!!! " ) ;
return ;
}
@ -310,14 +310,14 @@ static void keepalive_timer_cb(void* arg) {
// Check if all links are down and start recovery if needed (client only)
if ( link - > is_server = = 0 & & etcp_all_links_down ( link - > etcp ) ) {
DEBUG_WARN ( DEBUG_CATEGORY_CONNECTION , " [%s] All links are down, starting recovery " , link - > etcp - > log_name ) ;
DEBUG_WARN ( DEBUG_CATEGORY_KEEPALIVE , " [%s] All links are down, starting recovery " , link - > etcp - > log_name ) ;
etcp_link_enter_reinit ( link ) ; // keepalive timr после reinit не нужен
return ;
}
// Skip if link is not initialized
if ( ! link - > initialized ) {
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " [%s] Keepalive skipped - link not initialized " ,
DEBUG_DEBUG ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Keepalive skipped - link not initialized " ,
link - > etcp - > log_name ) ;
goto restart_timer ;
}
@ -332,8 +332,8 @@ static void keepalive_timer_cb(void* arg) {
link - > recv_keepalive = 0 ;
link - > link_status = 0 ;
etcp_on_link_down ( link - > etcp ) ;
DEBUG_INFO ( DEBUG_CATEGORY_GENERAL , " [%s] Conn:%s Link down: link_id=%d ka=%d remote_ka=%d tmo: %d>%d " , link - > etcp - > log_name , link - > conn ? link - > conn - > name : " ??? " , link - > local_link_id , link - > recv_keepalive , link - > remote_keepalive , elapsed , timeout_units ) ;
DEBUG_WARN ( DEBUG_CATEGORY_CONNECTION , " [%s] Link %p (local_id=%d) recv status changed to DOWN - no packets for %llu ms " , link - > etcp - > log_name , link , link - > local_link_id , ( unsigned long long ) ( elapsed / 10 ) ) ;
DEBUG_INFO ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Conn:%s Link down: link_id=%d ka=%d remote_ka=%d tmo: %d>%d " , link - > etcp - > log_name , link - > conn ? link - > conn - > name : " ??? " , link - > local_link_id , link - > recv_keepalive , link - > remote_keepalive , elapsed , timeout_units ) ;
DEBUG_WARN ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Link %p (local_id=%d) recv status changed to DOWN - no packets for %llu ms " , link - > etcp - > log_name , link , link - > local_link_id , ( unsigned long long ) ( elapsed / 10 ) ) ;
}
}
@ -1636,7 +1636,7 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
link - > keepalive_interval = ( ack_hdr - > keepalive [ 0 ] < < 8 ) | ack_hdr - > keepalive [ 1 ] ;
link - > recovery_interval = ( ( ack_hdr - > recovery [ 0 ] < < 8 ) | ack_hdr - > recovery [ 1 ] ) * 100 ; // timebase в link, timebase/100 в кодограмме
if ( link - > keepalive_interval < 10 ) link - > keepalive_interval = 10 ;
DEBUG_DEBUG ( DEBUG_CATEGORY_CONNECTION , " set keepalive for link=%d " , link - > keepalive_interval ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_KEEPALIVE , " set keepalive for link=%d " , link - > keepalive_interval ) ;
}
link - > mtu_remote = ( ack_hdr - > mtu [ 0 ] < < 8 ) | ack_hdr - > mtu [ 1 ] ;
@ -1764,6 +1764,8 @@ process_decrypted:
// Count received keepalive packets (empty packets with no payload)
if ( pkt - > data_len = = 0 ) {
link - > keepalive_recv_count + + ;
DEBUG_DEBUG ( DEBUG_CATEGORY_KEEPALIVE , " [%s] Received keepalive on link %p (local_id=%d) " ,
link - > etcp - > log_name , link , link - > local_link_id ) ;
}
size_t offset = 0 ;