mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	SRT: Upgrade libsrt from 1.4.1 to 1.5.1. v6.0.12 (#3362)
Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
		
							parent
							
								
									7a56208f2f
								
							
						
					
					
						commit
						fe086dfc31
					
				
					 143 changed files with 38185 additions and 15108 deletions
				
			
		
							
								
								
									
										456
									
								
								trunk/3rdparty/srt-1-fit/srtcore/packet.cpp
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										456
									
								
								trunk/3rdparty/srt-1-fit/srtcore/packet.cpp
									
										
									
									
										vendored
									
									
								
							|  | @ -1,11 +1,11 @@ | |||
| /*
 | ||||
|  * SRT - Secure, Reliable, Transport | ||||
|  * Copyright (c) 2018 Haivision Systems Inc. | ||||
|  *  | ||||
|  * | ||||
|  * This Source Code Form is subject to the terms of the Mozilla Public | ||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| /*****************************************************************************
 | ||||
|  | @ -50,7 +50,6 @@ modified by | |||
|    Haivision Systems Inc. | ||||
| *****************************************************************************/ | ||||
| 
 | ||||
| 
 | ||||
| //////////////////////////////////////////////////////////////////////////////
 | ||||
| //    0                   1                   2                   3
 | ||||
| //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 | ||||
|  | @ -137,9 +136,9 @@ modified by | |||
| //              Add. Info:    Error code
 | ||||
| //              Control Info: None
 | ||||
| //      0x7FFF: Explained by bits 16 - 31 (UMSG_EXT)
 | ||||
| //              
 | ||||
| //
 | ||||
| //   bit 16 - 31:
 | ||||
| //      This space is used for future expansion or user defined control packets. 
 | ||||
| //      This space is used for future expansion or user defined control packets.
 | ||||
| //
 | ||||
| //    0                   1                   2                   3
 | ||||
| //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 | ||||
|  | @ -159,26 +158,29 @@ modified by | |||
| //      For any single loss or consectutive loss less than 2 packets, use
 | ||||
| //      the original sequence numbers in the field.
 | ||||
| 
 | ||||
| #include "platform_sys.h" | ||||
| 
 | ||||
| #include <cstring> | ||||
| #include "packet.h" | ||||
| #include "handshake.h" | ||||
| #include "logging.h" | ||||
| #include "handshake.h" | ||||
| 
 | ||||
| namespace srt_logging | ||||
| { | ||||
|     extern Logger mglog; | ||||
| extern Logger inlog; | ||||
| } | ||||
| using namespace srt_logging; | ||||
| 
 | ||||
| // Set up the aliases in the constructure
 | ||||
| CPacket::CPacket(): | ||||
| __pad(), | ||||
| m_data_owned(false), | ||||
| m_iSeqNo((int32_t&)(m_nHeader[SRT_PH_SEQNO])), | ||||
| m_iMsgNo((int32_t&)(m_nHeader[SRT_PH_MSGNO])), | ||||
| m_iTimeStamp((int32_t&)(m_nHeader[SRT_PH_TIMESTAMP])), | ||||
| m_iID((int32_t&)(m_nHeader[SRT_PH_ID])), | ||||
| m_pcData((char*&)(m_PacketVector[PV_DATA].dataRef())) | ||||
| srt::CPacket::CPacket() | ||||
|     : m_extra_pad() | ||||
|     , m_data_owned(false) | ||||
|     , m_iSeqNo((int32_t&)(m_nHeader[SRT_PH_SEQNO])) | ||||
|     , m_iMsgNo((int32_t&)(m_nHeader[SRT_PH_MSGNO])) | ||||
|     , m_iTimeStamp((int32_t&)(m_nHeader[SRT_PH_TIMESTAMP])) | ||||
|     , m_iID((int32_t&)(m_nHeader[SRT_PH_ID])) | ||||
|     , m_pcData((char*&)(m_PacketVector[PV_DATA].dataRef())) | ||||
| { | ||||
|     m_nHeader.clear(); | ||||
| 
 | ||||
|  | @ -192,166 +194,236 @@ m_pcData((char*&)(m_PacketVector[PV_DATA].dataRef())) | |||
|     m_PacketVector[PV_DATA].set(NULL, 0); | ||||
| } | ||||
| 
 | ||||
| void CPacket::allocate(size_t alloc_buffer_size) | ||||
| char* srt::CPacket::getData() | ||||
| { | ||||
|     return (char*)m_PacketVector[PV_DATA].dataRef(); | ||||
| } | ||||
| 
 | ||||
| void srt::CPacket::allocate(size_t alloc_buffer_size) | ||||
| { | ||||
|     if (m_data_owned) | ||||
|     { | ||||
|         if (getLength() == alloc_buffer_size) | ||||
|             return; // already allocated
 | ||||
| 
 | ||||
|         // Would be nice to reallocate; for now just allocate again.
 | ||||
|         delete[] m_pcData; | ||||
|     } | ||||
|     m_PacketVector[PV_DATA].set(new char[alloc_buffer_size], alloc_buffer_size); | ||||
|     m_data_owned = true; | ||||
| } | ||||
| 
 | ||||
| void CPacket::deallocate() | ||||
| void srt::CPacket::deallocate() | ||||
| { | ||||
|     if (m_data_owned) | ||||
|         delete [] (char*)m_PacketVector[PV_DATA].data(); | ||||
|         delete[](char*) m_PacketVector[PV_DATA].data(); | ||||
|     m_PacketVector[PV_DATA].set(NULL, 0); | ||||
| } | ||||
| 
 | ||||
| CPacket::~CPacket() | ||||
| char* srt::CPacket::release() | ||||
| { | ||||
|     // When not owned, release returns NULL.
 | ||||
|     char* buffer = NULL; | ||||
|     if (m_data_owned) | ||||
|     { | ||||
|         buffer       = getData(); | ||||
|         m_data_owned = false; | ||||
|     } | ||||
| 
 | ||||
|     deallocate(); // won't delete because m_data_owned == false
 | ||||
|     return buffer; | ||||
| } | ||||
| 
 | ||||
| srt::CPacket::~CPacket() | ||||
| { | ||||
|     // PV_HEADER is always owned, PV_DATA may use a "borrowed" buffer.
 | ||||
|     // Delete the internal buffer only if it was declared as owned.
 | ||||
|     if (m_data_owned) | ||||
|         delete[](char*)m_PacketVector[PV_DATA].data(); | ||||
|         delete[](char*) m_PacketVector[PV_DATA].data(); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| size_t CPacket::getLength() const | ||||
| size_t srt::CPacket::getLength() const | ||||
| { | ||||
|    return m_PacketVector[PV_DATA].size(); | ||||
|     return m_PacketVector[PV_DATA].size(); | ||||
| } | ||||
| 
 | ||||
| void CPacket::setLength(size_t len) | ||||
| void srt::CPacket::setLength(size_t len) | ||||
| { | ||||
|    m_PacketVector[PV_DATA].setLength(len); | ||||
|     m_PacketVector[PV_DATA].setLength(len); | ||||
| } | ||||
| 
 | ||||
| void CPacket::pack(UDTMessageType pkttype, const void* lparam, void* rparam, int size) | ||||
| void srt::CPacket::pack(UDTMessageType pkttype, const int32_t* lparam, void* rparam, size_t size) | ||||
| { | ||||
|     // Set (bit-0 = 1) and (bit-1~15 = type)
 | ||||
|     setControl(pkttype); | ||||
|     HLOGC(inlog.Debug, | ||||
|           log << "pack: type=" << MessageTypeStr(pkttype) << " ARG=" << (lparam ? Sprint(*lparam) : std::string("NULL")) | ||||
|               << " [ " << (rparam ? Sprint(*(int32_t*)rparam) : std::string()) << " ]"); | ||||
| 
 | ||||
|    // Set additional information and control information field
 | ||||
|    switch (pkttype) | ||||
|    { | ||||
|    case UMSG_ACK: //0010 - Acknowledgement (ACK)
 | ||||
|       // ACK packet seq. no.
 | ||||
|       if (NULL != lparam) | ||||
|          m_nHeader[SRT_PH_MSGNO] = *(int32_t *)lparam; | ||||
|     // Set additional information and control information field
 | ||||
|     switch (pkttype) | ||||
|     { | ||||
|     case UMSG_ACK: // 0010 - Acknowledgement (ACK)
 | ||||
|         // ACK packet seq. no.
 | ||||
|         if (NULL != lparam) | ||||
|             m_nHeader[SRT_PH_MSGNO] = *lparam; | ||||
| 
 | ||||
|       // data ACK seq. no. 
 | ||||
|       // optional: RTT (microsends), RTT variance (microseconds) advertised flow window size (packets), and estimated link capacity (packets per second)
 | ||||
|       m_PacketVector[PV_DATA].set(rparam, size); | ||||
|         // data ACK seq. no.
 | ||||
|         // optional: RTT (microsends), RTT variance (microseconds) advertised flow window size (packets), and estimated
 | ||||
|         // link capacity (packets per second)
 | ||||
|         m_PacketVector[PV_DATA].set(rparam, size); | ||||
| 
 | ||||
|       break; | ||||
|         break; | ||||
| 
 | ||||
|    case UMSG_ACKACK: //0110 - Acknowledgement of Acknowledgement (ACK-2)
 | ||||
|       // ACK packet seq. no.
 | ||||
|       m_nHeader[SRT_PH_MSGNO] = *(int32_t *)lparam; | ||||
|     case UMSG_ACKACK: // 0110 - Acknowledgement of Acknowledgement (ACK-2)
 | ||||
|         // ACK packet seq. no.
 | ||||
|         m_nHeader[SRT_PH_MSGNO] = *lparam; | ||||
| 
 | ||||
|       // control info field should be none
 | ||||
|       // but "writev" does not allow this
 | ||||
|       m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|         // control info field should be none
 | ||||
|         // but "writev" does not allow this
 | ||||
|         m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
| 
 | ||||
|       break; | ||||
|         break; | ||||
| 
 | ||||
|    case UMSG_LOSSREPORT: //0011 - Loss Report (NAK)
 | ||||
|       // loss list
 | ||||
|       m_PacketVector[PV_DATA].set(rparam, size); | ||||
|     case UMSG_LOSSREPORT: // 0011 - Loss Report (NAK)
 | ||||
|         // loss list
 | ||||
|         m_PacketVector[PV_DATA].set(rparam, size); | ||||
| 
 | ||||
|       break; | ||||
|         break; | ||||
| 
 | ||||
|    case UMSG_CGWARNING: //0100 - Congestion Warning
 | ||||
|       // control info field should be none
 | ||||
|       // but "writev" does not allow this
 | ||||
|       m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|    | ||||
|       break; | ||||
|     case UMSG_CGWARNING: // 0100 - Congestion Warning
 | ||||
|         // control info field should be none
 | ||||
|         // but "writev" does not allow this
 | ||||
|         m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
| 
 | ||||
|    case UMSG_KEEPALIVE: //0001 - Keep-alive
 | ||||
|       // control info field should be none
 | ||||
|       // but "writev" does not allow this
 | ||||
|       m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|         break; | ||||
| 
 | ||||
|       break; | ||||
|     case UMSG_KEEPALIVE: // 0001 - Keep-alive
 | ||||
|         if (lparam) | ||||
|         { | ||||
|             // XXX EXPERIMENTAL. Pass the 32-bit integer here.
 | ||||
|             m_nHeader[SRT_PH_MSGNO] = *lparam; | ||||
|         } | ||||
|         // control info field should be none
 | ||||
|         // but "writev" does not allow this
 | ||||
|         m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
| 
 | ||||
|    case UMSG_HANDSHAKE: //0000 - Handshake
 | ||||
|       // control info filed is handshake info
 | ||||
|       m_PacketVector[PV_DATA].set(rparam, size); | ||||
|         break; | ||||
| 
 | ||||
|       break; | ||||
|     case UMSG_HANDSHAKE: // 0000 - Handshake
 | ||||
|         // control info filed is handshake info
 | ||||
|         m_PacketVector[PV_DATA].set(rparam, size); | ||||
| 
 | ||||
|    case UMSG_SHUTDOWN: //0101 - Shutdown
 | ||||
|       // control info field should be none
 | ||||
|       // but "writev" does not allow this
 | ||||
|       m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|         break; | ||||
| 
 | ||||
|       break; | ||||
|     case UMSG_SHUTDOWN: // 0101 - Shutdown
 | ||||
|         // control info field should be none
 | ||||
|         // but "writev" does not allow this
 | ||||
|         m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
| 
 | ||||
|    case UMSG_DROPREQ: //0111 - Message Drop Request
 | ||||
|       // msg id 
 | ||||
|       m_nHeader[SRT_PH_MSGNO] = *(int32_t *)lparam; | ||||
|         break; | ||||
| 
 | ||||
|       //first seq no, last seq no
 | ||||
|       m_PacketVector[PV_DATA].set(rparam, size); | ||||
|     case UMSG_DROPREQ: // 0111 - Message Drop Request
 | ||||
|         // msg id
 | ||||
|         m_nHeader[SRT_PH_MSGNO] = *lparam; | ||||
| 
 | ||||
|       break; | ||||
|         // first seq no, last seq no
 | ||||
|         m_PacketVector[PV_DATA].set(rparam, size); | ||||
| 
 | ||||
|    case UMSG_PEERERROR: //1000 - Error Signal from the Peer Side
 | ||||
|       // Error type
 | ||||
|       m_nHeader[SRT_PH_MSGNO] = *(int32_t *)lparam; | ||||
|         break; | ||||
| 
 | ||||
|       // control info field should be none
 | ||||
|       // but "writev" does not allow this
 | ||||
|       m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|     case UMSG_PEERERROR: // 1000 - Error Signal from the Peer Side
 | ||||
|         // Error type
 | ||||
|         m_nHeader[SRT_PH_MSGNO] = *lparam; | ||||
| 
 | ||||
|       break; | ||||
|         // control info field should be none
 | ||||
|         // but "writev" does not allow this
 | ||||
|         m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
| 
 | ||||
|    case UMSG_EXT: //0x7FFF - Reserved for user defined control packets
 | ||||
|       // for extended control packet
 | ||||
|       // "lparam" contains the extended type information for bit 16 - 31
 | ||||
|       // "rparam" is the control information
 | ||||
|       m_nHeader[SRT_PH_SEQNO] |= *(int32_t *)lparam; | ||||
|         break; | ||||
| 
 | ||||
|       if (NULL != rparam) | ||||
|       { | ||||
|          m_PacketVector[PV_DATA].set(rparam, size); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          m_PacketVector[PV_DATA].set((void *)&__pad, 4); | ||||
|       } | ||||
|     case UMSG_EXT: // 0x7FFF - Reserved for user defined control packets
 | ||||
|         // for extended control packet
 | ||||
|         // "lparam" contains the extended type information for bit 16 - 31
 | ||||
|         // "rparam" is the control information
 | ||||
|         m_nHeader[SRT_PH_SEQNO] |= *lparam; | ||||
| 
 | ||||
|       break; | ||||
|         if (NULL != rparam) | ||||
|         { | ||||
|             m_PacketVector[PV_DATA].set(rparam, size); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             m_PacketVector[PV_DATA].set((void*)&m_extra_pad, 4); | ||||
|         } | ||||
| 
 | ||||
|    default: | ||||
|       break; | ||||
|    } | ||||
|         break; | ||||
| 
 | ||||
|     default: | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| IOVector* CPacket::getPacketVector() | ||||
| void srt::CPacket::toNL() | ||||
| { | ||||
|    return m_PacketVector; | ||||
|     // XXX USE HtoNLA!
 | ||||
|     if (isControl()) | ||||
|     { | ||||
|         for (ptrdiff_t i = 0, n = getLength() / 4; i < n; ++i) | ||||
|             *((uint32_t*)m_pcData + i) = htonl(*((uint32_t*)m_pcData + i)); | ||||
|     } | ||||
| 
 | ||||
|     // convert packet header into network order
 | ||||
|     uint32_t* p = m_nHeader; | ||||
|     for (int j = 0; j < 4; ++j) | ||||
|     { | ||||
|         *p = htonl(*p); | ||||
|         ++p; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| UDTMessageType CPacket::getType() const | ||||
| void srt::CPacket::toHL() | ||||
| { | ||||
|     // convert back into local host order
 | ||||
|     uint32_t* p = m_nHeader; | ||||
|     for (int k = 0; k < 4; ++k) | ||||
|     { | ||||
|         *p = ntohl(*p); | ||||
|         ++p; | ||||
|     } | ||||
| 
 | ||||
|     if (isControl()) | ||||
|     { | ||||
|         for (ptrdiff_t l = 0, n = getLength() / 4; l < n; ++l) | ||||
|             *((uint32_t*)m_pcData + l) = ntohl(*((uint32_t*)m_pcData + l)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| srt::IOVector* srt::CPacket::getPacketVector() | ||||
| { | ||||
|     return m_PacketVector; | ||||
| } | ||||
| 
 | ||||
| srt::UDTMessageType srt::CPacket::getType() const | ||||
| { | ||||
|     return UDTMessageType(SEQNO_MSGTYPE::unwrap(m_nHeader[SRT_PH_SEQNO])); | ||||
| } | ||||
| 
 | ||||
| int CPacket::getExtendedType() const | ||||
| int srt::CPacket::getExtendedType() const | ||||
| { | ||||
|     return SEQNO_EXTTYPE::unwrap(m_nHeader[SRT_PH_SEQNO]); | ||||
| } | ||||
| 
 | ||||
| int32_t CPacket::getAckSeqNo() const | ||||
| int32_t srt::CPacket::getAckSeqNo() const | ||||
| { | ||||
|    // read additional information field
 | ||||
|    // This field is used only in UMSG_ACK and UMSG_ACKACK,
 | ||||
|    // so 'getAckSeqNo' symbolically defines the only use of it
 | ||||
|    // in case of CONTROL PACKET.
 | ||||
|    return m_nHeader[SRT_PH_MSGNO]; | ||||
|     // read additional information field
 | ||||
|     // This field is used only in UMSG_ACK and UMSG_ACKACK,
 | ||||
|     // so 'getAckSeqNo' symbolically defines the only use of it
 | ||||
|     // in case of CONTROL PACKET.
 | ||||
|     return m_nHeader[SRT_PH_MSGNO]; | ||||
| } | ||||
| 
 | ||||
| uint16_t CPacket::getControlFlags() const | ||||
| uint16_t srt::CPacket::getControlFlags() const | ||||
| { | ||||
|     // This returns exactly the "extended type" value,
 | ||||
|     // which is not used at all in case when the standard
 | ||||
|  | @ -360,19 +432,19 @@ uint16_t CPacket::getControlFlags() const | |||
|     return SEQNO_EXTTYPE::unwrap(m_nHeader[SRT_PH_SEQNO]); | ||||
| } | ||||
| 
 | ||||
| PacketBoundary CPacket::getMsgBoundary() const | ||||
| srt::PacketBoundary srt::CPacket::getMsgBoundary() const | ||||
| { | ||||
|     return PacketBoundary(MSGNO_PACKET_BOUNDARY::unwrap(m_nHeader[SRT_PH_MSGNO])); | ||||
| } | ||||
| 
 | ||||
| bool CPacket::getMsgOrderFlag() const | ||||
| bool srt::CPacket::getMsgOrderFlag() const | ||||
| { | ||||
|     return 0!=  MSGNO_PACKET_INORDER::unwrap(m_nHeader[SRT_PH_MSGNO]); | ||||
|     return 0 != MSGNO_PACKET_INORDER::unwrap(m_nHeader[SRT_PH_MSGNO]); | ||||
| } | ||||
| 
 | ||||
| int32_t CPacket::getMsgSeq(bool has_rexmit) const | ||||
| int32_t srt::CPacket::getMsgSeq(bool has_rexmit) const | ||||
| { | ||||
|     if ( has_rexmit ) | ||||
|     if (has_rexmit) | ||||
|     { | ||||
|         return MSGNO_SEQ::unwrap(m_nHeader[SRT_PH_MSGNO]); | ||||
|     } | ||||
|  | @ -382,13 +454,13 @@ int32_t CPacket::getMsgSeq(bool has_rexmit) const | |||
|     } | ||||
| } | ||||
| 
 | ||||
| bool CPacket::getRexmitFlag() const | ||||
| bool srt::CPacket::getRexmitFlag() const | ||||
| { | ||||
|     // return false; //
 | ||||
|     return 0 !=  MSGNO_REXMIT::unwrap(m_nHeader[SRT_PH_MSGNO]); | ||||
|     return 0 != MSGNO_REXMIT::unwrap(m_nHeader[SRT_PH_MSGNO]); | ||||
| } | ||||
| 
 | ||||
| EncryptionKeySpec CPacket::getMsgCryptoFlags() const | ||||
| srt::EncryptionKeySpec srt::CPacket::getMsgCryptoFlags() const | ||||
| { | ||||
|     return EncryptionKeySpec(MSGNO_ENCKEYSPEC::unwrap(m_nHeader[SRT_PH_MSGNO])); | ||||
| } | ||||
|  | @ -396,82 +468,31 @@ EncryptionKeySpec CPacket::getMsgCryptoFlags() const | |||
| // This is required as the encryption/decryption happens in place.
 | ||||
| // This is required to clear off the flags after decryption or set
 | ||||
| // crypto flags after encrypting a packet.
 | ||||
| void CPacket::setMsgCryptoFlags(EncryptionKeySpec spec) | ||||
| void srt::CPacket::setMsgCryptoFlags(EncryptionKeySpec spec) | ||||
| { | ||||
|     int32_t clr_msgno = m_nHeader[SRT_PH_MSGNO] & ~MSGNO_ENCKEYSPEC::mask; | ||||
|     int32_t clr_msgno       = m_nHeader[SRT_PH_MSGNO] & ~MSGNO_ENCKEYSPEC::mask; | ||||
|     m_nHeader[SRT_PH_MSGNO] = clr_msgno | EncryptionKeyBits(spec); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|    Leaving old code for historical reasons. This is moved to CSRTCC. | ||||
| EncryptionStatus CPacket::encrypt(HaiCrypt_Handle hcrypto) | ||||
| uint32_t srt::CPacket::getMsgTimeStamp() const | ||||
| { | ||||
|     if ( !hcrypto ) | ||||
|     { | ||||
|         LOGC(mglog.Error, log << "IPE: NULL crypto passed to CPacket::encrypt!"); | ||||
|         return ENCS_FAILED; | ||||
|     } | ||||
| 
 | ||||
|    int rc = HaiCrypt_Tx_Data(hcrypto, (uint8_t *)m_nHeader.raw(), (uint8_t *)m_pcData, m_PacketVector[PV_DATA].iov_len); | ||||
|    if ( rc < 0 ) | ||||
|    { | ||||
|        // -1: encryption failure
 | ||||
|        // 0: key not received yet
 | ||||
|        return ENCS_FAILED; | ||||
|    } else if (rc > 0) { | ||||
|        m_PacketVector[PV_DATA].iov_len = rc; | ||||
|    } | ||||
|    return ENCS_CLEAR; | ||||
|     // SRT_DEBUG_TSBPD_WRAP may enable smaller timestamp for faster wraparoud handling tests
 | ||||
|     return (uint32_t)m_nHeader[SRT_PH_TIMESTAMP] & TIMESTAMP_MASK; | ||||
| } | ||||
| 
 | ||||
| EncryptionStatus CPacket::decrypt(HaiCrypt_Handle hcrypto) | ||||
| srt::CPacket* srt::CPacket::clone() const | ||||
| { | ||||
|    if (getMsgCryptoFlags() == EK_NOENC) | ||||
|    { | ||||
|        //HLOGC(mglog.Debug, log << "CPacket::decrypt: packet not encrypted");
 | ||||
|        return ENCS_CLEAR; // not encrypted, no need do decrypt, no flags to be modified
 | ||||
|    } | ||||
|     CPacket* pkt = new CPacket; | ||||
|     memcpy((pkt->m_nHeader), m_nHeader, HDR_SIZE); | ||||
|     pkt->m_pcData = new char[m_PacketVector[PV_DATA].size()]; | ||||
|     memcpy((pkt->m_pcData), m_pcData, m_PacketVector[PV_DATA].size()); | ||||
|     pkt->m_PacketVector[PV_DATA].setLength(m_PacketVector[PV_DATA].size()); | ||||
| 
 | ||||
|    if (!hcrypto) | ||||
|    { | ||||
|         LOGC(mglog.Error, log << "IPE: NULL crypto passed to CPacket::decrypt!"); | ||||
|         return ENCS_FAILED; // "invalid argument" (leave encryption flags untouched)
 | ||||
|    } | ||||
| 
 | ||||
|    int rc = HaiCrypt_Rx_Data(hcrypto, (uint8_t *)m_nHeader.raw(), (uint8_t *)m_pcData, m_PacketVector[PV_DATA].iov_len); | ||||
|    if ( rc <= 0 ) | ||||
|    { | ||||
|        // -1: decryption failure
 | ||||
|        // 0: key not received yet
 | ||||
|        return ENCS_FAILED; | ||||
|    } | ||||
|    // Otherwise: rc == decrypted text length.
 | ||||
|    m_PacketVector[PV_DATA].iov_len = rc; // In case clr txt size is different from cipher txt
 | ||||
| 
 | ||||
|    // Decryption succeeded. Update flags.
 | ||||
|    m_nHeader[SRT_PH_MSGNO] &= ~MSGNO_ENCKEYSPEC::mask; // sets EK_NOENC to ENCKEYSPEC bits.
 | ||||
| 
 | ||||
|    return ENCS_CLEAR; | ||||
|     return pkt; | ||||
| } | ||||
| 
 | ||||
| */ | ||||
| 
 | ||||
| uint32_t CPacket::getMsgTimeStamp() const | ||||
| namespace srt | ||||
| { | ||||
|    // SRT_DEBUG_TSBPD_WRAP may enable smaller timestamp for faster wraparoud handling tests
 | ||||
|    return (uint32_t)m_nHeader[SRT_PH_TIMESTAMP] & TIMESTAMP_MASK; | ||||
| } | ||||
| 
 | ||||
| CPacket* CPacket::clone() const | ||||
| { | ||||
|    CPacket* pkt = new CPacket; | ||||
|    memcpy(pkt->m_nHeader, m_nHeader, HDR_SIZE); | ||||
|    pkt->m_pcData = new char[m_PacketVector[PV_DATA].size()]; | ||||
|    memcpy(pkt->m_pcData, m_pcData, m_PacketVector[PV_DATA].size()); | ||||
|    pkt->m_PacketVector[PV_DATA].setLength(m_PacketVector[PV_DATA].size()); | ||||
| 
 | ||||
|    return pkt; | ||||
| } | ||||
| 
 | ||||
| // Useful for debugging
 | ||||
| std::string PacketMessageFlagStr(uint32_t msgno_field) | ||||
|  | @ -480,10 +501,10 @@ std::string PacketMessageFlagStr(uint32_t msgno_field) | |||
| 
 | ||||
|     stringstream out; | ||||
| 
 | ||||
|     static const char* const boundary [] = { "PB_SUBSEQUENT", "PB_LAST", "PB_FIRST", "PB_SOLO" }; | ||||
|     static const char* const order [] = { "ORD_RELAXED", "ORD_REQUIRED" }; | ||||
|     static const char* const crypto [] = { "EK_NOENC", "EK_EVEN", "EK_ODD", "EK*ERROR" }; | ||||
|     static const char* const rexmit [] = { "SN_ORIGINAL", "SN_REXMIT" }; | ||||
|     static const char* const boundary[] = {"PB_SUBSEQUENT", "PB_LAST", "PB_FIRST", "PB_SOLO"}; | ||||
|     static const char* const order[]    = {"ORD_RELAXED", "ORD_REQUIRED"}; | ||||
|     static const char* const crypto[]   = {"EK_NOENC", "EK_EVEN", "EK_ODD", "EK*ERROR"}; | ||||
|     static const char* const rexmit[]   = {"SN_ORIGINAL", "SN_REXMIT"}; | ||||
| 
 | ||||
|     out << boundary[MSGNO_PACKET_BOUNDARY::unwrap(msgno_field)] << " "; | ||||
|     out << order[MSGNO_PACKET_INORDER::unwrap(msgno_field)] << " "; | ||||
|  | @ -492,3 +513,70 @@ std::string PacketMessageFlagStr(uint32_t msgno_field) | |||
| 
 | ||||
|     return out.str(); | ||||
| } | ||||
| 
 | ||||
| inline void SprintSpecialWord(std::ostream& os, int32_t val) | ||||
| { | ||||
|     if (val & LOSSDATA_SEQNO_RANGE_FIRST) | ||||
|         os << "<" << (val & (~LOSSDATA_SEQNO_RANGE_FIRST)) << ">"; | ||||
|     else | ||||
|         os << val; | ||||
| } | ||||
| 
 | ||||
| } // namespace srt
 | ||||
| 
 | ||||
| #if ENABLE_LOGGING | ||||
| std::string srt::CPacket::Info() | ||||
| { | ||||
|     std::ostringstream os; | ||||
|     os << "TARGET=@" << m_iID << " "; | ||||
| 
 | ||||
|     if (isControl()) | ||||
|     { | ||||
|         os << "CONTROL: size=" << getLength() << " type=" << MessageTypeStr(getType(), getExtendedType()); | ||||
| 
 | ||||
|         if (getType() == UMSG_HANDSHAKE) | ||||
|         { | ||||
|             os << " HS: "; | ||||
|             // For handshake we already have a parsing method
 | ||||
|             CHandShake hs; | ||||
|             hs.load_from(m_pcData, getLength()); | ||||
|             os << hs.show(); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // This is a value that some messages use for some purposes.
 | ||||
|             // The "ack seq no" is one of the purposes, used by UMSG_ACK and UMSG_ACKACK.
 | ||||
|             // This is simply the SRT_PH_MSGNO field used as a message number in data packets.
 | ||||
|             os << " ARG: 0x"; | ||||
|             os << std::hex << getAckSeqNo() << " "; | ||||
|             os << std::dec << getAckSeqNo(); | ||||
| 
 | ||||
|             // It would be nice to see the extended packet data, but this
 | ||||
|             // requires strictly a message-dependent interpreter. So let's simply
 | ||||
|             // display all numbers in the array with the following restrictions:
 | ||||
|             // - all data contained in the buffer are considered 32-bit integer
 | ||||
|             // - sign flag will be cleared before displaying, with additional mark
 | ||||
|             size_t   wordlen = getLength() / 4; // drop any remainder if present
 | ||||
|             int32_t* array   = (int32_t*)m_pcData; | ||||
|             os << " [ "; | ||||
|             for (size_t i = 0; i < wordlen; ++i) | ||||
|             { | ||||
|                 SprintSpecialWord(os, array[i]); | ||||
|                 os << " "; | ||||
|             } | ||||
|             os << "]"; | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         // It's hard to extract the information about peer's supported rexmit flag.
 | ||||
|         // This is only a log, nothing crucial, so we can risk displaying incorrect message number.
 | ||||
|         // Declaring that the peer supports rexmit flag cuts off the highest bit from
 | ||||
|         // the displayed number.
 | ||||
|         os << "DATA: size=" << getLength() << " " << BufferStamp(m_pcData, getLength()) << " #" << getMsgSeq(true) | ||||
|            << " %" << getSeqNo() << " " << MessageFlagStr(); | ||||
|     } | ||||
| 
 | ||||
|     return os.str(); | ||||
| } | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue