mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
optimize srt handle shake
This commit is contained in:
parent
f0ae5a1bd7
commit
beb6383e72
@ -116,14 +116,41 @@ 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) {
|
void SrtTransport::handleHandshakeInduction(HandshakePacket &pkt, struct sockaddr_storage *addr) {
|
||||||
// Induction Phase
|
// Induction Phase
|
||||||
TraceL << getIdentifier() << " Induction Phase ";
|
|
||||||
if (_handleshake_res) {
|
if (_handleshake_res) {
|
||||||
TraceL << getIdentifier() << " Induction handle repeate ";
|
if(isSameCon(pkt)){
|
||||||
|
TraceL << getIdentifier() <<" Induction repeate "<<SockUtil::inet_ntoa((struct sockaddr *)addr) << ":" << SockUtil::inet_port((struct sockaddr *)addr);
|
||||||
sendControlPacket(_handleshake_res, true);
|
sendControlPacket(_handleshake_res, true);
|
||||||
|
}else{
|
||||||
|
TraceL << getIdentifier() <<" new connection fron client "<<SockUtil::inet_ntoa((struct sockaddr *)addr) << ":" << SockUtil::inet_port((struct sockaddr *)addr);
|
||||||
|
onShutdown(SockException(Err_other, "client new connection"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}else{
|
||||||
|
TraceL << getIdentifier() <<" Induction from "<<SockUtil::inet_ntoa((struct sockaddr *)addr) << ":" << SockUtil::inet_port((struct sockaddr *)addr);
|
||||||
}
|
}
|
||||||
_induction_ts = _now;
|
_induction_ts = _now;
|
||||||
_start_timestamp = _now;
|
_start_timestamp = _now;
|
||||||
@ -222,8 +249,14 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad
|
|||||||
_buf_delay = delay;
|
_buf_delay = delay;
|
||||||
onHandShakeFinished(_stream_id, addr);
|
onHandShakeFinished(_stream_id, addr);
|
||||||
} else {
|
} else {
|
||||||
TraceL << getIdentifier() << " CONCLUSION handle repeate ";
|
if(isSameCon(pkt)){
|
||||||
|
TraceL << getIdentifier() <<" CONCLUSION repeate "<<SockUtil::inet_ntoa((struct sockaddr *)addr) << ":" << SockUtil::inet_port((struct sockaddr *)addr);
|
||||||
sendControlPacket(_handleshake_res, true);
|
sendControlPacket(_handleshake_res, true);
|
||||||
|
}else{
|
||||||
|
TraceL << getIdentifier() <<" new connection fron client "<<SockUtil::inet_ntoa((struct sockaddr *)addr) << ":" << SockUtil::inet_port((struct sockaddr *)addr);
|
||||||
|
onShutdown(SockException(Err_other, "client new connection"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
_last_ack_pkt_seq_num = _init_seq_number;
|
_last_ack_pkt_seq_num = _init_seq_number;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,8 @@ private:
|
|||||||
|
|
||||||
size_t getPayloadSize();
|
size_t getPayloadSize();
|
||||||
|
|
||||||
|
bool isSameCon(HandshakePacket &pkt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sendDataPacket(DataPacket::Ptr pkt, char *buf, int len, bool flush = false);
|
void sendDataPacket(DataPacket::Ptr pkt, char *buf, int len, bool flush = false);
|
||||||
void sendControlPacket(ControlPacket::Ptr pkt, bool flush = true);
|
void sendControlPacket(ControlPacket::Ptr pkt, bool flush = true);
|
||||||
|
Loading…
Reference in New Issue
Block a user