@ -746,6 +746,8 @@ void etcp_socket_remove(struct ETCP_SOCKET* conn) {
}
}
static void bbr_cwnd_updated ( void * ctx , uint32_t new_cwnd ) ;
struct ETCP_LINK * etcp_link_new ( struct ETCP_CONN * etcp , struct ETCP_SOCKET * conn , struct sockaddr_storage * remote_addr , uint8_t is_server ) {
struct ETCP_LINK * etcp_link_new ( struct ETCP_CONN * etcp , struct ETCP_SOCKET * conn , struct sockaddr_storage * remote_addr , uint8_t is_server ) {
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
if ( ! remote_addr ) return NULL ;
if ( ! remote_addr ) return NULL ;
@ -787,7 +789,6 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
link - > keepalive_sent_count = 0 ;
link - > keepalive_sent_count = 0 ;
link - > keepalive_recv_count = 0 ;
link - > keepalive_recv_count = 0 ;
link - > ka_period_ms = KA_PERIOD_MIN_MS ;
link - > ka_period_ms = KA_PERIOD_MIN_MS ;
link - > inflight_lim_bytes = link - > mtu * 4 ; // BBR init_cwnd (~4 packets)
link - > bandwidth = 10000 ; // начальная оценка 10 Mbps для шейпера
link - > bandwidth = 10000 ; // начальная оценка 10 Mbps для шейпера
link - > burst_id = 0 ;
link - > burst_id = 0 ;
link - > burst_active = 0 ;
link - > burst_active = 0 ;
@ -832,10 +833,9 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
while ( l & & l - > next ) l = l - > next ;
while ( l & & l - > next ) l = l - > next ;
if ( l ) l - > next = link ; else etcp - > links = link ;
if ( l ) l - > next = link ; else etcp - > links = link ;
// пересчитать connection-level optimal_inflight
etcp_link_update_inflight_lim ( link , link - > mtu * 4 ) ;
{ uint32_t sum = 0 ;
link - > bbr - > on_cwnd_update = bbr_cwnd_updated ;
for ( struct ETCP_LINK * tl = etcp - > links ; tl ; tl = tl - > next ) sum + = tl - > inflight_lim_bytes ;
link - > bbr - > cwnd_update_ctx = link ;
etcp - > optimal_inflight = sum ; }
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION , " NEW link initialized on etcp=[%s] link=%p socket=%s id=%d is_server=%d mtu=%d " , etcp - > log_name , link , conn - > name , link - > local_link_id , link - > is_server , link - > mtu ) ;
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTION , " NEW link initialized on etcp=[%s] link=%p socket=%s id=%d is_server=%d mtu=%d " , etcp - > log_name , link , conn - > name , link - > local_link_id , link - > is_server , link - > mtu ) ;
@ -847,6 +847,18 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
return link ;
return link ;
}
}
static void bbr_cwnd_updated ( void * ctx , uint32_t new_cwnd ) {
etcp_link_update_inflight_lim ( ( struct ETCP_LINK * ) ctx , new_cwnd ) ;
}
void etcp_link_update_inflight_lim ( struct ETCP_LINK * link , uint32_t new_lim ) {
link - > inflight_lim_bytes = new_lim ;
struct ETCP_CONN * etcp = link - > etcp ;
uint32_t sum = 0 ;
for ( struct ETCP_LINK * tl = etcp - > links ; tl ; tl = tl - > next ) sum + = tl - > inflight_lim_bytes ;
etcp - > optimal_inflight = sum ;
}
void etcp_link_close ( struct ETCP_LINK * link ) {
void etcp_link_close ( struct ETCP_LINK * link ) {
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTION , " " ) ;
if ( ! link ) return ;
if ( ! link ) return ;
@ -1731,10 +1743,6 @@ process_decrypted:
// log_dump("RECV decrypted:", pkt->data, pkt->data_len, link);
// log_dump("RECV decrypted:", pkt->data, pkt->data_len, link);
if ( link - > link_state = = 3 ) {
if ( link - > link_state = = 3 ) {
if ( memory_pool_is_freed ( e_sock - > instance - > pkt_pool , pkt ) ) {
DEBUG_ERROR ( DEBUG_CATEGORY_ETCP , " etcp_conn_input: pkt=%p ALREADY FREED in pkt_pool — HALTING " , ( void * ) pkt ) ;
volatile int _halt = 1 ; while ( _halt ) { }
}
etcp_conn_input ( pkt ) ;
etcp_conn_input ( pkt ) ;
} else memory_pool_free ( e_sock - > instance - > pkt_pool , pkt ) ;
} else memory_pool_free ( e_sock - > instance - > pkt_pool , pkt ) ;
return ;
return ;