From f9f6fd136a7337518b6516a8897d812c0344c351 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Sat, 27 Aug 2022 15:06:03 +0800 Subject: [PATCH] srt handle packet send repeate by timer --- srt/SrtTransport.cpp | 74 +++++++++++++++++++++----------------------- srt/SrtTransport.hpp | 4 +-- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/srt/SrtTransport.cpp b/srt/SrtTransport.cpp index dd6cc5a1..398486da 100644 --- a/srt/SrtTransport.cpp +++ b/srt/SrtTransport.cpp @@ -80,6 +80,9 @@ void SrtTransport::inputSockData(uint8_t *buf, int len, struct sockaddr_storage if (DataPacket::isDataPacket(buf, len)) { uint32_t socketId = DataPacket::getSocketID(buf, len); if (socketId == _socket_id) { + if(_handleshake_timer){ + _handleshake_timer.reset(); + } _pkt_recv_rate_context->inputPacket(_now); _estimated_link_capacity_context->inputPacket(_now); _recv_rate_context->inputPacket(_now, len); @@ -116,39 +119,27 @@ void SrtTransport::inputSockData(uint8_t *buf, int len, struct sockaddr_storage } } } -bool SrtTransport::isSameCon(HandshakePacket &pkt) { - if (_handleshake_res) { - if (_handleshake_res->handshake_type == HandshakePacket::HS_TYPE_INDUCTION) { - if (pkt.srt_socket_id == _handleshake_res->dst_socket_id - && pkt.initial_packet_sequence_number == _init_seq_number) { - return true; - } - // TraceL << getIdentifier() << " new client from same udp connection"; - return false; - } else if (_handleshake_res->handshake_type == HandshakePacket::HS_TYPE_CONCLUSION) { - if (pkt.srt_socket_id == _handleshake_res->dst_socket_id && _sync_cookie == pkt.syn_cookie) { - return true; - } - // TraceL << getIdentifier() << " new client from new same udp connection "; - return false; - } else { - WarnL << "not reach this"; - } - return false; - } - return true; -} + void SrtTransport::handleHandshakeInduction(HandshakePacket &pkt, struct sockaddr_storage *addr) { // Induction Phase if (_handleshake_res) { - if(isSameCon(pkt)){ - TraceL << getIdentifier() <<" Induction repeate "<handshake_type == HandshakePacket::HS_TYPE_INDUCTION){ + if(pkt.srt_socket_id == _handleshake_res->dst_socket_id){ + TraceL << getIdentifier() <<" Induction repeate "<handshake_type == HandshakePacket::HS_TYPE_CONCLUSION){ + if(_handleshake_res->dst_socket_id != pkt.srt_socket_id){ + TraceL << getIdentifier() <<" new connection fron client "<storeToData(); registerSelfHandshake(); - for(int i=0;i<3;++i){ - sendControlPacket(res, true); - } + sendControlPacket(res, true); + + _handleshake_timer = std::make_shared(0.02,[this]()->bool{ + sendControlPacket(_handleshake_res, true); + return true; + },getPoller()); } void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockaddr_storage *addr) { @@ -220,7 +214,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad srt_flag = req->srt_flag; delay = delay <= req->recv_tsbpd_delay ? req->recv_tsbpd_delay : delay; } - TraceL << getIdentifier() << " CONCLUSION Phase "; + TraceL << getIdentifier() << " CONCLUSION Phase from"<(); res->dst_socket_id = _peer_socket_id; res->timestamp = DurationCountMicroseconds(_now - _start_timestamp); @@ -244,9 +238,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad _handleshake_res = res; unregisterSelfHandshake(); registerSelf(); - for(int i=0;i<3;++i){ - sendControlPacket(res, true); - } + sendControlPacket(res, true); TraceL << " buf size = " << res->max_flow_window_size << " init seq =" << _init_seq_number << " latency=" << delay; _recv_buf = std::make_shared(getPktBufSize(), _init_seq_number, delay * 1e3,srt_flag); @@ -255,15 +247,19 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad _buf_delay = delay; onHandShakeFinished(_stream_id, addr); } else { - if(isSameCon(pkt)){ - TraceL << getIdentifier() <<" CONCLUSION repeate "<handshake_type == HandshakePacket::HS_TYPE_CONCLUSION){ + if(_handleshake_res->dst_socket_id != pkt.srt_socket_id){ + TraceL << getIdentifier() <<" new connection fron client "< _packet_pool; };