Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
e5ee62f1
提交
e5ee62f1
authored
2月 13, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use capitalized CamelCase for C++ classes.
上级
80d70719
隐藏空白字符变更
内嵌
并排
正在显示
34 个修改的文件
包含
740 行增加
和
746 行删除
+740
-746
DtlsTransport.h
worker/include/RTC/DtlsTransport.h
+30
-30
IceCandidate.h
worker/include/RTC/IceCandidate.h
+4
-4
IceServer.h
worker/include/RTC/IceServer.h
+15
-15
RtcpPacket.h
worker/include/RTC/RtcpPacket.h
+8
-8
RtpListener.h
worker/include/RTC/RtpListener.h
+2
-2
RtpPacket.h
worker/include/RTC/RtpPacket.h
+24
-24
SrtpSession.h
worker/include/RTC/SrtpSession.h
+9
-9
StunMessage.h
worker/include/RTC/StunMessage.h
+34
-34
TcpConnection.h
worker/include/RTC/TcpConnection.h
+8
-8
TcpServer.h
worker/include/RTC/TcpServer.h
+13
-13
Transport.h
worker/include/RTC/Transport.h
+40
-44
TransportTuple.h
worker/include/RTC/TransportTuple.h
+8
-8
UdpSocket.h
worker/include/RTC/UdpSocket.h
+8
-8
TcpConnection.h
worker/include/handles/TcpConnection.h
+15
-15
TcpServer.h
worker/include/handles/TcpServer.h
+14
-14
UdpSocket.h
worker/include/handles/UdpSocket.h
+12
-12
DtlsTransport.cpp
worker/src/RTC/DtlsTransport.cpp
+121
-121
IceCandidate.cpp
worker/src/RTC/IceCandidate.cpp
+2
-2
IceServer.cpp
worker/src/RTC/IceServer.cpp
+44
-44
Peer.cpp
worker/src/RTC/Peer.cpp
+1
-1
RtcpPacket.cpp
worker/src/RTC/RtcpPacket.cpp
+7
-7
RtpListener.cpp
worker/src/RTC/RtpListener.cpp
+2
-2
RtpPacket.cpp
worker/src/RTC/RtpPacket.cpp
+12
-12
RtpParameters.cpp
worker/src/RTC/RtpParameters.cpp
+0
-1
SrtpSession.cpp
worker/src/RTC/SrtpSession.cpp
+20
-20
StunMessage.cpp
worker/src/RTC/StunMessage.cpp
+33
-33
TcpConnection.cpp
worker/src/RTC/TcpConnection.cpp
+7
-7
TcpServer.cpp
worker/src/RTC/TcpServer.cpp
+36
-38
Transport.cpp
worker/src/RTC/Transport.cpp
+88
-86
UdpSocket.cpp
worker/src/RTC/UdpSocket.cpp
+31
-31
TcpConnection.cpp
worker/src/handles/TcpConnection.cpp
+26
-26
TcpServer.cpp
worker/src/handles/TcpServer.cpp
+33
-34
UdpSocket.cpp
worker/src/handles/UdpSocket.cpp
+24
-24
main.cpp
worker/src/main.cpp
+9
-9
没有找到文件。
worker/include/RTC/D
TLS
Transport.h
→
worker/include/RTC/D
tls
Transport.h
浏览文件 @
e5ee62f1
...
...
@@ -2,7 +2,7 @@
#define MS_RTC_DTLS_TRANSPORT_H
#include "common.h"
#include "RTC/S
RTP
Session.h"
#include "RTC/S
rtp
Session.h"
#include "handles/Timer.h"
#include <string>
#include <map>
...
...
@@ -15,7 +15,7 @@
namespace
RTC
{
class
D
TLS
Transport
:
class
D
tls
Transport
:
public
Timer
::
Listener
{
public
:
...
...
@@ -58,7 +58,7 @@ namespace RTC
private
:
struct
SrtpProfileMapEntry
{
RTC
::
S
RTP
Session
::
Profile
profile
;
RTC
::
S
rtp
Session
::
Profile
profile
;
const
char
*
name
;
};
...
...
@@ -69,24 +69,24 @@ namespace RTC
// DTLS is in the process of negotiating a secure connection. Incoming
// media can flow through.
// NOTE: The caller MUST NOT call any method during this callback.
virtual
void
onD
TLSConnecting
(
DTLS
Transport
*
dtlsTransport
)
=
0
;
virtual
void
onD
tlsConnecting
(
Dtls
Transport
*
dtlsTransport
)
=
0
;
// DTLS has completed negotiation of a secure connection (including DTLS-SRTP
// and remote fingerprint verification). Outgoing media can now flow through.
// NOTE: The caller MUST NOT call any method during this callback.
virtual
void
onD
TLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTP
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onD
tlsConnected
(
DtlsTransport
*
dtlsTransport
,
RTC
::
Srtp
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
// The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onD
TLSFailed
(
DTLS
Transport
*
dtlsTransport
)
=
0
;
virtual
void
onD
tlsFailed
(
Dtls
Transport
*
dtlsTransport
)
=
0
;
// The DTLS connection has been closed due to receipt of a close_notify alert.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onD
TLSClosed
(
DTLS
Transport
*
dtlsTransport
)
=
0
;
virtual
void
onD
tlsClosed
(
Dtls
Transport
*
dtlsTransport
)
=
0
;
// Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onOutgoingD
TLSData
(
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
virtual
void
onOutgoingD
tlsData
(
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
// DTLS application data received.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onD
TLSApplicationData
(
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
virtual
void
onD
tlsApplicationData
(
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
};
public
:
...
...
@@ -95,7 +95,7 @@ namespace RTC
static
Json
::
Value
&
GetLocalFingerprints
();
static
Role
StringToRole
(
std
::
string
role
);
static
FingerprintAlgorithm
GetFingerprintAlgorithm
(
std
::
string
fingerprint
);
static
bool
IsD
TLS
(
const
uint8_t
*
data
,
size_t
len
);
static
bool
IsD
tls
(
const
uint8_t
*
data
,
size_t
len
);
private
:
static
void
GenerateCertificateAndPrivateKey
();
...
...
@@ -114,14 +114,14 @@ namespace RTC
static
std
::
vector
<
SrtpProfileMapEntry
>
srtpProfiles
;
public
:
D
TLS
Transport
(
Listener
*
listener
);
virtual
~
D
TLS
Transport
();
D
tls
Transport
(
Listener
*
listener
);
virtual
~
D
tls
Transport
();
void
Close
();
void
Dump
();
void
Run
(
Role
localRole
);
void
SetRemoteFingerprint
(
Fingerprint
fingerprint
);
void
ProcessD
TLS
Data
(
const
uint8_t
*
data
,
size_t
len
);
void
ProcessD
tls
Data
(
const
uint8_t
*
data
,
size_t
len
);
DtlsState
GetState
();
Role
GetLocalRole
();
void
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
);
...
...
@@ -130,12 +130,12 @@ namespace RTC
bool
IsRunning
();
void
Reset
();
bool
CheckStatus
(
int
return_code
);
void
SendPendingOutgoingD
TLS
Data
();
void
SendPendingOutgoingD
tls
Data
();
bool
SetTimeout
();
void
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
void
ExtractS
RTPKeys
(
RTC
::
SRTP
Session
::
Profile
srtp_profile
);
RTC
::
S
RTPSession
::
Profile
GetNegotiatedSRTP
Profile
();
void
ExtractS
rtpKeys
(
RTC
::
Srtp
Session
::
Profile
srtp_profile
);
RTC
::
S
rtpSession
::
Profile
GetNegotiatedSrtp
Profile
();
/* Callbacks fired by OpenSSL events. */
public
:
...
...
@@ -164,35 +164,35 @@ namespace RTC
/* Inline static methods. */
inline
Json
::
Value
&
D
TLS
Transport
::
GetLocalFingerprints
()
Json
::
Value
&
D
tls
Transport
::
GetLocalFingerprints
()
{
return
D
TLS
Transport
::
localFingerprints
;
return
D
tls
Transport
::
localFingerprints
;
}
inline
D
TLSTransport
::
Role
DTLS
Transport
::
StringToRole
(
std
::
string
role
)
D
tlsTransport
::
Role
Dtls
Transport
::
StringToRole
(
std
::
string
role
)
{
auto
it
=
D
TLS
Transport
::
string2Role
.
find
(
role
);
auto
it
=
D
tls
Transport
::
string2Role
.
find
(
role
);
if
(
it
!=
D
TLS
Transport
::
string2Role
.
end
())
if
(
it
!=
D
tls
Transport
::
string2Role
.
end
())
return
it
->
second
;
else
return
D
TLS
Transport
::
Role
::
NONE
;
return
D
tls
Transport
::
Role
::
NONE
;
}
inline
D
TLSTransport
::
FingerprintAlgorithm
DTLS
Transport
::
GetFingerprintAlgorithm
(
std
::
string
fingerprint
)
D
tlsTransport
::
FingerprintAlgorithm
Dtls
Transport
::
GetFingerprintAlgorithm
(
std
::
string
fingerprint
)
{
auto
it
=
D
TLS
Transport
::
string2FingerprintAlgorithm
.
find
(
fingerprint
);
auto
it
=
D
tls
Transport
::
string2FingerprintAlgorithm
.
find
(
fingerprint
);
if
(
it
!=
D
TLS
Transport
::
string2FingerprintAlgorithm
.
end
())
if
(
it
!=
D
tls
Transport
::
string2FingerprintAlgorithm
.
end
())
return
it
->
second
;
else
return
D
TLS
Transport
::
FingerprintAlgorithm
::
NONE
;
return
D
tls
Transport
::
FingerprintAlgorithm
::
NONE
;
}
inline
bool
D
TLSTransport
::
IsDTLS
(
const
uint8_t
*
data
,
size_t
len
)
bool
D
tlsTransport
::
IsDtls
(
const
uint8_t
*
data
,
size_t
len
)
{
return
(
// Minimum DTLS record length is 13 bytes.
...
...
@@ -205,7 +205,7 @@ namespace RTC
/* Inline instance methods. */
inline
bool
D
TLS
Transport
::
IsRunning
()
bool
D
tls
Transport
::
IsRunning
()
{
switch
(
this
->
state
)
{
...
...
@@ -224,13 +224,13 @@ namespace RTC
}
inline
D
TLSTransport
::
DtlsState
DTLS
Transport
::
GetState
()
D
tlsTransport
::
DtlsState
Dtls
Transport
::
GetState
()
{
return
this
->
state
;
}
inline
D
TLSTransport
::
Role
DTLS
Transport
::
GetLocalRole
()
D
tlsTransport
::
Role
Dtls
Transport
::
GetLocalRole
()
{
return
this
->
localRole
;
}
...
...
worker/include/RTC/IceCandidate.h
浏览文件 @
e5ee62f1
...
...
@@ -2,8 +2,8 @@
#define MS_RTC_ICE_CANDIDATE_H
#include "common.h"
#include "RTC/U
DP
Socket.h"
#include "RTC/T
CP
Server.h"
#include "RTC/U
dp
Socket.h"
#include "RTC/T
cp
Server.h"
#include <string>
#include <json/json.h>
...
...
@@ -31,8 +31,8 @@ namespace RTC
};
public
:
IceCandidate
(
RTC
::
U
DP
Socket
*
udpSocket
,
uint32_t
priority
);
IceCandidate
(
RTC
::
T
CP
Server
*
tcpServer
,
uint32_t
priority
);
IceCandidate
(
RTC
::
U
dp
Socket
*
udpSocket
,
uint32_t
priority
);
IceCandidate
(
RTC
::
T
cp
Server
*
tcpServer
,
uint32_t
priority
);
Json
::
Value
toJson
();
...
...
worker/include/RTC/I
CE
Server.h
→
worker/include/RTC/I
ce
Server.h
浏览文件 @
e5ee62f1
#ifndef MS_RTC_I
CE
_SERVER_H
#define MS_RTC_I
CE
_SERVER_H
#ifndef MS_RTC_I
ce
_SERVER_H
#define MS_RTC_I
ce
_SERVER_H
#include "common.h"
#include "RTC/S
TUN
Message.h"
#include "RTC/S
tun
Message.h"
#include "RTC/TransportTuple.h"
#include <string>
#include <list>
namespace
RTC
{
class
I
CE
Server
class
I
ce
Server
{
public
:
enum
class
IceState
...
...
@@ -25,21 +25,21 @@ namespace RTC
{
public
:
/**
* These callbacks are guaranteed to be called before ProcessS
TUN
Message()
* These callbacks are guaranteed to be called before ProcessS
tun
Message()
* returns, so the given pointers are still usable.
*/
virtual
void
onOutgoingS
TUNMessage
(
ICEServer
*
iceServer
,
RTC
::
STUN
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onI
CESelectedTuple
(
ICE
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onI
CEConnected
(
ICE
Server
*
iceServer
)
=
0
;
virtual
void
onI
CECompleted
(
ICE
Server
*
iceServer
)
=
0
;
virtual
void
onI
CEDisconnected
(
ICE
Server
*
iceServer
)
=
0
;
virtual
void
onOutgoingS
tunMessage
(
IceServer
*
iceServer
,
RTC
::
Stun
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onI
ceSelectedTuple
(
Ice
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onI
ceConnected
(
Ice
Server
*
iceServer
)
=
0
;
virtual
void
onI
ceCompleted
(
Ice
Server
*
iceServer
)
=
0
;
virtual
void
onI
ceDisconnected
(
Ice
Server
*
iceServer
)
=
0
;
};
public
:
I
CE
Server
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
);
I
ce
Server
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
);
void
Close
();
void
ProcessS
TUNMessage
(
RTC
::
STUN
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
);
void
ProcessS
tunMessage
(
RTC
::
Stun
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
);
std
::
string
&
GetUsernameFragment
();
std
::
string
&
GetPassword
();
IceState
GetState
();
...
...
@@ -79,19 +79,19 @@ namespace RTC
/* Inline methods. */
inline
std
::
string
&
I
CE
Server
::
GetUsernameFragment
()
std
::
string
&
I
ce
Server
::
GetUsernameFragment
()
{
return
this
->
usernameFragment
;
}
inline
std
::
string
&
I
CE
Server
::
GetPassword
()
std
::
string
&
I
ce
Server
::
GetPassword
()
{
return
this
->
password
;
}
inline
I
CEServer
::
IceState
ICE
Server
::
GetState
()
I
ceServer
::
IceState
Ice
Server
::
GetState
()
{
return
this
->
state
;
}
...
...
worker/include/RTC/R
TCP
Packet.h
→
worker/include/RTC/R
tcp
Packet.h
浏览文件 @
e5ee62f1
...
...
@@ -5,7 +5,7 @@
namespace
RTC
{
class
R
TCP
Packet
class
R
tcp
Packet
{
public
:
/* Struct for RTCP common header. */
...
...
@@ -25,12 +25,12 @@ namespace RTC
};
public
:
static
bool
IsR
TCP
(
const
uint8_t
*
data
,
size_t
len
);
static
R
TCP
Packet
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
static
bool
IsR
tcp
(
const
uint8_t
*
data
,
size_t
len
);
static
R
tcp
Packet
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
public
:
R
TCP
Packet
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
);
~
R
TCP
Packet
();
R
tcp
Packet
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
);
~
R
tcp
Packet
();
const
uint8_t
*
GetRaw
();
size_t
GetLength
();
...
...
@@ -45,7 +45,7 @@ namespace RTC
/* Inline static methods. */
inline
bool
R
TCPPacket
::
IsRTCP
(
const
uint8_t
*
data
,
size_t
len
)
bool
R
tcpPacket
::
IsRtcp
(
const
uint8_t
*
data
,
size_t
len
)
{
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
...
...
@@ -65,13 +65,13 @@ namespace RTC
/* Inline instance methods. */
inline
const
uint8_t
*
R
TCP
Packet
::
GetRaw
()
const
uint8_t
*
R
tcp
Packet
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
R
TCP
Packet
::
GetLength
()
size_t
R
tcp
Packet
::
GetLength
()
{
return
this
->
length
;
}
...
...
worker/include/RTC/RtpListener.h
浏览文件 @
e5ee62f1
...
...
@@ -4,7 +4,7 @@
#include "common.h"
#include "RTC/RtpReceiver.h"
#include "RTC/RtpParameters.h"
#include "RTC/R
TP
Packet.h"
#include "RTC/R
tp
Packet.h"
#include <unordered_map>
#include <json/json.h>
...
...
@@ -19,7 +19,7 @@ namespace RTC
Json
::
Value
toJson
();
void
AddRtpReceiver
(
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RtpParameters
*
rtpParameters
);
void
RemoveRtpReceiver
(
RTC
::
RtpReceiver
*
rtpReceiver
);
RTC
::
RtpReceiver
*
GetRtpReceiver
(
RTC
::
R
TP
Packet
*
packet
);
RTC
::
RtpReceiver
*
GetRtpReceiver
(
RTC
::
R
tp
Packet
*
packet
);
private
:
// Others.
...
...
worker/include/RTC/R
TP
Packet.h
→
worker/include/RTC/R
tp
Packet.h
浏览文件 @
e5ee62f1
...
...
@@ -5,7 +5,7 @@
namespace
RTC
{
class
R
TP
Packet
class
R
tp
Packet
{
public
:
/* Struct for RTP header. */
...
...
@@ -40,12 +40,12 @@ namespace RTC
};
public
:
static
bool
IsR
TP
(
const
uint8_t
*
data
,
size_t
len
);
static
R
TP
Packet
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
static
bool
IsR
tp
(
const
uint8_t
*
data
,
size_t
len
);
static
R
tp
Packet
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
public
:
R
TP
Packet
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLen
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
);
~
R
TP
Packet
();
R
tp
Packet
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLen
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
);
~
R
tp
Packet
();
void
Dump
();
const
uint8_t
*
GetRaw
();
...
...
@@ -56,8 +56,8 @@ namespace RTC
void
SetMarker
(
bool
marker
);
uint16_t
GetSequenceNumber
();
uint32_t
GetTimestamp
();
uint32_t
GetS
SRC
();
void
SetS
SRC
(
uint32_t
ssrc
);
// TODO: yes?
uint32_t
GetS
src
();
void
SetS
src
(
uint32_t
ssrc
);
// TODO: yes?
bool
HasExtensionHeader
();
uint16_t
GetExtensionHeaderId
();
size_t
GetExtensionHeaderLength
();
...
...
@@ -82,9 +82,9 @@ namespace RTC
/* Inline static methods. */
inline
bool
R
TPPacket
::
IsRTP
(
const
uint8_t
*
data
,
size_t
len
)
bool
R
tpPacket
::
IsRtp
(
const
uint8_t
*
data
,
size_t
len
)
{
// NOTE: R
TCPPacket::IsRTCP
() must always be called before this method.
// NOTE: R
tcpPacket::IsRtcp
() must always be called before this method.
Header
*
header
=
(
Header
*
)
data
;
...
...
@@ -100,74 +100,74 @@ namespace RTC
/* Inline instance methods. */
inline
const
uint8_t
*
R
TP
Packet
::
GetRaw
()
const
uint8_t
*
R
tp
Packet
::
GetRaw
()
{
return
this
->
raw
;
}
inline
size_t
R
TP
Packet
::
GetLength
()
size_t
R
tp
Packet
::
GetLength
()
{
return
this
->
length
;
}
inline
uint8_t
R
TP
Packet
::
GetPayloadType
()
uint8_t
R
tp
Packet
::
GetPayloadType
()
{
return
this
->
header
->
payload_type
;
}
inline
void
R
TP
Packet
::
SetPayloadType
(
uint8_t
payload_type
)
void
R
tp
Packet
::
SetPayloadType
(
uint8_t
payload_type
)
{
this
->
header
->
payload_type
=
payload_type
;
}
inline
bool
R
TP
Packet
::
HasMarker
()
bool
R
tp
Packet
::
HasMarker
()
{
return
this
->
header
->
marker
;
}
inline
void
R
TP
Packet
::
SetMarker
(
bool
marker
)
void
R
tp
Packet
::
SetMarker
(
bool
marker
)
{
this
->
header
->
marker
=
marker
;
}
inline
uint16_t
R
TP
Packet
::
GetSequenceNumber
()
uint16_t
R
tp
Packet
::
GetSequenceNumber
()
{
return
(
uint16_t
)
ntohs
(
this
->
header
->
sequence_number
);
}
inline
uint32_t
R
TP
Packet
::
GetTimestamp
()
uint32_t
R
tp
Packet
::
GetTimestamp
()
{
return
(
uint32_t
)
ntohl
(
this
->
header
->
timestamp
);
}
inline
uint32_t
R
TPPacket
::
GetSSRC
()
uint32_t
R
tpPacket
::
GetSsrc
()
{
return
(
uint32_t
)
ntohl
(
this
->
header
->
ssrc
);
}
// TODO temp
inline
void
R
TPPacket
::
SetSSRC
(
uint32_t
ssrc
)
void
R
tpPacket
::
SetSsrc
(
uint32_t
ssrc
)
{
this
->
header
->
ssrc
=
htonl
(
ssrc
);
}
inline
bool
R
TP
Packet
::
HasExtensionHeader
()
bool
R
tp
Packet
::
HasExtensionHeader
()
{
return
(
this
->
extensionHeader
?
true
:
false
);
}
inline
uint16_t
R
TP
Packet
::
GetExtensionHeaderId
()
uint16_t
R
tp
Packet
::
GetExtensionHeaderId
()
{
if
(
this
->
extensionHeader
)
return
uint16_t
(
ntohs
(
this
->
extensionHeader
->
id
));
...
...
@@ -176,7 +176,7 @@ namespace RTC
}
inline
size_t
R
TP
Packet
::
GetExtensionHeaderLength
()
size_t
R
tp
Packet
::
GetExtensionHeaderLength
()
{
if
(
this
->
extensionHeader
)
return
size_t
(
ntohs
(
this
->
extensionHeader
->
length
)
*
4
);
...
...
@@ -185,13 +185,13 @@ namespace RTC
}
inline
uint8_t
*
R
TP
Packet
::
GetPayload
()
uint8_t
*
R
tp
Packet
::
GetPayload
()
{
return
this
->
payload
;
}
inline
size_t
R
TP
Packet
::
GetPayloadLength
()
size_t
R
tp
Packet
::
GetPayloadLength
()
{
return
this
->
payloadLength
;
}
...
...
worker/include/RTC/S
RTP
Session.h
→
worker/include/RTC/S
rtp
Session.h
浏览文件 @
e5ee62f1
...
...
@@ -7,7 +7,7 @@
namespace
RTC
{
class
S
RTP
Session
class
S
rtp
Session
{
public
:
enum
class
Profile
...
...
@@ -28,19 +28,19 @@ namespace RTC
static
void
ClassInit
();
// private:
// static void onS
RTP
Event(srtp_event_data_t* data);
// static void onS
rtp
Event(srtp_event_data_t* data);
private
:
static
uint8_t
encryptBuffer
[];
public
:
S
RTP
Session
(
Type
type
,
Profile
profile
,
uint8_t
*
key
,
size_t
key_len
);
~
S
RTP
Session
();
S
rtp
Session
(
Type
type
,
Profile
profile
,
uint8_t
*
key
,
size_t
key_len
);
~
S
rtp
Session
();
bool
EncryptR
TP
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptS
RTP
(
const
uint8_t
*
data
,
size_t
*
len
);
bool
EncryptR
TCP
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptS
RTCP
(
const
uint8_t
*
data
,
size_t
*
len
);
bool
EncryptR
tp
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptS
rtp
(
const
uint8_t
*
data
,
size_t
*
len
);
bool
EncryptR
tcp
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptS
rtcp
(
const
uint8_t
*
data
,
size_t
*
len
);
const
char
*
GetLastErrorDesc
();
void
Close
();
...
...
@@ -54,7 +54,7 @@ namespace RTC
/* Inline instance methods. */
inline
const
char
*
S
RTP
Session
::
GetLastErrorDesc
()
const
char
*
S
rtp
Session
::
GetLastErrorDesc
()
{
const
char
*
error_string
;
...
...
worker/include/RTC/S
TUN
Message.h
→
worker/include/RTC/S
tun
Message.h
浏览文件 @
e5ee62f1
...
...
@@ -6,7 +6,7 @@
namespace
RTC
{
class
S
TUN
Message
class
S
tun
Message
{
public
:
// STUN message class.
...
...
@@ -53,15 +53,15 @@ namespace RTC
};
public
:
static
bool
IsS
TUN
(
const
uint8_t
*
data
,
size_t
len
);
static
S
TUN
Message
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
static
bool
IsS
tun
(
const
uint8_t
*
data
,
size_t
len
);
static
S
tun
Message
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
private
:
static
const
uint8_t
magicCookie
[];
public
:
S
TUN
Message
(
Class
klass
,
Method
method
,
const
uint8_t
*
transactionId
,
const
uint8_t
*
raw
,
size_t
length
);
~
S
TUN
Message
();
S
tun
Message
(
Class
klass
,
Method
method
,
const
uint8_t
*
transactionId
,
const
uint8_t
*
raw
,
size_t
length
);
~
S
tun
Message
();
void
Dump
();
Class
GetClass
();
...
...
@@ -87,8 +87,8 @@ namespace RTC
bool
HasMessageIntegrity
();
bool
HasFingerprint
();
Authentication
CheckAuthentication
(
const
std
::
string
&
local_username
,
const
std
::
string
&
local_password
);
S
TUN
Message
*
CreateSuccessResponse
();
S
TUN
Message
*
CreateErrorResponse
(
uint16_t
errorCode
);
S
tun
Message
*
CreateSuccessResponse
();
S
tun
Message
*
CreateErrorResponse
(
uint16_t
errorCode
);
void
Authenticate
(
const
std
::
string
&
password
);
void
Serialize
();
...
...
@@ -117,7 +117,7 @@ namespace RTC
/* Inline methods. */
inline
bool
S
TUNMessage
::
IsSTUN
(
const
uint8_t
*
data
,
size_t
len
)
bool
S
tunMessage
::
IsStun
(
const
uint8_t
*
data
,
size_t
len
)
{
return
(
// STUN headers are 20 bytes.
...
...
@@ -125,147 +125,147 @@ namespace RTC
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
<
20
)
&&
// Magic cookie must match.
(
data
[
4
]
==
S
TUN
Message
::
magicCookie
[
0
])
&&
(
data
[
5
]
==
S
TUN
Message
::
magicCookie
[
1
])
&&
(
data
[
6
]
==
S
TUN
Message
::
magicCookie
[
2
])
&&
(
data
[
7
]
==
S
TUN
Message
::
magicCookie
[
3
])
(
data
[
4
]
==
S
tun
Message
::
magicCookie
[
0
])
&&
(
data
[
5
]
==
S
tun
Message
::
magicCookie
[
1
])
&&
(
data
[
6
]
==
S
tun
Message
::
magicCookie
[
2
])
&&
(
data
[
7
]
==
S
tun
Message
::
magicCookie
[
3
])
);
}
inline
S
TUNMessage
::
Class
STUN
Message
::
GetClass
()
S
tunMessage
::
Class
Stun
Message
::
GetClass
()
{
return
this
->
klass
;
}
inline
S
TUNMessage
::
Method
STUN
Message
::
GetMethod
()
S
tunMessage
::
Method
Stun
Message
::
GetMethod
()
{
return
this
->
method
;
}
inline
const
uint8_t
*
S
TUN
Message
::
GetRaw
()
const
uint8_t
*
S
tun
Message
::
GetRaw
()
{
return
this
->
raw
;
}
inline
void
S
TUN
Message
::
SetLength
(
size_t
length
)
void
S
tun
Message
::
SetLength
(
size_t
length
)
{
this
->
length
=
length
;
}
inline
size_t
S
TUN
Message
::
GetLength
()
size_t
S
tun
Message
::
GetLength
()
{
return
this
->
length
;
}
inline
void
S
TUN
Message
::
SetUsername
(
const
char
*
username
,
size_t
len
)
void
S
tun
Message
::
SetUsername
(
const
char
*
username
,
size_t
len
)
{
if
(
this
->
username
.
empty
())
this
->
username
=
std
::
string
(
username
,
len
);
}
inline
void
S
TUN
Message
::
SetPriority
(
const
uint32_t
priority
)
void
S
tun
Message
::
SetPriority
(
const
uint32_t
priority
)
{
if
(
!
this
->
priority
)
this
->
priority
=
priority
;
}
inline
void
S
TUN
Message
::
SetIceControlling
(
const
uint64_t
iceControlling
)
void
S
tun
Message
::
SetIceControlling
(
const
uint64_t
iceControlling
)
{
if
(
!
this
->
iceControlling
)
this
->
iceControlling
=
iceControlling
;
}
inline
void
S
TUN
Message
::
SetIceControlled
(
const
uint64_t
iceControlled
)
void
S
tun
Message
::
SetIceControlled
(
const
uint64_t
iceControlled
)
{
if
(
!
this
->
iceControlled
)
this
->
iceControlled
=
iceControlled
;
}
inline
void
S
TUN
Message
::
SetUseCandidate
()
void
S
tun
Message
::
SetUseCandidate
()
{
this
->
hasUseCandidate
=
true
;
}
inline
void
S
TUN
Message
::
SetXorMappedAddress
(
const
struct
sockaddr
*
xorMappedAddress
)
void
S
tun
Message
::
SetXorMappedAddress
(
const
struct
sockaddr
*
xorMappedAddress
)
{
if
(
!
this
->
xorMappedAddress
)
this
->
xorMappedAddress
=
xorMappedAddress
;
}
inline
void
S
TUN
Message
::
SetErrorCode
(
uint16_t
errorCode
)
void
S
tun
Message
::
SetErrorCode
(
uint16_t
errorCode
)
{
this
->
errorCode
=
errorCode
;
}
inline
void
S
TUN
Message
::
SetMessageIntegrity
(
const
uint8_t
*
messageIntegrity
)
void
S
tun
Message
::
SetMessageIntegrity
(
const
uint8_t
*
messageIntegrity
)
{
if
(
!
this
->
messageIntegrity
)
this
->
messageIntegrity
=
messageIntegrity
;
}
inline
void
S
TUN
Message
::
SetFingerprint
()
void
S
tun
Message
::
SetFingerprint
()
{
this
->
hasFingerprint
=
true
;
}
inline
const
std
::
string
&
S
TUN
Message
::
GetUsername
()
const
std
::
string
&
S
tun
Message
::
GetUsername
()
{
return
this
->
username
;
}
inline
const
uint32_t
S
TUN
Message
::
GetPriority
()
const
uint32_t
S
tun
Message
::
GetPriority
()
{
return
this
->
priority
;
}
inline
const
uint64_t
S
TUN
Message
::
GetIceControlling
()
const
uint64_t
S
tun
Message
::
GetIceControlling
()
{
return
this
->
iceControlling
;
}
inline
const
uint64_t
S
TUN
Message
::
GetIceControlled
()
const
uint64_t
S
tun
Message
::
GetIceControlled
()
{
return
this
->
iceControlled
;
}
inline
bool
S
TUN
Message
::
HasUseCandidate
()
bool
S
tun
Message
::
HasUseCandidate
()
{
return
this
->
hasUseCandidate
;
}
inline
uint16_t
S
TUN
Message
::
GetErrorCode
()
uint16_t
S
tun
Message
::
GetErrorCode
()
{
return
this
->
errorCode
;
}
inline
bool
S
TUN
Message
::
HasMessageIntegrity
()
bool
S
tun
Message
::
HasMessageIntegrity
()
{
return
(
this
->
messageIntegrity
?
true
:
false
);
}
inline
bool
S
TUN
Message
::
HasFingerprint
()
bool
S
tun
Message
::
HasFingerprint
()
{
return
this
->
hasFingerprint
;
}
...
...
worker/include/RTC/T
CP
Connection.h
→
worker/include/RTC/T
cp
Connection.h
浏览文件 @
e5ee62f1
...
...
@@ -2,29 +2,29 @@
#define MS_RTC_TCP_CONNECTION_H
#include "common.h"
#include "handles/T
CP
Connection.h"
#include "handles/T
cp
Connection.h"
namespace
RTC
{
class
T
CP
Connection
:
public
::
T
CP
Connection
class
T
cp
Connection
:
public
::
T
cp
Connection
{
public
:
class
Listener
{
public
:
virtual
void
onPacketRecv
(
RTC
::
T
CP
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
virtual
void
onPacketRecv
(
RTC
::
T
cp
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
};
public
:
T
CP
Connection
(
Listener
*
listener
,
size_t
bufferSize
);
virtual
~
T
CP
Connection
();
T
cp
Connection
(
Listener
*
listener
,
size_t
bufferSize
);
virtual
~
T
cp
Connection
();
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
/* Pure virtual methods inherited from ::T
CP
Connection. */
/* Pure virtual methods inherited from ::T
cp
Connection. */
public
:
virtual
void
userOnT
CP
ConnectionRead
()
override
;
virtual
void
userOnT
cp
ConnectionRead
()
override
;
private
:
// Passed by argument.
...
...
worker/include/RTC/T
CP
Server.h
→
worker/include/RTC/T
cp
Server.h
浏览文件 @
e5ee62f1
...
...
@@ -2,22 +2,22 @@
#define MS_RTC_TCP_SERVER_H
#include "common.h"
#include "handles/T
CP
Server.h"
#include "handles/T
CP
Connection.h"
#include "RTC/T
CP
Connection.h"
#include "handles/T
cp
Server.h"
#include "handles/T
cp
Connection.h"
#include "RTC/T
cp
Connection.h"
#include <unordered_map>
#include <uv.h>
namespace
RTC
{
class
T
CP
Server
:
public
::
T
CP
Server
class
T
cp
Server
:
public
::
T
cp
Server
{
public
:
class
Listener
{
public
:
virtual
void
onR
TCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
onR
tcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
public
:
...
...
@@ -35,19 +35,19 @@ namespace RTC
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv6Ports
;
public
:
T
CPServer
(
Listener
*
listener
,
RTC
::
TCP
Connection
::
Listener
*
connListener
,
int
address_family
);
T
cpServer
(
Listener
*
listener
,
RTC
::
Tcp
Connection
::
Listener
*
connListener
,
int
address_family
);
/* Pure virtual methods inherited from ::T
CP
Server. */
/* Pure virtual methods inherited from ::T
cp
Server. */
public
:
virtual
void
userOnT
CPConnectionAlloc
(
::
TCP
Connection
**
connection
)
override
;
virtual
void
userOnNewT
CPConnection
(
::
TCP
Connection
*
connection
)
override
;
virtual
void
userOnT
CPConnectionClosed
(
::
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnT
CP
ServerClosed
()
override
;
virtual
void
userOnT
cpConnectionAlloc
(
::
Tcp
Connection
**
connection
)
override
;
virtual
void
userOnNewT
cpConnection
(
::
Tcp
Connection
*
connection
)
override
;
virtual
void
userOnT
cpConnectionClosed
(
::
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnT
cp
ServerClosed
()
override
;
private
:
// Passed by argument.
Listener
*
listener
=
nullptr
;
RTC
::
T
CP
Connection
::
Listener
*
connListener
=
nullptr
;
RTC
::
T
cp
Connection
::
Listener
*
connListener
=
nullptr
;
};
}
...
...
worker/include/RTC/Transport.h
浏览文件 @
e5ee62f1
...
...
@@ -2,18 +2,15 @@
#define MS_RTC_TRANSPORT_H
#include "common.h"
#include "RTC/U
DP
Socket.h"
#include "RTC/T
CP
Server.h"
#include "RTC/T
CP
Connection.h"
#include "RTC/U
dp
Socket.h"
#include "RTC/T
cp
Server.h"
#include "RTC/T
cp
Connection.h"
#include "RTC/IceCandidate.h"
#include "RTC/I
CE
Server.h"
#include "RTC/S
TUN
Message.h"
#include "RTC/I
ce
Server.h"
#include "RTC/S
tun
Message.h"
#include "RTC/TransportTuple.h"
#include "RTC/DTLSTransport.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/DtlsTransport.h"
#include "RTC/RtpListener.h"
#include "RTC/RtpReceiver.h" // TODO: let's see if needed here or not
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include <string>
...
...
@@ -24,12 +21,11 @@
namespace
RTC
{
class
Transport
:
public
RTC
::
UDPSocket
::
Listener
,
public
RTC
::
TCPServer
::
Listener
,
public
RTC
::
TCPConnection
::
Listener
,
public
RTC
::
ICEServer
::
Listener
,
public
RTC
::
DTLSTransport
::
Listener
,
// Transport is also a RtpListener.
public
RTC
::
UdpSocket
::
Listener
,
public
RTC
::
TcpServer
::
Listener
,
public
RTC
::
TcpConnection
::
Listener
,
public
RTC
::
IceServer
::
Listener
,
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
RtpListener
{
public
:
...
...
@@ -48,44 +44,44 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
private
:
void
MayRunD
TLS
Transport
();
void
MayRunD
tls
Transport
();
/* Private methods to unify UDP and TCP behavior. */
private
:
void
onPacketRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onS
TUN
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onD
TLS
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onR
TP
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onR
TCP
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onS
tun
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onD
tls
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onR
tp
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onR
tcp
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
/* Pure virtual methods inherited from RTC::U
DP
Socket::Listener. */
/* Pure virtual methods inherited from RTC::U
dp
Socket::Listener. */
public
:
virtual
void
onPacketRecv
(
RTC
::
U
DP
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
override
;
virtual
void
onPacketRecv
(
RTC
::
U
dp
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
override
;
/* Pure virtual methods inherited from RTC::T
CP
Server::Listener. */
/* Pure virtual methods inherited from RTC::T
cp
Server::Listener. */
public
:
virtual
void
onR
TCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
onR
tcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
override
;
/* Pure virtual methods inherited from RTC::T
CP
Connection::Listener. */
/* Pure virtual methods inherited from RTC::T
cp
Connection::Listener. */
public
:
virtual
void
onPacketRecv
(
RTC
::
T
CP
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
override
;
virtual
void
onPacketRecv
(
RTC
::
T
cp
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
override
;
/* Pure virtual methods inherited from RTC::I
CE
Server::Listener. */
/* Pure virtual methods inherited from RTC::I
ce
Server::Listener. */
public
:
virtual
void
onOutgoingS
TUNMessage
(
RTC
::
ICEServer
*
iceServer
,
RTC
::
STUN
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onI
CESelectedTuple
(
ICE
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onI
CEConnected
(
ICE
Server
*
iceServer
)
override
;
virtual
void
onI
CECompleted
(
ICE
Server
*
iceServer
)
override
;
virtual
void
onI
CEDisconnected
(
ICE
Server
*
iceServer
)
override
;
virtual
void
onOutgoingS
tunMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
Stun
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onI
ceSelectedTuple
(
Ice
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onI
ceConnected
(
Ice
Server
*
iceServer
)
override
;
virtual
void
onI
ceCompleted
(
Ice
Server
*
iceServer
)
override
;
virtual
void
onI
ceDisconnected
(
Ice
Server
*
iceServer
)
override
;
/* Pure virtual methods inherited from RTC::D
TLS
Transport::Listener. */
/* Pure virtual methods inherited from RTC::D
tls
Transport::Listener. */
public
:
virtual
void
onD
TLSConnecting
(
DTLS
Transport
*
dtlsTransport
)
override
;
virtual
void
onD
TLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTP
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
override
;
virtual
void
onD
TLSFailed
(
DTLS
Transport
*
dtlsTransport
)
override
;
virtual
void
onD
TLSClosed
(
DTLS
Transport
*
dtlsTransport
)
override
;
virtual
void
onOutgoingD
TLSData
(
RTC
::
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
virtual
void
onD
TLSApplicationData
(
RTC
::
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
virtual
void
onD
tlsConnecting
(
Dtls
Transport
*
dtlsTransport
)
override
;
virtual
void
onD
tlsConnected
(
DtlsTransport
*
dtlsTransport
,
RTC
::
Srtp
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
override
;
virtual
void
onD
tlsFailed
(
Dtls
Transport
*
dtlsTransport
)
override
;
virtual
void
onD
tlsClosed
(
Dtls
Transport
*
dtlsTransport
)
override
;
virtual
void
onOutgoingD
tlsData
(
RTC
::
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
virtual
void
onD
tlsApplicationData
(
RTC
::
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
public
:
// Passed by argument.
...
...
@@ -96,10 +92,10 @@ namespace RTC
Listener
*
listener
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
// Allocated by this.
RTC
::
I
CE
Server
*
iceServer
=
nullptr
;
std
::
vector
<
RTC
::
U
DP
Socket
*>
udpSockets
;
std
::
vector
<
RTC
::
T
CP
Server
*>
tcpServers
;
RTC
::
D
TLS
Transport
*
dtlsTransport
=
nullptr
;
RTC
::
I
ce
Server
*
iceServer
=
nullptr
;
std
::
vector
<
RTC
::
U
dp
Socket
*>
udpSockets
;
std
::
vector
<
RTC
::
T
cp
Server
*>
tcpServers
;
RTC
::
D
tls
Transport
*
dtlsTransport
=
nullptr
;
// Others.
bool
allocated
=
false
;
// Others (ICE).
...
...
@@ -107,7 +103,7 @@ namespace RTC
RTC
::
TransportTuple
*
selectedTuple
=
nullptr
;
// Others (DTLS).
bool
remoteDtlsParametersGiven
=
false
;
RTC
::
D
TLSTransport
::
Role
dtlsLocalRole
=
RTC
::
DTLS
Transport
::
Role
::
AUTO
;
RTC
::
D
tlsTransport
::
Role
dtlsLocalRole
=
RTC
::
Dtls
Transport
::
Role
::
AUTO
;
};
}
...
...
worker/include/RTC/TransportTuple.h
浏览文件 @
e5ee62f1
...
...
@@ -2,8 +2,8 @@
#define MS_RTC_TRANSPORT_TUPLE_H
#include "common.h"
#include "RTC/U
DP
Socket.h"
#include "RTC/T
CP
Connection.h"
#include "RTC/U
dp
Socket.h"
#include "RTC/T
cp
Connection.h"
#include "Utils.h"
#include <json/json.h>
...
...
@@ -19,8 +19,8 @@ namespace RTC
};
public
:
TransportTuple
(
RTC
::
U
DP
Socket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportTuple
(
RTC
::
T
CP
Connection
*
tcpConnection
);
TransportTuple
(
RTC
::
U
dp
Socket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportTuple
(
RTC
::
T
cp
Connection
*
tcpConnection
);
void
Close
();
Json
::
Value
toJson
();
...
...
@@ -34,10 +34,10 @@ namespace RTC
private
:
// Passed by argument.
RTC
::
U
DP
Socket
*
udpSocket
=
nullptr
;
RTC
::
U
dp
Socket
*
udpSocket
=
nullptr
;
struct
sockaddr
*
udpRemoteAddr
=
nullptr
;
sockaddr_storage
udpRemoteAddrStorage
;
RTC
::
T
CP
Connection
*
tcpConnection
=
nullptr
;
RTC
::
T
cp
Connection
*
tcpConnection
=
nullptr
;
// Others.
Protocol
protocol
;
};
...
...
@@ -52,14 +52,14 @@ namespace RTC
}
inline
TransportTuple
::
TransportTuple
(
RTC
::
U
DP
Socket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
TransportTuple
::
TransportTuple
(
RTC
::
U
dp
Socket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
udpSocket
(
udpSocket
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
protocol
(
Protocol
::
UDP
)
{}
inline
TransportTuple
::
TransportTuple
(
RTC
::
T
CP
Connection
*
tcpConnection
)
:
TransportTuple
::
TransportTuple
(
RTC
::
T
cp
Connection
*
tcpConnection
)
:
tcpConnection
(
tcpConnection
),
protocol
(
Protocol
::
TCP
)
{}
...
...
worker/include/RTC/U
DP
Socket.h
→
worker/include/RTC/U
dp
Socket.h
浏览文件 @
e5ee62f1
...
...
@@ -2,20 +2,20 @@
#define MS_RTC_UDP_SOCKET_H
#include "common.h"
#include "handles/U
DP
Socket.h"
#include "handles/U
dp
Socket.h"
#include <unordered_map>
#include <uv.h>
namespace
RTC
{
class
U
DP
Socket
:
public
::
U
DP
Socket
class
U
dp
Socket
:
public
::
U
dp
Socket
{
public
:
class
Listener
{
public
:
virtual
void
onPacketRecv
(
RTC
::
U
DP
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onPacketRecv
(
RTC
::
U
dp
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
};
public
:
...
...
@@ -33,12 +33,12 @@ namespace RTC
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv6Ports
;
public
:
U
DP
Socket
(
Listener
*
listener
,
int
address_family
);
U
dp
Socket
(
Listener
*
listener
,
int
address_family
);
/* Pure virtual methods inherited from ::U
DP
Socket. */
/* Pure virtual methods inherited from ::U
dp
Socket. */
public
:
virtual
void
userOnU
DP
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnU
DP
SocketClosed
()
override
;
virtual
void
userOnU
dp
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnU
dp
SocketClosed
()
override
;
private
:
// Passed by argument.
...
...
worker/include/handles/T
CP
Connection.h
→
worker/include/handles/T
cp
Connection.h
浏览文件 @
e5ee62f1
...
...
@@ -5,27 +5,27 @@
#include <string>
#include <uv.h>
class
T
CP
Connection
class
T
cp
Connection
{
public
:
class
Listener
{
public
:
virtual
void
onT
CPConnectionClosed
(
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
onT
cpConnectionClosed
(
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
public
:
/* Struct for the data field of uv_req_t when writing into the connection. */
struct
UvWriteData
{
T
CP
Connection
*
connection
;
T
cp
Connection
*
connection
;
uv_write_t
req
;
uint8_t
store
[
1
];
};
public
:
T
CP
Connection
(
size_t
bufferSize
);
virtual
~
T
CP
Connection
();
T
cp
Connection
(
size_t
bufferSize
);
virtual
~
T
cp
Connection
();
void
Close
();
virtual
void
Dump
();
...
...
@@ -56,7 +56,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
virtual
void
userOnT
CP
ConnectionRead
()
=
0
;
virtual
void
userOnT
cp
ConnectionRead
()
=
0
;
private
:
// Passed by argument.
...
...
@@ -86,55 +86,55 @@ protected:
/* Inline methods. */
inline
bool
T
CP
Connection
::
IsClosing
()
bool
T
cp
Connection
::
IsClosing
()
{
return
this
->
isClosing
;
}
inline
uv_tcp_t
*
T
CP
Connection
::
GetUvHandle
()
uv_tcp_t
*
T
cp
Connection
::
GetUvHandle
()
{
return
this
->
uvHandle
;
}
inline
void
T
CP
Connection
::
Write
(
const
std
::
string
&
data
)
void
T
cp
Connection
::
Write
(
const
std
::
string
&
data
)
{
Write
((
const
uint8_t
*
)
data
.
c_str
(),
data
.
size
());
}
inline
const
struct
sockaddr
*
T
CP
Connection
::
GetLocalAddress
()
const
struct
sockaddr
*
T
cp
Connection
::
GetLocalAddress
()
{
return
(
const
struct
sockaddr
*
)
this
->
localAddr
;
}
inline
const
std
::
string
&
T
CP
Connection
::
GetLocalIP
()
const
std
::
string
&
T
cp
Connection
::
GetLocalIP
()
{
return
this
->
localIP
;
}
inline
uint16_t
T
CP
Connection
::
GetLocalPort
()
uint16_t
T
cp
Connection
::
GetLocalPort
()
{
return
this
->
localPort
;
}
inline
const
struct
sockaddr
*
T
CP
Connection
::
GetPeerAddress
()
const
struct
sockaddr
*
T
cp
Connection
::
GetPeerAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
peerAddr
;
}
inline
const
std
::
string
&
T
CP
Connection
::
GetPeerIP
()
const
std
::
string
&
T
cp
Connection
::
GetPeerIP
()
{
return
this
->
peerIP
;
}
inline
uint16_t
T
CP
Connection
::
GetPeerPort
()
uint16_t
T
cp
Connection
::
GetPeerPort
()
{
return
this
->
peerPort
;
}
...
...
worker/include/handles/T
CP
Server.h
→
worker/include/handles/T
cp
Server.h
浏览文件 @
e5ee62f1
...
...
@@ -2,20 +2,20 @@
#define MS_TCP_SERVER_H
#include "common.h"
#include "handles/T
CP
Connection.h"
#include "handles/T
cp
Connection.h"
#include <string>
#include <unordered_set>
#include <uv.h>
class
T
CPServer
:
public
TCP
Connection
::
Listener
class
T
cpServer
:
public
Tcp
Connection
::
Listener
{
public
:
T
CP
Server
(
const
std
::
string
&
ip
,
uint16_t
port
,
int
backlog
);
T
cp
Server
(
const
std
::
string
&
ip
,
uint16_t
port
,
int
backlog
);
/**
* uvHandle must be an already initialized and binded uv_tcp_t pointer.
*/
T
CP
Server
(
uv_tcp_t
*
uvHandle
,
int
backlog
);
virtual
~
T
CP
Server
();
T
cp
Server
(
uv_tcp_t
*
uvHandle
,
int
backlog
);
virtual
~
T
cp
Server
();
void
Close
();
virtual
void
Dump
();
...
...
@@ -30,25 +30,25 @@ private:
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
virtual
void
userOnT
CPConnectionAlloc
(
TCP
Connection
**
connection
)
=
0
;
virtual
void
userOnNewT
CPConnection
(
TCP
Connection
*
connection
)
=
0
;
virtual
void
userOnT
CPConnectionClosed
(
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnT
CP
ServerClosed
()
=
0
;
virtual
void
userOnT
cpConnectionAlloc
(
Tcp
Connection
**
connection
)
=
0
;
virtual
void
userOnNewT
cpConnection
(
Tcp
Connection
*
connection
)
=
0
;
virtual
void
userOnT
cpConnectionClosed
(
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnT
cp
ServerClosed
()
=
0
;
/* Callbacks fired by UV events. */
public
:
void
onUvConnection
(
int
status
);
void
onUvClosed
();
/* Methods inherited from T
CP
Connection::Listener. */
/* Methods inherited from T
cp
Connection::Listener. */
public
:
virtual
void
onT
CPConnectionClosed
(
TCP
Connection
*
connection
,
bool
is_closed_by_peer
);
virtual
void
onT
cpConnectionClosed
(
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
);
private
:
// Allocated by this (may be passed by argument).
uv_tcp_t
*
uvHandle
=
nullptr
;
// Others.
std
::
unordered_set
<
T
CP
Connection
*>
connections
;
std
::
unordered_set
<
T
cp
Connection
*>
connections
;
bool
isClosing
=
false
;
protected
:
...
...
@@ -60,13 +60,13 @@ protected:
/* Inline methods. */
inline
bool
T
CP
Server
::
IsClosing
()
bool
T
cp
Server
::
IsClosing
()
{
return
this
->
isClosing
;
}
inline
size_t
T
CP
Server
::
GetNumConnections
()
size_t
T
cp
Server
::
GetNumConnections
()
{
return
this
->
connections
.
size
();
}
...
...
worker/include/handles/U
DP
Socket.h
→
worker/include/handles/U
dp
Socket.h
浏览文件 @
e5ee62f1
...
...
@@ -5,13 +5,13 @@
#include <string>
#include <uv.h>
class
U
DP
Socket
class
U
dp
Socket
{
public
:
/* Struct for the data field of uv_req_t when sending a datagram. */
struct
UvSendData
{
U
DP
Socket
*
socket
;
U
dp
Socket
*
socket
;
uv_udp_send_t
req
;
uint8_t
store
[
1
];
};
...
...
@@ -20,12 +20,12 @@ private:
static
uint8_t
readBuffer
[];
public
:
U
DP
Socket
(
const
std
::
string
&
ip
,
uint16_t
port
);
U
dp
Socket
(
const
std
::
string
&
ip
,
uint16_t
port
);
/**
* uvHandle must be an already initialized and binded uv_udp_t pointer.
*/
U
DP
Socket
(
uv_udp_t
*
uvHandle
);
virtual
~
U
DP
Socket
();
U
dp
Socket
(
uv_udp_t
*
uvHandle
);
virtual
~
U
dp
Socket
();
void
Close
();
virtual
void
Dump
();
...
...
@@ -49,8 +49,8 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
virtual
void
userOnU
DP
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
=
0
;
virtual
void
userOnU
DP
SocketClosed
()
=
0
;
virtual
void
userOnU
dp
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
=
0
;
virtual
void
userOnU
dp
SocketClosed
()
=
0
;
private
:
// Allocated by this (may be passed by argument).
...
...
@@ -67,31 +67,31 @@ protected:
/* Inline methods. */
inline
void
U
DP
Socket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
void
U
dp
Socket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
{
Send
((
const
uint8_t
*
)
data
.
c_str
(),
data
.
size
(),
addr
);
}
inline
void
U
DP
Socket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
uint16_t
port
)
void
U
dp
Socket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
uint16_t
port
)
{
Send
((
const
uint8_t
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
}
inline
const
struct
sockaddr
*
U
DP
Socket
::
GetLocalAddress
()
const
struct
sockaddr
*
U
dp
Socket
::
GetLocalAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
localAddr
;
}
inline
const
std
::
string
&
U
DP
Socket
::
GetLocalIP
()
const
std
::
string
&
U
dp
Socket
::
GetLocalIP
()
{
return
this
->
localIP
;
}
inline
uint16_t
U
DP
Socket
::
GetLocalPort
()
uint16_t
U
dp
Socket
::
GetLocalPort
()
{
return
this
->
localPort
;
}
...
...
worker/src/RTC/D
TLS
Transport.cpp
→
worker/src/RTC/D
tls
Transport.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::D
TLS
Transport"
#define MS_CLASS "RTC::D
tls
Transport"
#include "RTC/D
TLS
Transport.h"
#include "RTC/D
tls
Transport.h"
#include "Settings.h"
#include "Utils.h"
#include "MediaSoupError.h"
...
...
@@ -52,41 +52,41 @@ int on_ssl_certificate_verify(int preverify_ok, X509_STORE_CTX* ctx)
static
inline
void
on_ssl_info
(
const
SSL
*
ssl
,
int
where
,
int
ret
)
{
static_cast
<
RTC
::
D
TLS
Transport
*>
(
SSL_get_ex_data
(
ssl
,
0
))
->
onSSLInfo
(
where
,
ret
);
static_cast
<
RTC
::
D
tls
Transport
*>
(
SSL_get_ex_data
(
ssl
,
0
))
->
onSSLInfo
(
where
,
ret
);
}
namespace
RTC
{
/* Class variables. */
X509
*
D
TLS
Transport
::
certificate
=
nullptr
;
EVP_PKEY
*
D
TLS
Transport
::
privateKey
=
nullptr
;
SSL_CTX
*
D
TLS
Transport
::
sslCtx
=
nullptr
;
uint8_t
D
TLS
Transport
::
sslReadBuffer
[
MS_SSL_READ_BUFFER_SIZE
];
std
::
map
<
std
::
string
,
D
TLSTransport
::
FingerprintAlgorithm
>
DTLS
Transport
::
string2FingerprintAlgorithm
=
X509
*
D
tls
Transport
::
certificate
=
nullptr
;
EVP_PKEY
*
D
tls
Transport
::
privateKey
=
nullptr
;
SSL_CTX
*
D
tls
Transport
::
sslCtx
=
nullptr
;
uint8_t
D
tls
Transport
::
sslReadBuffer
[
MS_SSL_READ_BUFFER_SIZE
];
std
::
map
<
std
::
string
,
D
tlsTransport
::
FingerprintAlgorithm
>
Dtls
Transport
::
string2FingerprintAlgorithm
=
{
{
"sha-1"
,
D
TLS
Transport
::
FingerprintAlgorithm
::
SHA1
},
{
"sha-224"
,
D
TLS
Transport
::
FingerprintAlgorithm
::
SHA224
},
{
"sha-256"
,
D
TLS
Transport
::
FingerprintAlgorithm
::
SHA256
},
{
"sha-384"
,
D
TLS
Transport
::
FingerprintAlgorithm
::
SHA384
},
{
"sha-512"
,
D
TLS
Transport
::
FingerprintAlgorithm
::
SHA512
}
{
"sha-1"
,
D
tls
Transport
::
FingerprintAlgorithm
::
SHA1
},
{
"sha-224"
,
D
tls
Transport
::
FingerprintAlgorithm
::
SHA224
},
{
"sha-256"
,
D
tls
Transport
::
FingerprintAlgorithm
::
SHA256
},
{
"sha-384"
,
D
tls
Transport
::
FingerprintAlgorithm
::
SHA384
},
{
"sha-512"
,
D
tls
Transport
::
FingerprintAlgorithm
::
SHA512
}
};
std
::
map
<
std
::
string
,
D
TLSTransport
::
Role
>
DTLS
Transport
::
string2Role
=
std
::
map
<
std
::
string
,
D
tlsTransport
::
Role
>
Dtls
Transport
::
string2Role
=
{
{
"auto"
,
D
TLS
Transport
::
Role
::
AUTO
},
{
"client"
,
D
TLS
Transport
::
Role
::
CLIENT
},
{
"server"
,
D
TLS
Transport
::
Role
::
SERVER
}
{
"auto"
,
D
tls
Transport
::
Role
::
AUTO
},
{
"client"
,
D
tls
Transport
::
Role
::
CLIENT
},
{
"server"
,
D
tls
Transport
::
Role
::
SERVER
}
};
Json
::
Value
D
TLS
Transport
::
localFingerprints
=
Json
::
Value
(
Json
::
objectValue
);
std
::
vector
<
D
TLSTransport
::
SrtpProfileMapEntry
>
DTLS
Transport
::
srtpProfiles
=
Json
::
Value
D
tls
Transport
::
localFingerprints
=
Json
::
Value
(
Json
::
objectValue
);
std
::
vector
<
D
tlsTransport
::
SrtpProfileMapEntry
>
Dtls
Transport
::
srtpProfiles
=
{
{
RTC
::
S
RTP
Session
::
Profile
::
AES_CM_128_HMAC_SHA1_80
,
"SRTP_AES128_CM_SHA1_80"
},
{
RTC
::
S
RTP
Session
::
Profile
::
AES_CM_128_HMAC_SHA1_32
,
"SRTP_AES128_CM_SHA1_32"
}
{
RTC
::
S
rtp
Session
::
Profile
::
AES_CM_128_HMAC_SHA1_80
,
"SRTP_AES128_CM_SHA1_80"
},
{
RTC
::
S
rtp
Session
::
Profile
::
AES_CM_128_HMAC_SHA1_32
,
"SRTP_AES128_CM_SHA1_32"
}
};
/* Class methods. */
void
D
TLS
Transport
::
ClassInit
()
void
D
tls
Transport
::
ClassInit
()
{
MS_TRACE
();
...
...
@@ -103,19 +103,19 @@ namespace RTC
GenerateFingerprints
();
}
void
D
TLS
Transport
::
ClassDestroy
()
void
D
tls
Transport
::
ClassDestroy
()
{
MS_TRACE
();
if
(
D
TLS
Transport
::
privateKey
)
EVP_PKEY_free
(
D
TLS
Transport
::
privateKey
);
if
(
D
TLS
Transport
::
certificate
)
X509_free
(
D
TLS
Transport
::
certificate
);
if
(
D
TLS
Transport
::
sslCtx
)
SSL_CTX_free
(
D
TLS
Transport
::
sslCtx
);
if
(
D
tls
Transport
::
privateKey
)
EVP_PKEY_free
(
D
tls
Transport
::
privateKey
);
if
(
D
tls
Transport
::
certificate
)
X509_free
(
D
tls
Transport
::
certificate
);
if
(
D
tls
Transport
::
sslCtx
)
SSL_CTX_free
(
D
tls
Transport
::
sslCtx
);
}
void
D
TLS
Transport
::
GenerateCertificateAndPrivateKey
()
void
D
tls
Transport
::
GenerateCertificateAndPrivateKey
()
{
MS_TRACE
();
...
...
@@ -157,14 +157,14 @@ namespace RTC
}
// Create a private key object (needed to hold the RSA key).
D
TLS
Transport
::
privateKey
=
EVP_PKEY_new
();
if
(
!
D
TLS
Transport
::
privateKey
)
D
tls
Transport
::
privateKey
=
EVP_PKEY_new
();
if
(
!
D
tls
Transport
::
privateKey
)
{
LOG_OPENSSL_ERROR
(
"EVP_PKEY_new() failed"
);
goto
error
;
}
ret
=
EVP_PKEY_assign_RSA
(
D
TLS
Transport
::
privateKey
,
rsa_key
);
ret
=
EVP_PKEY_assign_RSA
(
D
tls
Transport
::
privateKey
,
rsa_key
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"EVP_PKEY_assign_RSA() failed"
);
...
...
@@ -174,25 +174,25 @@ namespace RTC
rsa_key
=
nullptr
;
// Create the X509 certificate.
D
TLS
Transport
::
certificate
=
X509_new
();
if
(
!
D
TLS
Transport
::
certificate
)
D
tls
Transport
::
certificate
=
X509_new
();
if
(
!
D
tls
Transport
::
certificate
)
{
LOG_OPENSSL_ERROR
(
"X509_new() failed"
);
goto
error
;
}
// Set version 3 (note that 0 means version 1).
X509_set_version
(
D
TLS
Transport
::
certificate
,
2
);
X509_set_version
(
D
tls
Transport
::
certificate
,
2
);
// Set serial number (avoid default 0).
ASN1_INTEGER_set
(
X509_get_serialNumber
(
D
TLS
Transport
::
certificate
),
(
long
)
Utils
::
Crypto
::
GetRandomUInt
(
1000000
,
9999999
));
ASN1_INTEGER_set
(
X509_get_serialNumber
(
D
tls
Transport
::
certificate
),
(
long
)
Utils
::
Crypto
::
GetRandomUInt
(
1000000
,
9999999
));
// Set valid period.
X509_gmtime_adj
(
X509_get_notBefore
(
D
TLS
Transport
::
certificate
),
-
1
*
60
*
60
*
24
*
365
*
10
);
// - 10 years.
X509_gmtime_adj
(
X509_get_notAfter
(
D
TLS
Transport
::
certificate
),
60
*
60
*
24
*
365
*
10
);
// 10 years.
X509_gmtime_adj
(
X509_get_notBefore
(
D
tls
Transport
::
certificate
),
-
1
*
60
*
60
*
24
*
365
*
10
);
// - 10 years.
X509_gmtime_adj
(
X509_get_notAfter
(
D
tls
Transport
::
certificate
),
60
*
60
*
24
*
365
*
10
);
// 10 years.
// Set the public key for the certificate using the key.
ret
=
X509_set_pubkey
(
D
TLSTransport
::
certificate
,
DTLS
Transport
::
privateKey
);
ret
=
X509_set_pubkey
(
D
tlsTransport
::
certificate
,
Dtls
Transport
::
privateKey
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"X509_set_pubkey() failed"
);
...
...
@@ -200,7 +200,7 @@ namespace RTC
}
// Set certificate fields.
cert_name
=
X509_get_subject_name
(
D
TLS
Transport
::
certificate
);
cert_name
=
X509_get_subject_name
(
D
tls
Transport
::
certificate
);
if
(
!
cert_name
)
{
LOG_OPENSSL_ERROR
(
"X509_get_subject_name() failed"
);
...
...
@@ -210,7 +210,7 @@ namespace RTC
X509_NAME_add_entry_by_txt
(
cert_name
,
"CN"
,
MBSTRING_ASC
,
(
uint8_t
*
)
MS_APP_NAME
,
-
1
,
-
1
,
0
);
// It is self-signed so set the issuer name to be the same as the subject.
ret
=
X509_set_issuer_name
(
D
TLS
Transport
::
certificate
,
cert_name
);
ret
=
X509_set_issuer_name
(
D
tls
Transport
::
certificate
,
cert_name
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"X509_set_issuer_name() failed"
);
...
...
@@ -218,7 +218,7 @@ namespace RTC
}
// Sign the certificate with its own private key.
ret
=
X509_sign
(
D
TLSTransport
::
certificate
,
DTLS
Transport
::
privateKey
,
EVP_sha1
());
ret
=
X509_sign
(
D
tlsTransport
::
certificate
,
Dtls
Transport
::
privateKey
,
EVP_sha1
());
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"X509_sign() failed"
);
...
...
@@ -232,17 +232,17 @@ namespace RTC
error
:
if
(
bne
)
BN_free
(
bne
);
if
(
rsa_key
&&
!
D
TLS
Transport
::
privateKey
)
if
(
rsa_key
&&
!
D
tls
Transport
::
privateKey
)
RSA_free
(
rsa_key
);
if
(
D
TLS
Transport
::
privateKey
)
EVP_PKEY_free
(
D
TLS
Transport
::
privateKey
);
// NOTE: This also frees the RSA key.
if
(
D
TLS
Transport
::
certificate
)
X509_free
(
D
TLS
Transport
::
certificate
);
if
(
D
tls
Transport
::
privateKey
)
EVP_PKEY_free
(
D
tls
Transport
::
privateKey
);
// NOTE: This also frees the RSA key.
if
(
D
tls
Transport
::
certificate
)
X509_free
(
D
tls
Transport
::
certificate
);
MS_THROW_ERROR
(
"DTLS certificate and private key generation failed"
);
}
void
D
TLS
Transport
::
ReadCertificateAndPrivateKeyFromFiles
()
void
D
tls
Transport
::
ReadCertificateAndPrivateKeyFromFiles
()
{
MS_TRACE
();
...
...
@@ -254,8 +254,8 @@ namespace RTC
MS_ERROR
(
"error reading DTLS certificate file: %s"
,
std
::
strerror
(
errno
));
goto
error
;
}
D
TLS
Transport
::
certificate
=
PEM_read_X509
(
file
,
nullptr
,
nullptr
,
nullptr
);
if
(
!
D
TLS
Transport
::
certificate
)
D
tls
Transport
::
certificate
=
PEM_read_X509
(
file
,
nullptr
,
nullptr
,
nullptr
);
if
(
!
D
tls
Transport
::
certificate
)
{
LOG_OPENSSL_ERROR
(
"PEM_read_X509() failed"
);
goto
error
;
...
...
@@ -268,8 +268,8 @@ namespace RTC
MS_ERROR
(
"error reading DTLS private key file: %s"
,
std
::
strerror
(
errno
));
goto
error
;
}
D
TLS
Transport
::
privateKey
=
PEM_read_PrivateKey
(
file
,
nullptr
,
nullptr
,
nullptr
);
if
(
!
D
TLS
Transport
::
privateKey
)
D
tls
Transport
::
privateKey
=
PEM_read_PrivateKey
(
file
,
nullptr
,
nullptr
,
nullptr
);
if
(
!
D
tls
Transport
::
privateKey
)
{
LOG_OPENSSL_ERROR
(
"PEM_read_PrivateKey() failed"
);
goto
error
;
...
...
@@ -282,7 +282,7 @@ namespace RTC
MS_THROW_ERROR
(
"error reading DTLS certificate and private key PEM files"
);
}
void
D
TLS
Transport
::
CreateSSL_CTX
()
void
D
tls
Transport
::
CreateSSL_CTX
()
{
MS_TRACE
();
...
...
@@ -294,35 +294,35 @@ namespace RTC
// - Both DTLS 1.0 and 1.2 (requires OpenSSL >= 1.1.0).
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
D
TLS
Transport
::
sslCtx
=
SSL_CTX_new
(
DTLS_method
());
D
tls
Transport
::
sslCtx
=
SSL_CTX_new
(
DTLS_method
());
// - Just DTLS 1.0 (requires OpenSSL >= 1.0.1).
#elif (OPENSSL_VERSION_NUMBER >= 0x10001000L)
D
TLS
Transport
::
sslCtx
=
SSL_CTX_new
(
DTLSv1_method
());
D
tls
Transport
::
sslCtx
=
SSL_CTX_new
(
DTLSv1_method
());
#else
#error "too old OpenSSL version"
#endif
if
(
!
D
TLS
Transport
::
sslCtx
)
if
(
!
D
tls
Transport
::
sslCtx
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_new() failed"
);
goto
error
;
}
ret
=
SSL_CTX_use_certificate
(
D
TLSTransport
::
sslCtx
,
DTLS
Transport
::
certificate
);
ret
=
SSL_CTX_use_certificate
(
D
tlsTransport
::
sslCtx
,
Dtls
Transport
::
certificate
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_use_certificate() failed"
);
goto
error
;
}
ret
=
SSL_CTX_use_PrivateKey
(
D
TLSTransport
::
sslCtx
,
DTLS
Transport
::
privateKey
);
ret
=
SSL_CTX_use_PrivateKey
(
D
tlsTransport
::
sslCtx
,
Dtls
Transport
::
privateKey
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_use_PrivateKey() failed"
);
goto
error
;
}
ret
=
SSL_CTX_check_private_key
(
D
TLS
Transport
::
sslCtx
);
ret
=
SSL_CTX_check_private_key
(
D
tls
Transport
::
sslCtx
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_check_private_key() failed"
);
...
...
@@ -330,26 +330,26 @@ namespace RTC
}
// Set options.
SSL_CTX_set_options
(
D
TLS
Transport
::
sslCtx
,
SSL_OP_CIPHER_SERVER_PREFERENCE
|
SSL_OP_NO_TICKET
|
SSL_OP_SINGLE_ECDH_USE
);
SSL_CTX_set_options
(
D
tls
Transport
::
sslCtx
,
SSL_OP_CIPHER_SERVER_PREFERENCE
|
SSL_OP_NO_TICKET
|
SSL_OP_SINGLE_ECDH_USE
);
// Don't use sessions cache.
SSL_CTX_set_session_cache_mode
(
D
TLS
Transport
::
sslCtx
,
SSL_SESS_CACHE_OFF
);
SSL_CTX_set_session_cache_mode
(
D
tls
Transport
::
sslCtx
,
SSL_SESS_CACHE_OFF
);
// Read always as much into the buffer as possible.
// NOTE: This is the default for DTLS, but a bug in non latest OpenSSL
// versions makes this call required.
SSL_CTX_set_read_ahead
(
D
TLS
Transport
::
sslCtx
,
1
);
SSL_CTX_set_read_ahead
(
D
tls
Transport
::
sslCtx
,
1
);
SSL_CTX_set_verify_depth
(
D
TLS
Transport
::
sslCtx
,
4
);
SSL_CTX_set_verify_depth
(
D
tls
Transport
::
sslCtx
,
4
);
// Require certificate from peer.
SSL_CTX_set_verify
(
D
TLS
Transport
::
sslCtx
,
SSL_VERIFY_PEER
|
SSL_VERIFY_FAIL_IF_NO_PEER_CERT
,
on_ssl_certificate_verify
);
SSL_CTX_set_verify
(
D
tls
Transport
::
sslCtx
,
SSL_VERIFY_PEER
|
SSL_VERIFY_FAIL_IF_NO_PEER_CERT
,
on_ssl_certificate_verify
);
// Set SSL info callback.
SSL_CTX_set_info_callback
(
D
TLS
Transport
::
sslCtx
,
on_ssl_info
);
SSL_CTX_set_info_callback
(
D
tls
Transport
::
sslCtx
,
on_ssl_info
);
// Set ciphers.
ret
=
SSL_CTX_set_cipher_list
(
D
TLS
Transport
::
sslCtx
,
"ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH"
);
ret
=
SSL_CTX_set_cipher_list
(
D
tls
Transport
::
sslCtx
,
"ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH"
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_set_cipher_list() failed"
);
...
...
@@ -361,7 +361,7 @@ namespace RTC
// NOTE: https://code.google.com/p/chromium/issues/detail?id=406458
// For OpenSSL >= 1.0.2:
#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
SSL_CTX_set_ecdh_auto
(
D
TLS
Transport
::
sslCtx
,
1
);
SSL_CTX_set_ecdh_auto
(
D
tls
Transport
::
sslCtx
,
1
);
#else
ecdh
=
EC_KEY_new_by_curve_name
(
NID_X9_62_prime256v1
);
if
(
!
ecdh
)
...
...
@@ -369,7 +369,7 @@ namespace RTC
LOG_OPENSSL_ERROR
(
"EC_KEY_new_by_curve_name() failed"
);
goto
error
;
}
if
(
SSL_CTX_set_tmp_ecdh
(
D
TLS
Transport
::
sslCtx
,
ecdh
)
!=
1
)
if
(
SSL_CTX_set_tmp_ecdh
(
D
tls
Transport
::
sslCtx
,
ecdh
)
!=
1
)
{
LOG_OPENSSL_ERROR
(
"SSL_CTX_set_tmp_ecdh() failed"
);
goto
error
;
...
...
@@ -379,9 +379,9 @@ namespace RTC
#endif
// Set the "use_srtp" DTLS extension.
for
(
auto
it
=
D
TLSTransport
::
srtpProfiles
.
begin
();
it
!=
DTLS
Transport
::
srtpProfiles
.
end
();
++
it
)
for
(
auto
it
=
D
tlsTransport
::
srtpProfiles
.
begin
();
it
!=
Dtls
Transport
::
srtpProfiles
.
end
();
++
it
)
{
if
(
it
!=
D
TLS
Transport
::
srtpProfiles
.
begin
())
if
(
it
!=
D
tls
Transport
::
srtpProfiles
.
begin
())
ssl_srtp_profiles
+=
":"
;
SrtpProfileMapEntry
*
profile_entry
=
&
(
*
it
);
...
...
@@ -389,7 +389,7 @@ namespace RTC
}
MS_DEBUG
(
"setting SRTP profiles for DTLS: %s"
,
ssl_srtp_profiles
.
c_str
());
// NOTE: This function returns 0 on success.
ret
=
SSL_CTX_set_tlsext_use_srtp
(
D
TLS
Transport
::
sslCtx
,
ssl_srtp_profiles
.
c_str
());
ret
=
SSL_CTX_set_tlsext_use_srtp
(
D
tls
Transport
::
sslCtx
,
ssl_srtp_profiles
.
c_str
());
if
(
ret
!=
0
)
{
MS_ERROR
(
"SSL_CTX_set_tlsext_use_srtp() failed when entering '%s'"
,
ssl_srtp_profiles
.
c_str
());
...
...
@@ -400,10 +400,10 @@ namespace RTC
return
;
error
:
if
(
D
TLS
Transport
::
sslCtx
)
if
(
D
tls
Transport
::
sslCtx
)
{
SSL_CTX_free
(
D
TLS
Transport
::
sslCtx
);
D
TLS
Transport
::
sslCtx
=
nullptr
;
SSL_CTX_free
(
D
tls
Transport
::
sslCtx
);
D
tls
Transport
::
sslCtx
=
nullptr
;
}
if
(
ecdh
)
...
...
@@ -412,11 +412,11 @@ namespace RTC
MS_THROW_ERROR
(
"SSL context creation failed"
);
}
void
D
TLS
Transport
::
GenerateFingerprints
()
void
D
tls
Transport
::
GenerateFingerprints
()
{
MS_TRACE
();
for
(
auto
it
=
D
TLSTransport
::
string2FingerprintAlgorithm
.
begin
();
it
!=
DTLS
Transport
::
string2FingerprintAlgorithm
.
end
();
++
it
)
for
(
auto
it
=
D
tlsTransport
::
string2FingerprintAlgorithm
.
begin
();
it
!=
Dtls
Transport
::
string2FingerprintAlgorithm
.
end
();
++
it
)
{
std
::
string
algorithm_str
=
it
->
first
;
FingerprintAlgorithm
algorithm
=
it
->
second
;
...
...
@@ -447,7 +447,7 @@ namespace RTC
MS_ABORT
(
"unknown algorithm"
);
}
ret
=
X509_digest
(
D
TLS
Transport
::
certificate
,
hash_function
,
binary_fingerprint
,
&
size
);
ret
=
X509_digest
(
D
tls
Transport
::
certificate
,
hash_function
,
binary_fingerprint
,
&
size
);
if
(
ret
==
0
)
{
MS_ERROR
(
"X509_digest() failed"
);
...
...
@@ -464,20 +464,20 @@ namespace RTC
MS_DEBUG
(
"%-7s fingerprint: %s"
,
algorithm_str
.
c_str
(),
hex_fingerprint
);
// Store in the JSON.
D
TLS
Transport
::
localFingerprints
[
algorithm_str
]
=
hex_fingerprint
;
D
tls
Transport
::
localFingerprints
[
algorithm_str
]
=
hex_fingerprint
;
}
}
/* Instance methods. */
D
TLSTransport
::
DTLS
Transport
(
Listener
*
listener
)
:
D
tlsTransport
::
Dtls
Transport
(
Listener
*
listener
)
:
listener
(
listener
)
{
MS_TRACE
();
/* Set SSL. */
this
->
ssl
=
SSL_new
(
D
TLS
Transport
::
sslCtx
);
this
->
ssl
=
SSL_new
(
D
tls
Transport
::
sslCtx
);
if
(
!
this
->
ssl
)
{
LOG_OPENSSL_ERROR
(
"SSL_new() failed"
);
...
...
@@ -524,10 +524,10 @@ namespace RTC
// NOTE: If this is not catched by the caller the program will abort, but
// this should never happen.
MS_THROW_ERROR
(
"D
TLS
Transport instance creation failed"
);
MS_THROW_ERROR
(
"D
tls
Transport instance creation failed"
);
}
D
TLSTransport
::~
DTLS
Transport
()
D
tlsTransport
::~
Dtls
Transport
()
{
MS_TRACE
();
...
...
@@ -540,7 +540,7 @@ namespace RTC
}
}
void
D
TLS
Transport
::
Close
()
void
D
tls
Transport
::
Close
()
{
MS_TRACE
();
...
...
@@ -548,7 +548,7 @@ namespace RTC
{
// Send close alert to the peer.
SSL_shutdown
(
this
->
ssl
);
SendPendingOutgoingD
TLS
Data
();
SendPendingOutgoingD
tls
Data
();
}
// Close the DTLS timer.
...
...
@@ -557,7 +557,7 @@ namespace RTC
delete
this
;
}
void
D
TLS
Transport
::
Dump
()
void
D
tls
Transport
::
Dump
()
{
MS_TRACE
();
...
...
@@ -568,7 +568,7 @@ namespace RTC
this
->
state
==
DtlsState
::
CONNECTED
?
"yes"
:
"no"
);
}
void
D
TLS
Transport
::
Run
(
Role
localRole
)
void
D
tls
Transport
::
Run
(
Role
localRole
)
{
MS_TRACE
();
...
...
@@ -596,7 +596,7 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
CONNECTING
;
this
->
listener
->
onD
TLS
Connecting
(
this
);
this
->
listener
->
onD
tls
Connecting
(
this
);
switch
(
this
->
localRole
)
{
...
...
@@ -605,7 +605,7 @@ namespace RTC
SSL_set_connect_state
(
this
->
ssl
);
SSL_do_handshake
(
this
->
ssl
);
SendPendingOutgoingD
TLS
Data
();
SendPendingOutgoingD
tls
Data
();
SetTimeout
();
break
;
case
Role
:
:
SERVER
:
...
...
@@ -620,7 +620,7 @@ namespace RTC
}
}
void
D
TLS
Transport
::
SetRemoteFingerprint
(
Fingerprint
fingerprint
)
void
D
tls
Transport
::
SetRemoteFingerprint
(
Fingerprint
fingerprint
)
{
MS_TRACE
();
...
...
@@ -638,7 +638,7 @@ namespace RTC
}
}
void
D
TLSTransport
::
ProcessDTLS
Data
(
const
uint8_t
*
data
,
size_t
len
)
void
D
tlsTransport
::
ProcessDtls
Data
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -658,10 +658,10 @@ namespace RTC
MS_WARN
(
"OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)"
,
(
size_t
)
written
,
len
);
// Must call SSL_read() to process received DTLS data.
read
=
SSL_read
(
this
->
ssl
,
(
void
*
)
D
TLS
Transport
::
sslReadBuffer
,
MS_SSL_READ_BUFFER_SIZE
);
read
=
SSL_read
(
this
->
ssl
,
(
void
*
)
D
tls
Transport
::
sslReadBuffer
,
MS_SSL_READ_BUFFER_SIZE
);
// Send data if it's ready.
SendPendingOutgoingD
TLS
Data
();
SendPendingOutgoingD
tls
Data
();
// Check SSL status and return if it is bad/closed.
if
(
!
CheckStatus
(
read
))
...
...
@@ -683,11 +683,11 @@ namespace RTC
}
// Notify the listener.
this
->
listener
->
onD
TLSApplicationData
(
this
,
(
uint8_t
*
)
DTLS
Transport
::
sslReadBuffer
,
(
size_t
)
read
);
this
->
listener
->
onD
tlsApplicationData
(
this
,
(
uint8_t
*
)
Dtls
Transport
::
sslReadBuffer
,
(
size_t
)
read
);
}
}
void
D
TLS
Transport
::
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
)
void
D
tls
Transport
::
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -721,10 +721,10 @@ namespace RTC
}
// Send data.
SendPendingOutgoingD
TLS
Data
();
SendPendingOutgoingD
tls
Data
();
}
void
D
TLS
Transport
::
Reset
()
void
D
tls
Transport
::
Reset
()
{
MS_TRACE
();
...
...
@@ -758,7 +758,7 @@ namespace RTC
}
inline
bool
D
TLS
Transport
::
CheckStatus
(
int
return_code
)
bool
D
tls
Transport
::
CheckStatus
(
int
return_code
)
{
MS_TRACE
();
...
...
@@ -818,7 +818,7 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
CLOSED
;
this
->
listener
->
onD
TLS
Closed
(
this
);
this
->
listener
->
onD
tls
Closed
(
this
);
}
else
{
...
...
@@ -828,7 +828,7 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
FAILED
;
this
->
listener
->
onD
TLS
Failed
(
this
);
this
->
listener
->
onD
tls
Failed
(
this
);
}
return
false
;
...
...
@@ -838,7 +838,7 @@ namespace RTC
}
inline
void
D
TLSTransport
::
SendPendingOutgoingDTLS
Data
()
void
D
tlsTransport
::
SendPendingOutgoingDtls
Data
()
{
MS_TRACE
();
...
...
@@ -855,7 +855,7 @@ namespace RTC
MS_DEBUG
(
"%ld bytes of DTLS data ready to sent to the peer"
,
read
);
// Notify the listener.
this
->
listener
->
onOutgoingD
TLS
Data
(
this
,
(
uint8_t
*
)
data
,
(
size_t
)
read
);
this
->
listener
->
onOutgoingD
tls
Data
(
this
,
(
uint8_t
*
)
data
,
(
size_t
)
read
);
// Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning.
...
...
@@ -863,7 +863,7 @@ namespace RTC
}
inline
bool
D
TLS
Transport
::
SetTimeout
()
bool
D
tls
Transport
::
SetTimeout
()
{
MS_TRACE
();
...
...
@@ -899,14 +899,14 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
FAILED
;
this
->
listener
->
onD
TLS
Failed
(
this
);
this
->
listener
->
onD
tls
Failed
(
this
);
return
false
;
}
}
inline
void
D
TLS
Transport
::
ProcessHandshake
()
void
D
tls
Transport
::
ProcessHandshake
()
{
MS_TRACE
();
...
...
@@ -928,19 +928,19 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
FAILED
;
this
->
listener
->
onD
TLS
Failed
(
this
);
this
->
listener
->
onD
tls
Failed
(
this
);
return
;
}
// Get the negotiated SRTP profile.
RTC
::
S
RTP
Session
::
Profile
srtp_profile
;
srtp_profile
=
GetNegotiatedS
RTP
Profile
();
RTC
::
S
rtp
Session
::
Profile
srtp_profile
;
srtp_profile
=
GetNegotiatedS
rtp
Profile
();
if
(
srtp_profile
!=
RTC
::
S
RTP
Session
::
Profile
::
NONE
)
if
(
srtp_profile
!=
RTC
::
S
rtp
Session
::
Profile
::
NONE
)
{
// Extract the SRTP keys (will notify the listener with them).
ExtractS
RTP
Keys
(
srtp_profile
);
ExtractS
rtp
Keys
(
srtp_profile
);
}
else
{
...
...
@@ -952,12 +952,12 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
FAILED
;
this
->
listener
->
onD
TLS
Failed
(
this
);
this
->
listener
->
onD
tls
Failed
(
this
);
}
}
inline
bool
D
TLS
Transport
::
CheckRemoteFingerprint
()
bool
D
tls
Transport
::
CheckRemoteFingerprint
()
{
MS_TRACE
();
...
...
@@ -1028,7 +1028,7 @@ namespace RTC
}
inline
void
D
TLSTransport
::
ExtractSRTPKeys
(
RTC
::
SRTP
Session
::
Profile
srtp_profile
)
void
D
tlsTransport
::
ExtractSrtpKeys
(
RTC
::
Srtp
Session
::
Profile
srtp_profile
)
{
MS_TRACE
();
...
...
@@ -1072,15 +1072,15 @@ namespace RTC
// Set state and notify the listener.
this
->
state
=
DtlsState
::
CONNECTED
;
this
->
listener
->
onD
TLS
Connected
(
this
,
srtp_profile
,
srtp_local_master_key
,
MS_SRTP_MASTER_LENGTH
,
srtp_remote_master_key
,
MS_SRTP_MASTER_LENGTH
);
this
->
listener
->
onD
tls
Connected
(
this
,
srtp_profile
,
srtp_local_master_key
,
MS_SRTP_MASTER_LENGTH
,
srtp_remote_master_key
,
MS_SRTP_MASTER_LENGTH
);
}
inline
RTC
::
S
RTPSession
::
Profile
DTLSTransport
::
GetNegotiatedSRTP
Profile
()
RTC
::
S
rtpSession
::
Profile
DtlsTransport
::
GetNegotiatedSrtp
Profile
()
{
MS_TRACE
();
RTC
::
S
RTPSession
::
Profile
negotiated_srtp_profile
=
RTC
::
SRTP
Session
::
Profile
::
NONE
;
RTC
::
S
rtpSession
::
Profile
negotiated_srtp_profile
=
RTC
::
Srtp
Session
::
Profile
::
NONE
;
// Ensure that the SRTP profile has been negotiated.
SRTP_PROTECTION_PROFILE
*
ssl_srtp_profile
=
SSL_get_selected_srtp_profile
(
this
->
ssl
);
...
...
@@ -1090,7 +1090,7 @@ namespace RTC
}
// Get the negotiated SRTP profile.
for
(
auto
it
=
D
TLSTransport
::
srtpProfiles
.
begin
();
it
!=
DTLS
Transport
::
srtpProfiles
.
end
();
++
it
)
for
(
auto
it
=
D
tlsTransport
::
srtpProfiles
.
begin
();
it
!=
Dtls
Transport
::
srtpProfiles
.
end
();
++
it
)
{
SrtpProfileMapEntry
*
profile_entry
=
&
(
*
it
);
...
...
@@ -1102,13 +1102,13 @@ namespace RTC
}
}
MS_ASSERT
(
negotiated_srtp_profile
!=
RTC
::
S
RTP
Session
::
Profile
::
NONE
,
"chosen SRTP profile is not an available one"
);
MS_ASSERT
(
negotiated_srtp_profile
!=
RTC
::
S
rtp
Session
::
Profile
::
NONE
,
"chosen SRTP profile is not an available one"
);
return
negotiated_srtp_profile
;
}
inline
void
D
TLS
Transport
::
onSSLInfo
(
int
where
,
int
ret
)
void
D
tls
Transport
::
onSSLInfo
(
int
where
,
int
ret
)
{
MS_TRACE
();
...
...
@@ -1164,14 +1164,14 @@ namespace RTC
}
inline
void
D
TLS
Transport
::
onTimer
(
Timer
*
timer
)
void
D
tls
Transport
::
onTimer
(
Timer
*
timer
)
{
MS_TRACE
();
DTLSv1_handle_timeout
(
this
->
ssl
);
// If required, send DTLS data.
SendPendingOutgoingD
TLS
Data
();
SendPendingOutgoingD
tls
Data
();
// Set the DTLS timer again.
SetTimeout
();
...
...
worker/src/RTC/IceCandidate.cpp
浏览文件 @
e5ee62f1
...
...
@@ -6,7 +6,7 @@ namespace RTC
{
/* Instance methods. */
IceCandidate
::
IceCandidate
(
RTC
::
U
DP
Socket
*
udpSocket
,
uint32_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
U
dp
Socket
*
udpSocket
,
uint32_t
priority
)
:
foundation
(
"udpcandidate"
),
priority
(
priority
),
ip
(
udpSocket
->
GetLocalIP
()),
...
...
@@ -15,7 +15,7 @@ namespace RTC
type
(
CandidateType
::
HOST
)
{}
IceCandidate
::
IceCandidate
(
RTC
::
T
CP
Server
*
tcpServer
,
uint32_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
T
cp
Server
*
tcpServer
,
uint32_t
priority
)
:
foundation
(
"tcpcandidate"
),
priority
(
priority
),
ip
(
tcpServer
->
GetLocalIP
()),
...
...
worker/src/RTC/I
CE
Server.cpp
→
worker/src/RTC/I
ce
Server.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::I
CE
Server"
#define MS_CLASS "RTC::I
ce
Server"
#include "RTC/I
CE
Server.h"
#include "RTC/I
ce
Server.h"
#include "Logger.h"
namespace
RTC
{
/* Instance methods. */
I
CEServer
::
ICE
Server
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
)
:
I
ceServer
::
Ice
Server
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
)
:
listener
(
listener
),
usernameFragment
(
usernameFragment
),
password
(
password
)
...
...
@@ -17,28 +17,28 @@ namespace RTC
MS_DEBUG
(
"[usernameFragment:%s, password:%s]"
,
this
->
usernameFragment
.
c_str
(),
this
->
password
.
c_str
());
}
void
I
CE
Server
::
Close
()
void
I
ce
Server
::
Close
()
{
MS_TRACE
();
delete
this
;
}
void
I
CEServer
::
ProcessSTUNMessage
(
RTC
::
STUN
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
void
I
ceServer
::
ProcessStunMessage
(
RTC
::
Stun
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
// Must be a Binding method.
if
(
msg
->
GetMethod
()
!=
RTC
::
S
TUN
Message
::
Method
::
Binding
)
if
(
msg
->
GetMethod
()
!=
RTC
::
S
tun
Message
::
Method
::
Binding
)
{
if
(
msg
->
GetClass
()
==
RTC
::
S
TUN
Message
::
Class
::
Request
)
if
(
msg
->
GetClass
()
==
RTC
::
S
tun
Message
::
Class
::
Request
)
{
MS_DEBUG
(
"unknown method %#.3x in STUN Request => 400"
,
(
unsigned
int
)
msg
->
GetMethod
());
// Reply 400.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
}
else
...
...
@@ -50,16 +50,16 @@ namespace RTC
}
// Must use FINGERPRINT (optional for ICE STUN indications).
if
(
!
msg
->
HasFingerprint
()
&&
msg
->
GetClass
()
!=
RTC
::
S
TUN
Message
::
Class
::
Indication
)
if
(
!
msg
->
HasFingerprint
()
&&
msg
->
GetClass
()
!=
RTC
::
S
tun
Message
::
Class
::
Indication
)
{
if
(
msg
->
GetClass
()
==
RTC
::
S
TUN
Message
::
Class
::
Request
)
if
(
msg
->
GetClass
()
==
RTC
::
S
tun
Message
::
Class
::
Request
)
{
MS_DEBUG
(
"STUN Binding Request without FINGERPRINT => 400"
);
// Reply 400.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
}
else
...
...
@@ -72,7 +72,7 @@ namespace RTC
switch
(
msg
->
GetClass
())
{
case
RTC
:
:
S
TUN
Message
::
Class
::
Request
:
case
RTC
:
:
S
tun
Message
::
Class
::
Request
:
{
// USERNAME, MESSAGE-INTEGRITY and PRIORITY are required.
if
(
!
msg
->
HasMessageIntegrity
()
||
!
msg
->
GetPriority
()
||
msg
->
GetUsername
().
empty
())
...
...
@@ -80,9 +80,9 @@ namespace RTC
MS_DEBUG
(
"mising required attributes in STUN Binding Request => 400"
);
// Reply 400.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
return
;
...
...
@@ -91,30 +91,30 @@ namespace RTC
// Check authentication.
switch
(
msg
->
CheckAuthentication
(
this
->
usernameFragment
,
this
->
password
))
{
case
RTC
:
:
S
TUN
Message
::
Authentication
::
OK
:
case
RTC
:
:
S
tun
Message
::
Authentication
::
OK
:
break
;
case
RTC
:
:
S
TUN
Message
::
Authentication
::
Unauthorized
:
case
RTC
:
:
S
tun
Message
::
Authentication
::
Unauthorized
:
{
MS_DEBUG
(
"wrong authentication in STUN Binding Request => 401"
);
// Reply 401.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
401
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
401
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
return
;
}
case
RTC
:
:
S
TUN
Message
::
Authentication
::
BadRequest
:
case
RTC
:
:
S
tun
Message
::
Authentication
::
BadRequest
:
{
MS_DEBUG
(
"cannot check authentication in STUN Binding Request => 400"
);
// Reply 400.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
return
;
...
...
@@ -127,9 +127,9 @@ namespace RTC
MS_DEBUG
(
"peer indicates ICE-CONTROLLED in STUN Binding Request => 487"
);
// Reply 487 (Role Conflict).
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateErrorResponse
(
487
);
RTC
::
S
tun
Message
*
response
=
msg
->
CreateErrorResponse
(
487
);
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
return
;
...
...
@@ -138,7 +138,7 @@ namespace RTC
MS_DEBUG
(
"processing STUN Binding Request [Priority:%"
PRIu32
", UseCandidate:%s]"
,
(
uint32_t
)
msg
->
GetPriority
(),
msg
->
HasUseCandidate
()
?
"true"
:
"false"
);
// Create a success response.
RTC
::
S
TUN
Message
*
response
=
msg
->
CreateSuccessResponse
();
RTC
::
S
tun
Message
*
response
=
msg
->
CreateSuccessResponse
();
// Add XOR-MAPPED-ADDRESS.
response
->
SetXorMappedAddress
(
tuple
->
GetRemoteAddress
());
...
...
@@ -148,7 +148,7 @@ namespace RTC
// Send back.
response
->
Serialize
();
this
->
listener
->
onOutgoingS
TUN
Message
(
this
,
response
,
tuple
);
this
->
listener
->
onOutgoingS
tun
Message
(
this
,
response
,
tuple
);
delete
response
;
// Handle the tuple.
...
...
@@ -157,21 +157,21 @@ namespace RTC
break
;
}
case
RTC
:
:
S
TUN
Message
::
Class
::
Indication
:
case
RTC
:
:
S
tun
Message
::
Class
::
Indication
:
{
MS_DEBUG
(
"STUN Binding Indication processed"
);
break
;
}
case
RTC
:
:
S
TUN
Message
::
Class
::
SuccessResponse
:
case
RTC
:
:
S
tun
Message
::
Class
::
SuccessResponse
:
{
MS_DEBUG
(
"STUN Binding Success Response processed"
);
break
;
}
case
RTC
:
:
S
TUN
Message
::
Class
::
ErrorResponse
:
case
RTC
:
:
S
tun
Message
::
Class
::
ErrorResponse
:
{
MS_DEBUG
(
"STUN Binding Error Response processed"
);
...
...
@@ -180,7 +180,7 @@ namespace RTC
}
}
bool
I
CE
Server
::
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
)
bool
I
ce
Server
::
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -191,7 +191,7 @@ namespace RTC
}
void
I
CE
Server
::
RemoveTuple
(
RTC
::
TransportTuple
*
tuple
)
void
I
ce
Server
::
RemoveTuple
(
RTC
::
TransportTuple
*
tuple
)
{
auto
it
=
this
->
tuples
.
begin
();
RTC
::
TransportTuple
*
removed_tuple
=
nullptr
;
...
...
@@ -237,12 +237,12 @@ namespace RTC
this
->
state
=
IceState
::
DISCONNECTED
;
// Notify the listener.
this
->
listener
->
onI
CE
Disconnected
(
this
);
this
->
listener
->
onI
ce
Disconnected
(
this
);
}
}
}
void
I
CE
Server
::
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
)
void
I
ce
Server
::
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -256,7 +256,7 @@ namespace RTC
SetSelectedTuple
(
stored_tuple
);
}
void
I
CE
Server
::
HandleTuple
(
RTC
::
TransportTuple
*
tuple
,
bool
has_use_candidate
)
void
I
ce
Server
::
HandleTuple
(
RTC
::
TransportTuple
*
tuple
,
bool
has_use_candidate
)
{
MS_TRACE
();
...
...
@@ -284,7 +284,7 @@ namespace RTC
this
->
state
=
IceState
::
CONNECTED
;
// Notify the listener.
this
->
listener
->
onI
CE
Connected
(
this
);
this
->
listener
->
onI
ce
Connected
(
this
);
}
else
{
...
...
@@ -300,7 +300,7 @@ namespace RTC
this
->
state
=
IceState
::
COMPLETED
;
// Notify the listener.
this
->
listener
->
onI
CE
Completed
(
this
);
this
->
listener
->
onI
ce
Completed
(
this
);
}
break
;
...
...
@@ -328,7 +328,7 @@ namespace RTC
this
->
state
=
IceState
::
CONNECTED
;
// Notify the listener.
this
->
listener
->
onI
CE
Connected
(
this
);
this
->
listener
->
onI
ce
Connected
(
this
);
}
else
{
...
...
@@ -344,7 +344,7 @@ namespace RTC
this
->
state
=
IceState
::
COMPLETED
;
// Notify the listener.
this
->
listener
->
onI
CE
Completed
(
this
);
this
->
listener
->
onI
ce
Completed
(
this
);
}
break
;
...
...
@@ -381,7 +381,7 @@ namespace RTC
this
->
state
=
IceState
::
COMPLETED
;
// Notify the listener.
this
->
listener
->
onI
CE
Completed
(
this
);
this
->
listener
->
onI
ce
Completed
(
this
);
}
break
;
...
...
@@ -419,7 +419,7 @@ namespace RTC
}
inline
RTC
::
TransportTuple
*
I
CE
Server
::
AddTuple
(
RTC
::
TransportTuple
*
tuple
)
RTC
::
TransportTuple
*
I
ce
Server
::
AddTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -438,7 +438,7 @@ namespace RTC
}
inline
RTC
::
TransportTuple
*
I
CE
Server
::
HasTuple
(
RTC
::
TransportTuple
*
tuple
)
RTC
::
TransportTuple
*
I
ce
Server
::
HasTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -464,7 +464,7 @@ namespace RTC
}
inline
void
I
CE
Server
::
SetSelectedTuple
(
RTC
::
TransportTuple
*
stored_tuple
)
void
I
ce
Server
::
SetSelectedTuple
(
RTC
::
TransportTuple
*
stored_tuple
)
{
MS_TRACE
();
...
...
@@ -475,6 +475,6 @@ namespace RTC
this
->
selectedTuple
=
stored_tuple
;
// Notify the listener.
this
->
listener
->
onI
CE
SelectedTuple
(
this
,
this
->
selectedTuple
);
this
->
listener
->
onI
ce
SelectedTuple
(
this
,
this
->
selectedTuple
);
}
}
worker/src/RTC/Peer.cpp
浏览文件 @
e5ee62f1
...
...
@@ -236,7 +236,7 @@ namespace RTC
MS_DEBUG
(
"RtpReceiver created [rtpReceiverId:%"
PRIu32
"]"
,
rtpReceiverId
);
// RTC::Transport inherits from RTC::RtpListener, but the API of
// RTC:RtpReceiver requires RT
P
::RtpListener.
// RTC:RtpReceiver requires RT
C
::RtpListener.
RTC
::
RtpListener
*
rtpListener
=
transport
;
// Set the RtpListener.
...
...
worker/src/RTC/R
TCP
Packet.cpp
→
worker/src/RTC/R
tcp
Packet.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::R
TCP
Packet"
#define MS_CLASS "RTC::R
tcp
Packet"
#include "RTC/R
TCP
Packet.h"
#include "RTC/R
tcp
Packet.h"
#include "Logger.h"
namespace
RTC
{
/* Class methods. */
R
TCPPacket
*
RTCP
Packet
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
R
tcpPacket
*
Rtcp
Packet
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
if
(
!
R
TCPPacket
::
IsRTCP
(
data
,
len
))
if
(
!
R
tcpPacket
::
IsRtcp
(
data
,
len
))
return
nullptr
;
// TODO: Do it.
...
...
@@ -19,12 +19,12 @@ namespace RTC
// Get the header.
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
return
new
R
TCP
Packet
(
header
,
data
,
len
);
return
new
R
tcp
Packet
(
header
,
data
,
len
);
}
/* Instance methods. */
R
TCPPacket
::
RTCP
Packet
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
)
:
R
tcpPacket
::
Rtcp
Packet
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
)
:
header
(
header
),
raw
((
uint8_t
*
)
raw
),
length
(
length
)
...
...
@@ -32,7 +32,7 @@ namespace RTC
MS_TRACE
();
}
R
TCPPacket
::~
RTCP
Packet
()
R
tcpPacket
::~
Rtcp
Packet
()
{
MS_TRACE
();
}
...
...
worker/src/RTC/RtpListener.cpp
浏览文件 @
e5ee62f1
...
...
@@ -108,7 +108,7 @@ namespace RTC
}
}
RTC
::
RtpReceiver
*
RtpListener
::
GetRtpReceiver
(
RTC
::
R
TP
Packet
*
packet
)
RTC
::
RtpReceiver
*
RtpListener
::
GetRtpReceiver
(
RTC
::
R
tp
Packet
*
packet
)
{
MS_TRACE
();
...
...
@@ -116,7 +116,7 @@ namespace RTC
// Check the SSRC table.
auto
it
=
this
->
ssrcTable
.
find
(
packet
->
GetS
SRC
());
auto
it
=
this
->
ssrcTable
.
find
(
packet
->
GetS
src
());
if
(
it
==
this
->
ssrcTable
.
end
())
{
...
...
worker/src/RTC/R
TP
Packet.cpp
→
worker/src/RTC/R
tp
Packet.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::R
TP
Packet"
#define MS_CLASS "RTC::R
tp
Packet"
#include "RTC/R
TP
Packet.h"
#include "RTC/R
tp
Packet.h"
#include "Utils.h"
#include "Logger.h"
#include <cstring> // std::memcmp(), std::memcpy()
...
...
@@ -9,11 +9,11 @@ namespace RTC
{
/* Class methods. */
R
TPPacket
*
RTP
Packet
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
R
tpPacket
*
Rtp
Packet
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
if
(
!
R
TPPacket
::
IsRTP
(
data
,
len
))
if
(
!
R
tpPacket
::
IsRtp
(
data
,
len
))
return
nullptr
;
// Get the header.
...
...
@@ -109,12 +109,12 @@ namespace RTC
MS_ASSERT
(
len
==
sizeof
(
Header
)
+
csrc_list_size
+
(
extensionHeader
?
4
+
extension_value_size
:
0
)
+
payloadLength
+
(
size_t
)
payloadPadding
,
"packet's computed length does not match received length"
);
return
new
R
TP
Packet
(
header
,
extensionHeader
,
payload
,
payloadLength
,
payloadPadding
,
data
,
len
);
return
new
R
tp
Packet
(
header
,
extensionHeader
,
payload
,
payloadLength
,
payloadPadding
,
data
,
len
);
}
/* Instance methods. */
R
TPPacket
::
RTP
Packet
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLength
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
)
:
R
tpPacket
::
Rtp
Packet
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLength
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
)
:
header
(
header
),
extensionHeader
(
extensionHeader
),
payload
((
uint8_t
*
)
payload
),
...
...
@@ -129,7 +129,7 @@ namespace RTC
this
->
csrcList
=
(
uint8_t
*
)
raw
+
sizeof
(
Header
);
}
R
TPPacket
::~
RTP
Packet
()
R
tpPacket
::~
Rtp
Packet
()
{
MS_TRACE
();
...
...
@@ -137,14 +137,14 @@ namespace RTC
delete
this
->
raw
;
}
void
R
TP
Packet
::
Dump
()
void
R
tp
Packet
::
Dump
()
{
MS_TRACE
();
if
(
!
Logger
::
HasDebugLevel
())
return
;
MS_DEBUG
(
"<R
TP
Packet>"
);
MS_DEBUG
(
"<R
tp
Packet>"
);
MS_DEBUG
(
"padding: %s"
,
this
->
header
->
padding
?
"true"
:
"false"
);
MS_DEBUG
(
"extension: %s"
,
HasExtensionHeader
()
?
"true"
:
"false"
);
if
(
HasExtensionHeader
())
...
...
@@ -157,12 +157,12 @@ namespace RTC
MS_DEBUG
(
"payload type: %"
PRIu8
,
GetPayloadType
());
MS_DEBUG
(
"sequence number: %"
PRIu16
,
GetSequenceNumber
());
MS_DEBUG
(
"timestamp: %"
PRIu32
,
GetTimestamp
());
MS_DEBUG
(
"SSRC: %"
PRIu32
,
GetS
SRC
());
MS_DEBUG
(
"SSRC: %"
PRIu32
,
GetS
src
());
MS_DEBUG
(
"payload size: %zu bytes"
,
GetPayloadLength
());
MS_DEBUG
(
"</R
TP
Packet>"
);
MS_DEBUG
(
"</R
tp
Packet>"
);
}
void
R
TP
Packet
::
Serialize
()
void
R
tp
Packet
::
Serialize
()
{
MS_TRACE
();
...
...
worker/src/RTC/RtpParameters.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::RtpParameters"
#include "RTC/RtpParameters.h"
// #include "Utils.h" // TODO: let's see
#include "MediaSoupError.h"
#include "Logger.h"
...
...
worker/src/RTC/S
RTP
Session.cpp
→
worker/src/RTC/S
rtp
Session.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::S
RTP
Session"
#define MS_CLASS "RTC::S
rtp
Session"
#include "RTC/S
RTP
Session.h"
#include "RTC/S
rtp
Session.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <cstring> // std::memset(), std::memcpy()
...
...
@@ -12,24 +12,24 @@ namespace RTC
{
/* Class variables. */
uint8_t
S
RTP
Session
::
encryptBuffer
[
MS_ENCRYPT_BUFFER_SIZE
];
uint8_t
S
rtp
Session
::
encryptBuffer
[
MS_ENCRYPT_BUFFER_SIZE
];
/* Class methods. */
void
S
RTP
Session
::
ClassInit
()
void
S
rtp
Session
::
ClassInit
()
{
/* Set libsrtp event handler. */
// srtp_err_status_t err;
// err = srtp_install_event_handler((srtp_event_handler_func_t*)onS
RTP
Event);
// err = srtp_install_event_handler((srtp_event_handler_func_t*)onS
rtp
Event);
// if (DepLibSRTP::IsError(err))
// {
// MS_THROW_ERROR("srtp_install_event_handler() failed: %s", DepLibSRTP::GetErrorString(err));
// }
}
// void S
RTPSession::onSRTP
Event(srtp_event_data_t* data)
// void S
rtpSession::onSrtp
Event(srtp_event_data_t* data)
// {
// MS_TRACE();
...
...
@@ -57,7 +57,7 @@ namespace RTC
/* Instance methods. */
S
RTPSession
::
SRTP
Session
(
Type
type
,
Profile
profile
,
uint8_t
*
key
,
size_t
key_len
)
S
rtpSession
::
Srtp
Session
(
Type
type
,
Profile
profile
,
uint8_t
*
key
,
size_t
key_len
)
{
MS_TRACE
();
...
...
@@ -92,7 +92,7 @@ namespace RTC
policy
.
ssrc
.
type
=
ssrc_any_outbound
;
break
;
default
:
MS_ABORT
(
"unknown S
RTP
Session::Type"
);
MS_ABORT
(
"unknown S
rtp
Session::Type"
);
}
policy
.
ssrc
.
value
=
0
;
policy
.
key
=
key
;
...
...
@@ -108,7 +108,7 @@ namespace RTC
}
}
S
RTPSession
::~
SRTP
Session
()
S
rtpSession
::~
Srtp
Session
()
{
MS_TRACE
();
...
...
@@ -126,7 +126,7 @@ namespace RTC
// TODO: It must not memcpy it but instead the provided packet must already be
// allocated into a buffer.
bool
S
RTPSession
::
EncryptRTP
(
const
uint8_t
**
data
,
size_t
*
len
)
bool
S
rtpSession
::
EncryptRtp
(
const
uint8_t
**
data
,
size_t
*
len
)
{
MS_TRACE
();
...
...
@@ -139,9 +139,9 @@ namespace RTC
return
false
;
}
std
::
memcpy
(
S
RTP
Session
::
encryptBuffer
,
*
data
,
*
len
);
std
::
memcpy
(
S
rtp
Session
::
encryptBuffer
,
*
data
,
*
len
);
this
->
lastError
=
srtp_protect
(
this
->
session
,
(
void
*
)
S
RTP
Session
::
encryptBuffer
,
(
int
*
)
len
);
this
->
lastError
=
srtp_protect
(
this
->
session
,
(
void
*
)
S
rtp
Session
::
encryptBuffer
,
(
int
*
)
len
);
if
(
DepLibSRTP
::
IsError
(
this
->
lastError
))
{
MS_DEBUG
(
"srtp_protect() failed: %s"
,
DepLibSRTP
::
GetErrorString
(
this
->
lastError
));
...
...
@@ -150,12 +150,12 @@ namespace RTC
}
// Update the given data pointer.
*
data
=
(
const
uint8_t
*
)
S
RTP
Session
::
encryptBuffer
;
*
data
=
(
const
uint8_t
*
)
S
rtp
Session
::
encryptBuffer
;
return
true
;
}
bool
S
RTPSession
::
DecryptSRTP
(
const
uint8_t
*
data
,
size_t
*
len
)
bool
S
rtpSession
::
DecryptSrtp
(
const
uint8_t
*
data
,
size_t
*
len
)
{
MS_TRACE
();
...
...
@@ -170,7 +170,7 @@ namespace RTC
return
true
;
}
bool
S
RTPSession
::
EncryptRTCP
(
const
uint8_t
**
data
,
size_t
*
len
)
bool
S
rtpSession
::
EncryptRtcp
(
const
uint8_t
**
data
,
size_t
*
len
)
{
MS_TRACE
();
...
...
@@ -183,9 +183,9 @@ namespace RTC
return
false
;
}
std
::
memcpy
(
S
RTP
Session
::
encryptBuffer
,
*
data
,
*
len
);
std
::
memcpy
(
S
rtp
Session
::
encryptBuffer
,
*
data
,
*
len
);
this
->
lastError
=
srtp_protect_rtcp
(
this
->
session
,
(
void
*
)
S
RTP
Session
::
encryptBuffer
,
(
int
*
)
len
);
this
->
lastError
=
srtp_protect_rtcp
(
this
->
session
,
(
void
*
)
S
rtp
Session
::
encryptBuffer
,
(
int
*
)
len
);
if
(
DepLibSRTP
::
IsError
(
this
->
lastError
))
{
MS_DEBUG
(
"srtp_protect_rtcp() failed: %s"
,
DepLibSRTP
::
GetErrorString
(
this
->
lastError
));
...
...
@@ -194,12 +194,12 @@ namespace RTC
}
// Update the given data pointer.
*
data
=
(
const
uint8_t
*
)
S
RTP
Session
::
encryptBuffer
;
*
data
=
(
const
uint8_t
*
)
S
rtp
Session
::
encryptBuffer
;
return
true
;
}
bool
S
RTPSession
::
DecryptSRTCP
(
const
uint8_t
*
data
,
size_t
*
len
)
bool
S
rtpSession
::
DecryptSrtcp
(
const
uint8_t
*
data
,
size_t
*
len
)
{
MS_TRACE
();
...
...
@@ -214,7 +214,7 @@ namespace RTC
return
true
;
}
void
S
RTP
Session
::
Close
()
void
S
rtp
Session
::
Close
()
{
MS_TRACE
();
...
...
worker/src/RTC/S
TUN
Message.cpp
→
worker/src/RTC/S
tun
Message.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::S
TUN
Message"
#define MS_CLASS "RTC::S
tun
Message"
#include "RTC/S
TUN
Message.h"
#include "RTC/S
tun
Message.h"
#include "Utils.h"
#include "Logger.h"
#include <cstdio> // std::snprintf()
...
...
@@ -10,15 +10,15 @@ namespace RTC
{
/* Class variables. */
const
uint8_t
S
TUN
Message
::
magicCookie
[]
=
{
0x21
,
0x12
,
0xA4
,
0x42
};
const
uint8_t
S
tun
Message
::
magicCookie
[]
=
{
0x21
,
0x12
,
0xA4
,
0x42
};
/* Class methods. */
S
TUNMessage
*
STUN
Message
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
S
tunMessage
*
Stun
Message
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
if
(
!
S
TUNMessage
::
IsSTUN
(
data
,
len
))
if
(
!
S
tunMessage
::
IsStun
(
data
,
len
))
return
nullptr
;
/*
...
...
@@ -60,8 +60,8 @@ namespace RTC
// Get STUN class.
uint16_t
msg_class
=
((
data
[
0
]
&
0x01
)
<<
1
)
|
((
data
[
1
]
&
0x10
)
>>
4
);
// Create a new S
TUN
Message (data + 8 points to the received TransactionID field).
S
TUNMessage
*
msg
=
new
STUN
Message
((
Class
)
msg_class
,
(
Method
)
msg_method
,
data
+
8
,
data
,
len
);
// Create a new S
tun
Message (data + 8 points to the received TransactionID field).
S
tunMessage
*
msg
=
new
Stun
Message
((
Class
)
msg_class
,
(
Method
)
msg_method
,
data
+
8
,
data
,
len
);
/*
STUN Attributes
...
...
@@ -201,7 +201,7 @@ namespace RTC
/* Instance methods. */
S
TUNMessage
::
STUN
Message
(
Class
klass
,
Method
method
,
const
uint8_t
*
transactionId
,
const
uint8_t
*
raw
,
size_t
length
)
:
S
tunMessage
::
Stun
Message
(
Class
klass
,
Method
method
,
const
uint8_t
*
transactionId
,
const
uint8_t
*
raw
,
size_t
length
)
:
klass
(
klass
),
method
(
method
),
transactionId
(
transactionId
),
...
...
@@ -211,7 +211,7 @@ namespace RTC
MS_TRACE
();
}
S
TUNMessage
::~
STUN
Message
()
S
tunMessage
::~
Stun
Message
()
{
MS_TRACE
();
...
...
@@ -219,14 +219,14 @@ namespace RTC
delete
this
->
raw
;
}
void
S
TUN
Message
::
Dump
()
void
S
tun
Message
::
Dump
()
{
MS_TRACE
();
if
(
!
Logger
::
HasDebugLevel
())
return
;
MS_DEBUG
(
"<S
TUN
Message>"
);
MS_DEBUG
(
"<S
tun
Message>"
);
std
::
string
klass
;
switch
(
this
->
klass
)
{
...
...
@@ -279,10 +279,10 @@ namespace RTC
}
if
(
this
->
hasFingerprint
)
MS_DEBUG
(
"fingerprint"
);
MS_DEBUG
(
"</S
TUN
Message>"
);
MS_DEBUG
(
"</S
tun
Message>"
);
}
S
TUNMessage
::
Authentication
STUN
Message
::
CheckAuthentication
(
const
std
::
string
&
local_username
,
const
std
::
string
&
local_password
)
S
tunMessage
::
Authentication
Stun
Message
::
CheckAuthentication
(
const
std
::
string
&
local_username
,
const
std
::
string
&
local_password
)
{
MS_TRACE
();
...
...
@@ -341,29 +341,29 @@ namespace RTC
return
result
;
}
S
TUNMessage
*
STUN
Message
::
CreateSuccessResponse
()
S
tunMessage
*
Stun
Message
::
CreateSuccessResponse
()
{
MS_TRACE
();
MS_ASSERT
(
this
->
klass
==
Class
::
Request
,
"attempt to create a success response for a non Request STUN message"
);
return
new
S
TUN
Message
(
Class
::
SuccessResponse
,
this
->
method
,
this
->
transactionId
,
nullptr
,
0
);
return
new
S
tun
Message
(
Class
::
SuccessResponse
,
this
->
method
,
this
->
transactionId
,
nullptr
,
0
);
}
S
TUNMessage
*
STUN
Message
::
CreateErrorResponse
(
uint16_t
errorCode
)
S
tunMessage
*
Stun
Message
::
CreateErrorResponse
(
uint16_t
errorCode
)
{
MS_TRACE
();
MS_ASSERT
(
this
->
klass
==
Class
::
Request
,
"attempt to create an error response for a non Request STUN message"
);
S
TUNMessage
*
response
=
new
STUN
Message
(
Class
::
ErrorResponse
,
this
->
method
,
this
->
transactionId
,
nullptr
,
0
);
S
tunMessage
*
response
=
new
Stun
Message
(
Class
::
ErrorResponse
,
this
->
method
,
this
->
transactionId
,
nullptr
,
0
);
response
->
SetErrorCode
(
errorCode
);
return
response
;
}
void
S
TUN
Message
::
Authenticate
(
const
std
::
string
&
password
)
void
S
tun
Message
::
Authenticate
(
const
std
::
string
&
password
)
{
// Just for Request, Indication and SuccessResponse messages.
if
(
this
->
klass
==
Class
::
ErrorResponse
)
...
...
@@ -376,7 +376,7 @@ namespace RTC
this
->
password
=
password
;
}
void
S
TUN
Message
::
Serialize
()
void
S
tun
Message
::
Serialize
()
{
MS_TRACE
();
...
...
@@ -389,7 +389,7 @@ namespace RTC
// Some useful variables.
uint16_t
username_padded_len
=
0
;
uint16_t
xor_mapped_address_padded_len
=
0
;
bool
add_xor_mapped_address
=
(
this
->
xorMappedAddress
&&
this
->
method
==
S
TUN
Message
::
Method
::
Binding
&&
this
->
klass
==
Class
::
SuccessResponse
);
bool
add_xor_mapped_address
=
(
this
->
xorMappedAddress
&&
this
->
method
==
S
tun
Message
::
Method
::
Binding
&&
this
->
klass
==
Class
::
SuccessResponse
);
bool
add_error_code
=
(
this
->
errorCode
&&
this
->
klass
==
Class
::
ErrorResponse
);
bool
add_message_integrity
=
(
this
->
klass
!=
Class
::
ErrorResponse
&&
!
this
->
password
.
empty
());
bool
add_fingerprint
=
true
;
// Do always.
...
...
@@ -459,7 +459,7 @@ namespace RTC
Utils
::
Byte
::
Set2Bytes
(
this
->
raw
,
2
,
(
uint16_t
)
this
->
length
-
20
);
// Set magic cookie.
std
::
memcpy
(
this
->
raw
+
4
,
S
TUN
Message
::
magicCookie
,
4
);
std
::
memcpy
(
this
->
raw
+
4
,
S
tun
Message
::
magicCookie
,
4
);
// Set TransactionId field.
std
::
memcpy
(
this
->
raw
+
8
,
this
->
transactionId
,
12
);
...
...
@@ -529,14 +529,14 @@ namespace RTC
attr_value
[
1
]
=
0x01
;
// Set port and XOR it.
std
::
memcpy
(
attr_value
+
2
,
&
((
const
sockaddr_in
*
)(
this
->
xorMappedAddress
))
->
sin_port
,
2
);
attr_value
[
2
]
^=
S
TUN
Message
::
magicCookie
[
0
];
attr_value
[
3
]
^=
S
TUN
Message
::
magicCookie
[
1
];
attr_value
[
2
]
^=
S
tun
Message
::
magicCookie
[
0
];
attr_value
[
3
]
^=
S
tun
Message
::
magicCookie
[
1
];
// Set address and XOR it.
std
::
memcpy
(
attr_value
+
4
,
&
((
const
sockaddr_in
*
)
this
->
xorMappedAddress
)
->
sin_addr
.
s_addr
,
4
);
attr_value
[
4
]
^=
S
TUN
Message
::
magicCookie
[
0
];
attr_value
[
5
]
^=
S
TUN
Message
::
magicCookie
[
1
];
attr_value
[
6
]
^=
S
TUN
Message
::
magicCookie
[
2
];
attr_value
[
7
]
^=
S
TUN
Message
::
magicCookie
[
3
];
attr_value
[
4
]
^=
S
tun
Message
::
magicCookie
[
0
];
attr_value
[
5
]
^=
S
tun
Message
::
magicCookie
[
1
];
attr_value
[
6
]
^=
S
tun
Message
::
magicCookie
[
2
];
attr_value
[
7
]
^=
S
tun
Message
::
magicCookie
[
3
];
pos
+=
4
+
8
;
break
;
...
...
@@ -549,14 +549,14 @@ namespace RTC
attr_value
[
1
]
=
0x02
;
// Set port and XOR it.
std
::
memcpy
(
attr_value
+
2
,
&
((
const
sockaddr_in6
*
)(
this
->
xorMappedAddress
))
->
sin6_port
,
2
);
attr_value
[
2
]
^=
S
TUN
Message
::
magicCookie
[
0
];
attr_value
[
3
]
^=
S
TUN
Message
::
magicCookie
[
1
];
attr_value
[
2
]
^=
S
tun
Message
::
magicCookie
[
0
];
attr_value
[
3
]
^=
S
tun
Message
::
magicCookie
[
1
];
// Set address and XOR it.
std
::
memcpy
(
attr_value
+
4
,
&
((
const
sockaddr_in6
*
)
this
->
xorMappedAddress
)
->
sin6_addr
.
s6_addr
,
16
);
attr_value
[
4
]
^=
S
TUN
Message
::
magicCookie
[
0
];
attr_value
[
5
]
^=
S
TUN
Message
::
magicCookie
[
1
];
attr_value
[
6
]
^=
S
TUN
Message
::
magicCookie
[
2
];
attr_value
[
7
]
^=
S
TUN
Message
::
magicCookie
[
3
];
attr_value
[
4
]
^=
S
tun
Message
::
magicCookie
[
0
];
attr_value
[
5
]
^=
S
tun
Message
::
magicCookie
[
1
];
attr_value
[
6
]
^=
S
tun
Message
::
magicCookie
[
2
];
attr_value
[
7
]
^=
S
tun
Message
::
magicCookie
[
3
];
attr_value
[
8
]
^=
this
->
transactionId
[
0
];
attr_value
[
9
]
^=
this
->
transactionId
[
1
];
attr_value
[
10
]
^=
this
->
transactionId
[
2
];
...
...
worker/src/RTC/T
CP
Connection.cpp
→
worker/src/RTC/T
cp
Connection.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::T
CP
Connection"
#define MS_CLASS "RTC::T
cp
Connection"
#include "RTC/T
CP
Connection.h"
#include "RTC/T
cp
Connection.h"
#include "Utils.h"
#include "Logger.h"
#include <cstring> // std::memmove()
...
...
@@ -9,19 +9,19 @@ namespace RTC
{
/* Instance methods. */
T
CPConnection
::
TCP
Connection
(
Listener
*
listener
,
size_t
bufferSize
)
:
::
T
CP
Connection
(
bufferSize
),
T
cpConnection
::
Tcp
Connection
(
Listener
*
listener
,
size_t
bufferSize
)
:
::
T
cp
Connection
(
bufferSize
),
listener
(
listener
)
{
MS_TRACE
();
}
T
CPConnection
::~
TCP
Connection
()
T
cpConnection
::~
Tcp
Connection
()
{
MS_TRACE
();
}
void
T
CPConnection
::
userOnTCP
ConnectionRead
()
void
T
cpConnection
::
userOnTcp
ConnectionRead
()
{
MS_TRACE
();
...
...
@@ -139,7 +139,7 @@ namespace RTC
}
}
void
T
CP
Connection
::
Send
(
const
uint8_t
*
data
,
size_t
len
)
void
T
cp
Connection
::
Send
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
worker/src/RTC/T
CP
Server.cpp
→
worker/src/RTC/T
cp
Server.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::T
CP
Server"
#define MS_CLASS "RTC::T
cp
Server"
#include "RTC/TCPServer.h"
#include "RTC/STUNMessage.h"
#include "RTC/RTPPacket.h"
#include "RTC/TcpServer.h"
#include "Settings.h"
#include "Utils.h"
#include "DepLibUV.h"
...
...
@@ -25,16 +23,16 @@ namespace RTC
{
/* Class variables. */
struct
sockaddr_storage
T
CP
Server
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
T
CP
Server
::
sockaddrStorageIPv6
;
uint16_t
T
CP
Server
::
minPort
;
uint16_t
T
CP
Server
::
maxPort
;
std
::
unordered_map
<
uint16_t
,
bool
>
T
CP
Server
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
T
CP
Server
::
availableIPv6Ports
;
struct
sockaddr_storage
T
cp
Server
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
T
cp
Server
::
sockaddrStorageIPv6
;
uint16_t
T
cp
Server
::
minPort
;
uint16_t
T
cp
Server
::
maxPort
;
std
::
unordered_map
<
uint16_t
,
bool
>
T
cp
Server
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
T
cp
Server
::
availableIPv6Ports
;
/* Class methods. */
void
T
CP
Server
::
ClassInit
()
void
T
cp
Server
::
ClassInit
()
{
MS_TRACE
();
...
...
@@ -42,31 +40,31 @@ namespace RTC
if
(
!
Settings
::
configuration
.
rtcListenIPv4
.
empty
())
{
err
=
uv_ip4_addr
(
Settings
::
configuration
.
rtcListenIPv4
.
c_str
(),
0
,
(
struct
sockaddr_in
*
)
&
RTC
::
T
CP
Server
::
sockaddrStorageIPv4
);
err
=
uv_ip4_addr
(
Settings
::
configuration
.
rtcListenIPv4
.
c_str
(),
0
,
(
struct
sockaddr_in
*
)
&
RTC
::
T
cp
Server
::
sockaddrStorageIPv4
);
if
(
err
)
MS_ABORT
(
"uv_ipv4_addr() failed: %s"
,
uv_strerror
(
err
));
}
if
(
!
Settings
::
configuration
.
rtcListenIPv6
.
empty
())
{
err
=
uv_ip6_addr
(
Settings
::
configuration
.
rtcListenIPv6
.
c_str
(),
0
,
(
struct
sockaddr_in6
*
)
&
RTC
::
T
CP
Server
::
sockaddrStorageIPv6
);
err
=
uv_ip6_addr
(
Settings
::
configuration
.
rtcListenIPv6
.
c_str
(),
0
,
(
struct
sockaddr_in6
*
)
&
RTC
::
T
cp
Server
::
sockaddrStorageIPv6
);
if
(
err
)
MS_ABORT
(
"uv_ipv6_addr() failed: %s"
,
uv_strerror
(
err
));
}
T
CP
Server
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
T
CP
Server
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
T
cp
Server
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
T
cp
Server
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
uint16_t
i
=
RTC
::
T
CP
Server
::
minPort
;
uint16_t
i
=
RTC
::
T
cp
Server
::
minPort
;
do
{
RTC
::
T
CP
Server
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
T
CP
Server
::
availableIPv6Ports
[
i
]
=
true
;
RTC
::
T
cp
Server
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
T
cp
Server
::
availableIPv6Ports
[
i
]
=
true
;
}
while
(
i
++
!=
RTC
::
T
CP
Server
::
maxPort
);
while
(
i
++
!=
RTC
::
T
cp
Server
::
maxPort
);
}
uv_tcp_t
*
T
CP
Server
::
GetRandomPort
(
int
address_family
)
uv_tcp_t
*
T
cp
Server
::
GetRandomPort
(
int
address_family
)
{
MS_TRACE
();
...
...
@@ -89,14 +87,14 @@ namespace RTC
switch
(
address_family
)
{
case
AF_INET
:
available_ports
=
&
RTC
::
T
CP
Server
::
availableIPv4Ports
;
bind_addr
=
RTC
::
T
CP
Server
::
sockaddrStorageIPv4
;
available_ports
=
&
RTC
::
T
cp
Server
::
availableIPv4Ports
;
bind_addr
=
RTC
::
T
cp
Server
::
sockaddrStorageIPv4
;
listen_ip
=
Settings
::
configuration
.
rtcListenIPv4
.
c_str
();
break
;
case
AF_INET6
:
available_ports
=
&
RTC
::
T
CP
Server
::
availableIPv6Ports
;
bind_addr
=
RTC
::
T
CP
Server
::
sockaddrStorageIPv6
;
available_ports
=
&
RTC
::
T
cp
Server
::
availableIPv6Ports
;
bind_addr
=
RTC
::
T
cp
Server
::
sockaddrStorageIPv6
;
listen_ip
=
Settings
::
configuration
.
rtcListenIPv6
.
c_str
();
// Don't also bind into IPv4 when listening in IPv6.
flags
|=
UV_TCP_IPV6ONLY
;
...
...
@@ -108,7 +106,7 @@ namespace RTC
}
// Choose a random first port to start from.
initial_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
T
CPServer
::
minPort
,
(
uint32_t
)
RTC
::
TCP
Server
::
maxPort
);
initial_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
T
cpServer
::
minPort
,
(
uint32_t
)
RTC
::
Tcp
Server
::
maxPort
);
iterating_port
=
initial_port
;
...
...
@@ -119,10 +117,10 @@ namespace RTC
attempt
++
;
// Increase the iterate port) within the range of RTC TCP ports.
if
(
iterating_port
<
RTC
::
T
CP
Server
::
maxPort
)
if
(
iterating_port
<
RTC
::
T
cp
Server
::
maxPort
)
iterating_port
+=
1
;
else
iterating_port
=
RTC
::
T
CP
Server
::
minPort
;
iterating_port
=
RTC
::
T
cp
Server
::
minPort
;
// Check whether the chosen port is available.
if
(
!
(
*
available_ports
)[
iterating_port
])
...
...
@@ -204,26 +202,26 @@ namespace RTC
/* Instance methods. */
T
CPServer
::
TCPServer
(
Listener
*
listener
,
RTC
::
TCP
Connection
::
Listener
*
connListener
,
int
address_family
)
:
T
cpServer
::
TcpServer
(
Listener
*
listener
,
RTC
::
Tcp
Connection
::
Listener
*
connListener
,
int
address_family
)
:
// Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports.
::
T
CPServer
::
TCP
Server
(
GetRandomPort
(
address_family
),
256
),
::
T
cpServer
::
Tcp
Server
(
GetRandomPort
(
address_family
),
256
),
listener
(
listener
),
connListener
(
connListener
)
{
MS_TRACE
();
}
void
T
CPServer
::
userOnTCPConnectionAlloc
(
::
TCP
Connection
**
connection
)
void
T
cpServer
::
userOnTcpConnectionAlloc
(
::
Tcp
Connection
**
connection
)
{
MS_TRACE
();
// Allocate a new RTC::T
CPConnection for the TCP
Server to handle it.
*
connection
=
new
RTC
::
T
CP
Connection
(
this
->
connListener
,
65536
);
// Allocate a new RTC::T
cpConnection for the Tcp
Server to handle it.
*
connection
=
new
RTC
::
T
cp
Connection
(
this
->
connListener
,
65536
);
}
void
T
CPServer
::
userOnNewTCPConnection
(
::
TCP
Connection
*
connection
)
void
T
cpServer
::
userOnNewTcpConnection
(
::
Tcp
Connection
*
connection
)
{
MS_TRACE
();
...
...
@@ -232,7 +230,7 @@ namespace RTC
connection
->
Close
();
}
void
T
CPServer
::
userOnTCPConnectionClosed
(
::
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
void
T
cpServer
::
userOnTcpConnectionClosed
(
::
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
{
MS_TRACE
();
...
...
@@ -240,17 +238,17 @@ namespace RTC
// NOTE: Don't do it if closing (since at this point the listener is already freed).
// At the end, this is just called if the connection was remotely closed.
if
(
!
IsClosing
())
this
->
listener
->
onR
TCTCPConnectionClosed
(
this
,
static_cast
<
RTC
::
TCP
Connection
*>
(
connection
),
is_closed_by_peer
);
this
->
listener
->
onR
tcTcpConnectionClosed
(
this
,
static_cast
<
RTC
::
Tcp
Connection
*>
(
connection
),
is_closed_by_peer
);
}
void
T
CPServer
::
userOnTCP
ServerClosed
()
void
T
cpServer
::
userOnTcp
ServerClosed
()
{
MS_TRACE
();
// Mark the port as available again.
if
(
this
->
localAddr
.
ss_family
==
AF_INET
)
RTC
::
T
CP
Server
::
availableIPv4Ports
[
this
->
localPort
]
=
true
;
RTC
::
T
cp
Server
::
availableIPv4Ports
[
this
->
localPort
]
=
true
;
else
if
(
this
->
localAddr
.
ss_family
==
AF_INET6
)
RTC
::
T
CP
Server
::
availableIPv6Ports
[
this
->
localPort
]
=
true
;
RTC
::
T
cp
Server
::
availableIPv6Ports
[
this
->
localPort
]
=
true
;
}
}
worker/src/RTC/Transport.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::Transport"
#include "RTC/Transport.h"
#include "RTC/RtpPacket.h"
#include "RTC/RtcpPacket.h"
#include "Settings.h"
#include "Utils.h"
#include "MediaSoupError.h"
...
...
@@ -73,7 +75,7 @@ namespace RTC
preferTcp
=
data
[
k_preferTcp
].
asBool
();
// Create a ICE server.
this
->
iceServer
=
new
RTC
::
I
CE
Server
(
this
,
this
->
iceServer
=
new
RTC
::
I
ce
Server
(
this
,
Utils
::
Crypto
::
GetRandomString
(
16
),
Utils
::
Crypto
::
GetRandomString
(
32
));
...
...
@@ -91,7 +93,7 @@ namespace RTC
try
{
RTC
::
U
DPSocket
*
udpSocket
=
new
RTC
::
UDP
Socket
(
this
,
AF_INET
);
RTC
::
U
dpSocket
*
udpSocket
=
new
RTC
::
Udp
Socket
(
this
,
AF_INET
);
RTC
::
IceCandidate
iceCandidate
(
udpSocket
,
priority
);
this
->
udpSockets
.
push_back
(
udpSocket
);
...
...
@@ -117,7 +119,7 @@ namespace RTC
try
{
RTC
::
U
DPSocket
*
udpSocket
=
new
RTC
::
UDP
Socket
(
this
,
AF_INET6
);
RTC
::
U
dpSocket
*
udpSocket
=
new
RTC
::
Udp
Socket
(
this
,
AF_INET6
);
RTC
::
IceCandidate
iceCandidate
(
udpSocket
,
priority
);
this
->
udpSockets
.
push_back
(
udpSocket
);
...
...
@@ -143,7 +145,7 @@ namespace RTC
try
{
RTC
::
T
CPServer
*
tcpServer
=
new
RTC
::
TCP
Server
(
this
,
this
,
AF_INET
);
RTC
::
T
cpServer
*
tcpServer
=
new
RTC
::
Tcp
Server
(
this
,
this
,
AF_INET
);
RTC
::
IceCandidate
iceCandidate
(
tcpServer
,
priority
);
this
->
tcpServers
.
push_back
(
tcpServer
);
...
...
@@ -169,7 +171,7 @@ namespace RTC
try
{
RTC
::
T
CPServer
*
tcpServer
=
new
RTC
::
TCP
Server
(
this
,
this
,
AF_INET6
);
RTC
::
T
cpServer
*
tcpServer
=
new
RTC
::
Tcp
Server
(
this
,
this
,
AF_INET6
);
RTC
::
IceCandidate
iceCandidate
(
tcpServer
,
priority
);
this
->
tcpServers
.
push_back
(
tcpServer
);
...
...
@@ -190,7 +192,7 @@ namespace RTC
}
// Create a DTLS agent.
this
->
dtlsTransport
=
new
RTC
::
D
TLS
Transport
(
this
);
this
->
dtlsTransport
=
new
RTC
::
D
tls
Transport
(
this
);
// Hack to avoid that Close() above attempts to delete this.
this
->
allocated
=
true
;
...
...
@@ -300,33 +302,33 @@ namespace RTC
// Add `iceState`.
switch
(
this
->
iceServer
->
GetState
())
{
case
RTC
:
:
I
CE
Server
::
IceState
::
NEW
:
case
RTC
:
:
I
ce
Server
::
IceState
::
NEW
:
json
[
k_iceState
]
=
v_new
;
break
;
case
RTC
:
:
I
CE
Server
::
IceState
::
CONNECTED
:
case
RTC
:
:
I
ce
Server
::
IceState
::
CONNECTED
:
json
[
k_iceState
]
=
v_connected
;
break
;
case
RTC
:
:
I
CE
Server
::
IceState
::
COMPLETED
:
case
RTC
:
:
I
ce
Server
::
IceState
::
COMPLETED
:
json
[
k_iceState
]
=
v_completed
;
break
;
case
RTC
:
:
I
CE
Server
::
IceState
::
DISCONNECTED
:
case
RTC
:
:
I
ce
Server
::
IceState
::
DISCONNECTED
:
json
[
k_iceState
]
=
v_disconnected
;
break
;
}
// Add `dtlsLocalParameters.fingerprints`.
json
[
k_dtlsLocalParameters
][
k_fingerprints
]
=
RTC
::
D
TLS
Transport
::
GetLocalFingerprints
();
json
[
k_dtlsLocalParameters
][
k_fingerprints
]
=
RTC
::
D
tls
Transport
::
GetLocalFingerprints
();
// Add `dtlsLocalParameters.role`.
switch
(
this
->
dtlsLocalRole
)
{
case
RTC
:
:
D
TLS
Transport
::
Role
::
AUTO
:
case
RTC
:
:
D
tls
Transport
::
Role
::
AUTO
:
json
[
k_dtlsLocalParameters
][
k_role
]
=
v_auto
;
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
CLIENT
:
case
RTC
:
:
D
tls
Transport
::
Role
::
CLIENT
:
json
[
k_dtlsLocalParameters
][
k_role
]
=
v_client
;
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
SERVER
:
case
RTC
:
:
D
tls
Transport
::
Role
::
SERVER
:
json
[
k_dtlsLocalParameters
][
k_role
]
=
v_server
;
break
;
default
:
...
...
@@ -336,19 +338,19 @@ namespace RTC
// Add `dtlsState`.
switch
(
this
->
dtlsTransport
->
GetState
())
{
case
D
TLS
Transport
:
:
DtlsState
::
NEW
:
case
D
tls
Transport
:
:
DtlsState
::
NEW
:
json
[
k_dtlsState
]
=
v_new
;
break
;
case
D
TLS
Transport
:
:
DtlsState
::
CONNECTING
:
case
D
tls
Transport
:
:
DtlsState
::
CONNECTING
:
json
[
k_dtlsState
]
=
v_connecting
;
break
;
case
D
TLS
Transport
:
:
DtlsState
::
CONNECTED
:
case
D
tls
Transport
:
:
DtlsState
::
CONNECTED
:
json
[
k_dtlsState
]
=
v_connected
;
break
;
case
D
TLS
Transport
:
:
DtlsState
::
FAILED
:
case
D
tls
Transport
:
:
DtlsState
::
FAILED
:
json
[
k_dtlsState
]
=
v_failed
;
break
;
case
D
TLS
Transport
:
:
DtlsState
::
CLOSED
:
case
D
tls
Transport
:
:
DtlsState
::
CLOSED
:
json
[
k_dtlsState
]
=
v_closed
;
break
;
}
...
...
@@ -396,8 +398,8 @@ namespace RTC
static
const
Json
::
StaticString
k_algorithm
(
"algorithm"
);
static
const
Json
::
StaticString
k_value
(
"value"
);
RTC
::
D
TLS
Transport
::
Fingerprint
remoteFingerprint
;
RTC
::
D
TLSTransport
::
Role
remoteRole
=
RTC
::
DTLS
Transport
::
Role
::
AUTO
;
// Default value if missing.
RTC
::
D
tls
Transport
::
Fingerprint
remoteFingerprint
;
RTC
::
D
tlsTransport
::
Role
remoteRole
=
RTC
::
Dtls
Transport
::
Role
::
AUTO
;
// Default value if missing.
// Ensure this method is not called twice.
if
(
this
->
remoteDtlsParametersGiven
)
...
...
@@ -428,9 +430,9 @@ namespace RTC
return
;
}
remoteFingerprint
.
algorithm
=
RTC
::
D
TLS
Transport
::
GetFingerprintAlgorithm
(
request
->
data
[
k_fingerprint
][
k_algorithm
].
asString
());
remoteFingerprint
.
algorithm
=
RTC
::
D
tls
Transport
::
GetFingerprintAlgorithm
(
request
->
data
[
k_fingerprint
][
k_algorithm
].
asString
());
if
(
remoteFingerprint
.
algorithm
==
RTC
::
D
TLS
Transport
::
FingerprintAlgorithm
::
NONE
)
if
(
remoteFingerprint
.
algorithm
==
RTC
::
D
tls
Transport
::
FingerprintAlgorithm
::
NONE
)
{
MS_ERROR
(
"unsupported `data.fingerprint.algorithm`"
);
...
...
@@ -441,22 +443,22 @@ namespace RTC
remoteFingerprint
.
value
=
request
->
data
[
k_fingerprint
][
k_value
].
asString
();
if
(
request
->
data
[
k_role
].
isString
())
remoteRole
=
RTC
::
D
TLS
Transport
::
StringToRole
(
request
->
data
[
k_role
].
asString
());
remoteRole
=
RTC
::
D
tls
Transport
::
StringToRole
(
request
->
data
[
k_role
].
asString
());
// Set local DTLS role.
switch
(
remoteRole
)
{
case
RTC
:
:
D
TLS
Transport
::
Role
::
CLIENT
:
this
->
dtlsLocalRole
=
RTC
::
D
TLS
Transport
::
Role
::
SERVER
;
case
RTC
:
:
D
tls
Transport
::
Role
::
CLIENT
:
this
->
dtlsLocalRole
=
RTC
::
D
tls
Transport
::
Role
::
SERVER
;
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
SERVER
:
this
->
dtlsLocalRole
=
RTC
::
D
TLS
Transport
::
Role
::
CLIENT
;
case
RTC
:
:
D
tls
Transport
::
Role
::
SERVER
:
this
->
dtlsLocalRole
=
RTC
::
D
tls
Transport
::
Role
::
CLIENT
;
break
;
// If the peer has "auto" we become "client" since we are ICE controlled.
case
RTC
:
:
D
TLS
Transport
::
Role
::
AUTO
:
this
->
dtlsLocalRole
=
RTC
::
D
TLS
Transport
::
Role
::
CLIENT
;
case
RTC
:
:
D
tls
Transport
::
Role
::
AUTO
:
this
->
dtlsLocalRole
=
RTC
::
D
tls
Transport
::
Role
::
CLIENT
;
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
NONE
:
case
RTC
:
:
D
tls
Transport
::
Role
::
NONE
:
MS_ERROR
(
"invalid .role"
);
request
->
Reject
(
"invalid `data.role`"
);
...
...
@@ -467,10 +469,10 @@ namespace RTC
switch
(
this
->
dtlsLocalRole
)
{
case
RTC
:
:
D
TLS
Transport
::
Role
::
CLIENT
:
case
RTC
:
:
D
tls
Transport
::
Role
::
CLIENT
:
data
[
k_role
]
=
v_client
;
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
SERVER
:
case
RTC
:
:
D
tls
Transport
::
Role
::
SERVER
:
data
[
k_role
]
=
v_server
;
break
;
default
:
...
...
@@ -483,7 +485,7 @@ namespace RTC
this
->
dtlsTransport
->
SetRemoteFingerprint
(
remoteFingerprint
);
// Run the DTLS transport if ready.
MayRunD
TLS
Transport
();
MayRunD
tls
Transport
();
break
;
}
...
...
@@ -498,7 +500,7 @@ namespace RTC
}
inline
void
Transport
::
MayRunD
TLS
Transport
()
void
Transport
::
MayRunD
tls
Transport
()
{
MS_TRACE
();
...
...
@@ -512,42 +514,42 @@ namespace RTC
{
// If still 'auto' then transition to 'server' if ICE is 'connected' or
// 'completed'.
case
RTC
:
:
D
TLS
Transport
::
Role
::
AUTO
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
CE
Server
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
I
CE
Server
::
IceState
::
COMPLETED
)
case
RTC
:
:
D
tls
Transport
::
Role
::
AUTO
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
ce
Server
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
I
ce
Server
::
IceState
::
COMPLETED
)
{
MS_DEBUG
(
"transition from DTLS local role 'auto' to 'server' and running DTLS transport"
);
this
->
dtlsLocalRole
=
RTC
::
D
TLS
Transport
::
Role
::
SERVER
;
this
->
dtlsTransport
->
Run
(
RTC
::
D
TLS
Transport
::
Role
::
SERVER
);
this
->
dtlsLocalRole
=
RTC
::
D
tls
Transport
::
Role
::
SERVER
;
this
->
dtlsTransport
->
Run
(
RTC
::
D
tls
Transport
::
Role
::
SERVER
);
}
break
;
// 'client' is only set if a 'setRemoteDtlsParameters' request was previously
// received with remote DTLS role 'server'.
// If 'client' then wait for ICE to be 'completed' (got USE-CANDIDATE).
case
RTC
:
:
D
TLS
Transport
::
Role
::
CLIENT
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
CE
Server
::
IceState
::
COMPLETED
)
case
RTC
:
:
D
tls
Transport
::
Role
::
CLIENT
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
ce
Server
::
IceState
::
COMPLETED
)
{
MS_DEBUG
(
"running DTLS transport in local role 'client'"
);
this
->
dtlsTransport
->
Run
(
RTC
::
D
TLS
Transport
::
Role
::
CLIENT
);
this
->
dtlsTransport
->
Run
(
RTC
::
D
tls
Transport
::
Role
::
CLIENT
);
}
break
;
// If 'server' then run the DTLS transport if ICE is 'connected' (not yet
// USE-CANDIDATE) or 'completed'.
case
RTC
:
:
D
TLS
Transport
::
Role
::
SERVER
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
CE
Server
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
I
CE
Server
::
IceState
::
COMPLETED
)
case
RTC
:
:
D
tls
Transport
::
Role
::
SERVER
:
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
I
ce
Server
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
I
ce
Server
::
IceState
::
COMPLETED
)
{
MS_DEBUG
(
"running DTLS transport in local role 'server'"
);
this
->
dtlsTransport
->
Run
(
RTC
::
D
TLS
Transport
::
Role
::
SERVER
);
this
->
dtlsTransport
->
Run
(
RTC
::
D
tls
Transport
::
Role
::
SERVER
);
}
break
;
case
RTC
:
:
D
TLS
Transport
::
Role
::
NONE
:
case
RTC
:
:
D
tls
Transport
::
Role
::
NONE
:
MS_ABORT
(
"local DTLS role not set"
);
}
}
...
...
@@ -558,24 +560,24 @@ namespace RTC
MS_TRACE
();
// Check if it's STUN.
if
(
S
TUNMessage
::
IsSTUN
(
data
,
len
))
if
(
S
tunMessage
::
IsStun
(
data
,
len
))
{
onS
TUN
DataRecv
(
tuple
,
data
,
len
);
onS
tun
DataRecv
(
tuple
,
data
,
len
);
}
// Check if it's RTCP.
else
if
(
R
TCPPacket
::
IsRTCP
(
data
,
len
))
else
if
(
R
tcpPacket
::
IsRtcp
(
data
,
len
))
{
onR
TCP
DataRecv
(
tuple
,
data
,
len
);
onR
tcp
DataRecv
(
tuple
,
data
,
len
);
}
// Check if it's RTP.
else
if
(
R
TPPacket
::
IsRTP
(
data
,
len
))
else
if
(
R
tpPacket
::
IsRtp
(
data
,
len
))
{
onR
TP
DataRecv
(
tuple
,
data
,
len
);
onR
tp
DataRecv
(
tuple
,
data
,
len
);
}
// Check if it's DTLS.
else
if
(
D
TLSTransport
::
IsDTLS
(
data
,
len
))
else
if
(
D
tlsTransport
::
IsDtls
(
data
,
len
))
{
onD
TLS
DataRecv
(
tuple
,
data
,
len
);
onD
tls
DataRecv
(
tuple
,
data
,
len
);
}
else
{
...
...
@@ -585,11 +587,11 @@ namespace RTC
}
inline
void
Transport
::
onS
TUN
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onS
tun
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
RTC
::
S
TUNMessage
*
msg
=
RTC
::
STUN
Message
::
Parse
(
data
,
len
);
RTC
::
S
tunMessage
*
msg
=
RTC
::
Stun
Message
::
Parse
(
data
,
len
);
if
(
!
msg
)
{
MS_DEBUG
(
"ignoring wrong STUN message received"
);
...
...
@@ -597,14 +599,14 @@ namespace RTC
return
;
}
// Pass it to the I
CE
Server.
this
->
iceServer
->
ProcessS
TUN
Message
(
msg
,
tuple
);
// Pass it to the I
ce
Server.
this
->
iceServer
->
ProcessS
tun
Message
(
msg
,
tuple
);
delete
msg
;
}
inline
void
Transport
::
onD
TLS
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onD
tls
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -619,23 +621,23 @@ namespace RTC
this
->
iceServer
->
ForceSelectedTuple
(
tuple
);
// Check that DTLS status is 'connecting' or 'connected'.
if
(
this
->
dtlsTransport
->
GetState
()
==
D
TLS
Transport
::
DtlsState
::
CONNECTING
||
this
->
dtlsTransport
->
GetState
()
==
D
TLS
Transport
::
DtlsState
::
CONNECTED
)
if
(
this
->
dtlsTransport
->
GetState
()
==
D
tls
Transport
::
DtlsState
::
CONNECTING
||
this
->
dtlsTransport
->
GetState
()
==
D
tls
Transport
::
DtlsState
::
CONNECTED
)
{
MS_DEBUG
(
"DTLS data received, passing it to the DTLS transport"
);
this
->
dtlsTransport
->
ProcessD
TLS
Data
(
data
,
len
);
this
->
dtlsTransport
->
ProcessD
tls
Data
(
data
,
len
);
}
else
{
MS_DEBUG
(
"D
TLS
Transport is not 'connecting' or 'conneted', ignoring received DTLS data"
);
MS_DEBUG
(
"D
tls
Transport is not 'connecting' or 'conneted', ignoring received DTLS data"
);
return
;
}
}
inline
void
Transport
::
onR
TP
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onR
tp
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -657,7 +659,7 @@ namespace RTC
// TODO
// MS_DEBUG("received RTP data");
RTC
::
R
TPPacket
*
packet
=
RTC
::
RTP
Packet
::
Parse
(
data
,
len
);
RTC
::
R
tpPacket
*
packet
=
RTC
::
Rtp
Packet
::
Parse
(
data
,
len
);
if
(
!
packet
)
{
MS_DEBUG
(
"data received is not a valid RTP packet"
);
...
...
@@ -671,11 +673,11 @@ namespace RTC
if
(
!
rtpReceiver
)
{
// TODO: let's see
MS_WARN
(
"no suitable RtpReceiver for received RTP packet [ssrc:%"
PRIu32
", payload:%"
PRIu8
"]"
,
packet
->
GetS
SRC
(),
packet
->
GetPayloadType
());
MS_WARN
(
"no suitable RtpReceiver for received RTP packet [ssrc:%"
PRIu32
", payload:%"
PRIu8
"]"
,
packet
->
GetS
src
(),
packet
->
GetPayloadType
());
}
else
{
MS_DEBUG
(
"valid RTP packet received [ssrc:%"
PRIu32
", payload:%"
PRIu8
", rtpReceiver:%"
PRIu32
"]"
,
packet
->
GetS
SRC
(),
packet
->
GetPayloadType
(),
rtpReceiver
->
rtpReceiverId
);
MS_DEBUG
(
"valid RTP packet received [ssrc:%"
PRIu32
", payload:%"
PRIu8
", rtpReceiver:%"
PRIu32
"]"
,
packet
->
GetS
src
(),
packet
->
GetPayloadType
(),
rtpReceiver
->
rtpReceiverId
);
// packet->Dump();
}
...
...
@@ -683,7 +685,7 @@ namespace RTC
}
inline
void
Transport
::
onR
TCP
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onR
tcp
DataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -701,7 +703,7 @@ namespace RTC
MS_DEBUG
(
"received RTCP data"
);
}
void
Transport
::
onPacketRecv
(
RTC
::
U
DP
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
void
Transport
::
onPacketRecv
(
RTC
::
U
dp
Socket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
{
MS_TRACE
();
...
...
@@ -710,7 +712,7 @@ namespace RTC
onPacketRecv
(
&
tuple
,
data
,
len
);
}
void
Transport
::
onR
TCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
void
Transport
::
onR
tcTcpConnectionClosed
(
RTC
::
TcpServer
*
tcpServer
,
RTC
::
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
{
MS_TRACE
();
...
...
@@ -720,7 +722,7 @@ namespace RTC
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
}
void
Transport
::
onPacketRecv
(
RTC
::
T
CP
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onPacketRecv
(
RTC
::
T
cp
Connection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -729,7 +731,7 @@ namespace RTC
onPacketRecv
(
&
tuple
,
data
,
len
);
}
void
Transport
::
onOutgoingS
TUNMessage
(
RTC
::
ICEServer
*
iceServer
,
RTC
::
STUN
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
void
Transport
::
onOutgoingS
tunMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
Stun
Message
*
msg
,
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -737,7 +739,7 @@ namespace RTC
tuple
->
Send
(
msg
->
GetRaw
(),
msg
->
GetLength
());
}
void
Transport
::
onI
CESelectedTuple
(
RTC
::
ICE
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
void
Transport
::
onI
ceSelectedTuple
(
RTC
::
Ice
Server
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
...
...
@@ -760,7 +762,7 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"iceselectedtuplechange"
,
event_data
);
}
void
Transport
::
onI
CEConnected
(
RTC
::
ICE
Server
*
iceServer
)
void
Transport
::
onI
ceConnected
(
RTC
::
Ice
Server
*
iceServer
)
{
MS_TRACE
();
...
...
@@ -776,10 +778,10 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"icestatechange"
,
event_data
);
// If ready, run the DTLS handler.
MayRunD
TLS
Transport
();
MayRunD
tls
Transport
();
}
void
Transport
::
onI
CECompleted
(
RTC
::
ICE
Server
*
iceServer
)
void
Transport
::
onI
ceCompleted
(
RTC
::
Ice
Server
*
iceServer
)
{
MS_TRACE
();
...
...
@@ -795,10 +797,10 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"icestatechange"
,
event_data
);
// If ready, run the DTLS handler.
MayRunD
TLS
Transport
();
MayRunD
tls
Transport
();
}
void
Transport
::
onI
CEDisconnected
(
RTC
::
ICE
Server
*
iceServer
)
void
Transport
::
onI
ceDisconnected
(
RTC
::
Ice
Server
*
iceServer
)
{
MS_TRACE
();
...
...
@@ -820,7 +822,7 @@ namespace RTC
Close
();
}
void
Transport
::
onD
TLSConnecting
(
RTC
::
DTLS
Transport
*
dtlsTransport
)
void
Transport
::
onD
tlsConnecting
(
RTC
::
Dtls
Transport
*
dtlsTransport
)
{
MS_TRACE
();
...
...
@@ -836,7 +838,7 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
event_data
);
}
void
Transport
::
onD
TLSConnected
(
RTC
::
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTP
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
void
Transport
::
onD
tlsConnected
(
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
Srtp
Session
::
Profile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
{
MS_TRACE
();
...
...
@@ -856,7 +858,7 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
event_data
);
}
void
Transport
::
onD
TLSFailed
(
RTC
::
DTLS
Transport
*
dtlsTransport
)
void
Transport
::
onD
tlsFailed
(
RTC
::
Dtls
Transport
*
dtlsTransport
)
{
MS_TRACE
();
...
...
@@ -875,7 +877,7 @@ namespace RTC
Close
();
}
void
Transport
::
onD
TLSClosed
(
RTC
::
DTLS
Transport
*
dtlsTransport
)
void
Transport
::
onD
tlsClosed
(
RTC
::
Dtls
Transport
*
dtlsTransport
)
{
MS_TRACE
();
...
...
@@ -894,7 +896,7 @@ namespace RTC
Close
();
}
void
Transport
::
onOutgoingD
TLSData
(
RTC
::
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onOutgoingD
tlsData
(
RTC
::
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -911,7 +913,7 @@ namespace RTC
this
->
selectedTuple
->
Send
(
data
,
len
);
}
void
Transport
::
onD
TLSApplicationData
(
RTC
::
DTLS
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
void
Transport
::
onD
tlsApplicationData
(
RTC
::
Dtls
Transport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
worker/src/RTC/U
DP
Socket.cpp
→
worker/src/RTC/U
dp
Socket.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "RTC::U
DP
Socket"
#define MS_CLASS "RTC::U
dp
Socket"
#include "RTC/U
DP
Socket.h"
#include "RTC/U
dp
Socket.h"
#include "Settings.h"
#include "Utils.h"
#include "DepLibUV.h"
...
...
@@ -22,16 +22,16 @@ namespace RTC
{
/* Class variables. */
struct
sockaddr_storage
U
DP
Socket
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
U
DP
Socket
::
sockaddrStorageIPv6
;
uint16_t
U
DP
Socket
::
minPort
;
uint16_t
U
DP
Socket
::
maxPort
;
std
::
unordered_map
<
uint16_t
,
bool
>
U
DP
Socket
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
U
DP
Socket
::
availableIPv6Ports
;
struct
sockaddr_storage
U
dp
Socket
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
U
dp
Socket
::
sockaddrStorageIPv6
;
uint16_t
U
dp
Socket
::
minPort
;
uint16_t
U
dp
Socket
::
maxPort
;
std
::
unordered_map
<
uint16_t
,
bool
>
U
dp
Socket
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
U
dp
Socket
::
availableIPv6Ports
;
/* Class methods. */
void
U
DP
Socket
::
ClassInit
()
void
U
dp
Socket
::
ClassInit
()
{
MS_TRACE
();
...
...
@@ -39,31 +39,31 @@ namespace RTC
if
(
Settings
::
configuration
.
hasIPv4
)
{
err
=
uv_ip4_addr
(
Settings
::
configuration
.
rtcListenIPv4
.
c_str
(),
0
,
(
struct
sockaddr_in
*
)
&
RTC
::
U
DP
Socket
::
sockaddrStorageIPv4
);
err
=
uv_ip4_addr
(
Settings
::
configuration
.
rtcListenIPv4
.
c_str
(),
0
,
(
struct
sockaddr_in
*
)
&
RTC
::
U
dp
Socket
::
sockaddrStorageIPv4
);
if
(
err
)
MS_ABORT
(
"uv_ipv4_addr() failed: %s"
,
uv_strerror
(
err
));
}
if
(
Settings
::
configuration
.
hasIPv6
)
{
err
=
uv_ip6_addr
(
Settings
::
configuration
.
rtcListenIPv6
.
c_str
(),
0
,
(
struct
sockaddr_in6
*
)
&
RTC
::
U
DP
Socket
::
sockaddrStorageIPv6
);
err
=
uv_ip6_addr
(
Settings
::
configuration
.
rtcListenIPv6
.
c_str
(),
0
,
(
struct
sockaddr_in6
*
)
&
RTC
::
U
dp
Socket
::
sockaddrStorageIPv6
);
if
(
err
)
MS_ABORT
(
"uv_ipv6_addr() failed: %s"
,
uv_strerror
(
err
));
}
U
DP
Socket
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
U
DP
Socket
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
U
dp
Socket
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
U
dp
Socket
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
uint16_t
i
=
RTC
::
U
DP
Socket
::
minPort
;
uint16_t
i
=
RTC
::
U
dp
Socket
::
minPort
;
do
{
RTC
::
U
DP
Socket
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
U
DP
Socket
::
availableIPv6Ports
[
i
]
=
true
;
RTC
::
U
dp
Socket
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
U
dp
Socket
::
availableIPv6Ports
[
i
]
=
true
;
}
while
(
i
++
!=
RTC
::
U
DP
Socket
::
maxPort
);
while
(
i
++
!=
RTC
::
U
dp
Socket
::
maxPort
);
}
uv_udp_t
*
U
DP
Socket
::
GetRandomPort
(
int
address_family
)
uv_udp_t
*
U
dp
Socket
::
GetRandomPort
(
int
address_family
)
{
MS_TRACE
();
...
...
@@ -86,14 +86,14 @@ namespace RTC
switch
(
address_family
)
{
case
AF_INET
:
available_ports
=
&
RTC
::
U
DP
Socket
::
availableIPv4Ports
;
bind_addr
=
RTC
::
U
DP
Socket
::
sockaddrStorageIPv4
;
available_ports
=
&
RTC
::
U
dp
Socket
::
availableIPv4Ports
;
bind_addr
=
RTC
::
U
dp
Socket
::
sockaddrStorageIPv4
;
listen_ip
=
Settings
::
configuration
.
rtcListenIPv4
.
c_str
();
break
;
case
AF_INET6
:
available_ports
=
&
RTC
::
U
DP
Socket
::
availableIPv6Ports
;
bind_addr
=
RTC
::
U
DP
Socket
::
sockaddrStorageIPv6
;
available_ports
=
&
RTC
::
U
dp
Socket
::
availableIPv6Ports
;
bind_addr
=
RTC
::
U
dp
Socket
::
sockaddrStorageIPv6
;
listen_ip
=
Settings
::
configuration
.
rtcListenIPv6
.
c_str
();
// Don't also bind into IPv4 when listening in IPv6.
flags
|=
UV_UDP_IPV6ONLY
;
...
...
@@ -105,7 +105,7 @@ namespace RTC
}
// Choose a random port to start from.
initial_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
U
DPSocket
::
minPort
,
(
uint32_t
)
RTC
::
UDP
Socket
::
maxPort
);
initial_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
U
dpSocket
::
minPort
,
(
uint32_t
)
RTC
::
Udp
Socket
::
maxPort
);
iterating_port
=
initial_port
;
...
...
@@ -116,10 +116,10 @@ namespace RTC
attempt
++
;
// Increase the iterate port within the range of RTC UDP ports.
if
(
iterating_port
<
RTC
::
U
DP
Socket
::
maxPort
)
if
(
iterating_port
<
RTC
::
U
dp
Socket
::
maxPort
)
iterating_port
++
;
else
iterating_port
=
RTC
::
U
DP
Socket
::
minPort
;
iterating_port
=
RTC
::
U
dp
Socket
::
minPort
;
// Check whether the chosen port is available.
if
(
!
(
*
available_ports
)[
iterating_port
])
...
...
@@ -200,17 +200,17 @@ namespace RTC
/* Instance methods. */
U
DPSocket
::
UDP
Socket
(
Listener
*
listener
,
int
address_family
)
:
U
dpSocket
::
Udp
Socket
(
Listener
*
listener
,
int
address_family
)
:
// Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports.
::
U
DPSocket
::
UDP
Socket
(
GetRandomPort
(
address_family
)),
::
U
dpSocket
::
Udp
Socket
(
GetRandomPort
(
address_family
)),
listener
(
listener
)
{
MS_TRACE
();
}
void
U
DPSocket
::
userOnUDP
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
void
U
dpSocket
::
userOnUdp
DatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
{
MS_TRACE
();
...
...
@@ -236,14 +236,14 @@ namespace RTC
this
->
listener
->
onPacketRecv
(
this
,
data
,
len
,
addr
);
}
void
U
DPSocket
::
userOnUDP
SocketClosed
()
void
U
dpSocket
::
userOnUdp
SocketClosed
()
{
MS_TRACE
();
// Mark the port as available again.
if
(
this
->
localAddr
.
ss_family
==
AF_INET
)
RTC
::
U
DP
Socket
::
availableIPv4Ports
[
this
->
localPort
]
=
true
;
RTC
::
U
dp
Socket
::
availableIPv4Ports
[
this
->
localPort
]
=
true
;
else
if
(
this
->
localAddr
.
ss_family
==
AF_INET6
)
RTC
::
U
DP
Socket
::
availableIPv6Ports
[
this
->
localPort
]
=
true
;
RTC
::
U
dp
Socket
::
availableIPv6Ports
[
this
->
localPort
]
=
true
;
}
}
worker/src/handles/T
CP
Connection.cpp
→
worker/src/handles/T
cp
Connection.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "T
CP
Connection"
#define MS_CLASS "T
cp
Connection"
#include "handles/T
CP
Connection.h"
#include "handles/T
cp
Connection.h"
#include "Utils.h"
#include "DepLibUV.h"
#include "MediaSoupError.h"
...
...
@@ -13,25 +13,25 @@
static
inline
void
on_alloc
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
static_cast
<
T
CP
Connection
*>
(
handle
->
data
)
->
onUvReadAlloc
(
suggested_size
,
buf
);
static_cast
<
T
cp
Connection
*>
(
handle
->
data
)
->
onUvReadAlloc
(
suggested_size
,
buf
);
}
static
inline
void
on_read
(
uv_stream_t
*
handle
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
static_cast
<
T
CP
Connection
*>
(
handle
->
data
)
->
onUvRead
(
nread
,
buf
);
static_cast
<
T
cp
Connection
*>
(
handle
->
data
)
->
onUvRead
(
nread
,
buf
);
}
static
inline
void
on_write
(
uv_write_t
*
req
,
int
status
)
{
T
CPConnection
::
UvWriteData
*
write_data
=
static_cast
<
TCP
Connection
::
UvWriteData
*>
(
req
->
data
);
T
CP
Connection
*
connection
=
write_data
->
connection
;
T
cpConnection
::
UvWriteData
*
write_data
=
static_cast
<
Tcp
Connection
::
UvWriteData
*>
(
req
->
data
);
T
cp
Connection
*
connection
=
write_data
->
connection
;
// Delete the UvWriteData struct (which includes the uv_req_t and the store char[]).
std
::
free
(
write_data
);
// Just notify the T
CP
Connection when error.
// Just notify the T
cp
Connection when error.
if
(
status
)
connection
->
onUvWriteError
(
status
);
}
...
...
@@ -39,18 +39,18 @@ void on_write(uv_write_t* req, int status)
static
inline
void
on_shutdown
(
uv_shutdown_t
*
req
,
int
status
)
{
static_cast
<
T
CP
Connection
*>
(
req
->
data
)
->
onUvShutdown
(
req
,
status
);
static_cast
<
T
cp
Connection
*>
(
req
->
data
)
->
onUvShutdown
(
req
,
status
);
}
static
inline
void
on_close
(
uv_handle_t
*
handle
)
{
static_cast
<
T
CP
Connection
*>
(
handle
->
data
)
->
onUvClosed
();
static_cast
<
T
cp
Connection
*>
(
handle
->
data
)
->
onUvClosed
();
}
/* Instance methods. */
T
CPConnection
::
TCP
Connection
(
size_t
bufferSize
)
:
T
cpConnection
::
Tcp
Connection
(
size_t
bufferSize
)
:
bufferSize
(
bufferSize
)
{
MS_TRACE
();
...
...
@@ -61,7 +61,7 @@ TCPConnection::TCPConnection(size_t bufferSize) :
// NOTE: Don't allocate the buffer here. Instead wait for the first uv_alloc_cb().
}
T
CPConnection
::~
TCP
Connection
()
T
cpConnection
::~
Tcp
Connection
()
{
MS_TRACE
();
...
...
@@ -71,7 +71,7 @@ TCPConnection::~TCPConnection()
delete
[]
this
->
buffer
;
}
void
T
CP
Connection
::
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
uint16_t
localPort
)
void
T
cp
Connection
::
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
uint16_t
localPort
)
{
MS_TRACE
();
...
...
@@ -95,7 +95,7 @@ void TCPConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr
this
->
localPort
=
localPort
;
}
void
T
CP
Connection
::
Close
()
void
T
cp
Connection
::
Close
()
{
MS_TRACE
();
...
...
@@ -129,15 +129,15 @@ void TCPConnection::Close()
}
}
void
T
CP
Connection
::
Dump
()
void
T
cp
Connection
::
Dump
()
{
MS_DEBUG
(
"[T
CP
, local:%s :%"
PRIu16
", remote:%s :%"
PRIu16
", status:%s]"
,
MS_DEBUG
(
"[T
cp
, local:%s :%"
PRIu16
", remote:%s :%"
PRIu16
", status:%s]"
,
this
->
localIP
.
c_str
(),
(
uint16_t
)
this
->
localPort
,
this
->
peerIP
.
c_str
(),
(
uint16_t
)
this
->
peerPort
,
(
!
this
->
isClosing
)
?
"open"
:
"closed"
);
}
void
T
CP
Connection
::
Start
()
void
T
cp
Connection
::
Start
()
{
MS_TRACE
();
...
...
@@ -155,7 +155,7 @@ void TCPConnection::Start()
MS_THROW_ERROR
(
"error setting peer IP and port"
);
}
void
T
CP
Connection
::
Write
(
const
uint8_t
*
data
,
size_t
len
)
void
T
cp
Connection
::
Write
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
...
...
@@ -213,7 +213,7 @@ void TCPConnection::Write(const uint8_t* data, size_t len)
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
}
void
T
CP
Connection
::
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
)
void
T
cp
Connection
::
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
)
{
MS_TRACE
();
...
...
@@ -283,7 +283,7 @@ void TCPConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
}
bool
T
CP
Connection
::
SetPeerAddress
()
bool
T
cp
Connection
::
SetPeerAddress
()
{
MS_TRACE
();
...
...
@@ -305,7 +305,7 @@ bool TCPConnection::SetPeerAddress()
}
inline
void
T
CP
Connection
::
onUvReadAlloc
(
size_t
suggested_size
,
uv_buf_t
*
buf
)
void
T
cp
Connection
::
onUvReadAlloc
(
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
MS_TRACE
();
...
...
@@ -329,7 +329,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
}
inline
void
T
CP
Connection
::
onUvRead
(
ssize_t
nread
,
const
uv_buf_t
*
buf
)
void
T
cp
Connection
::
onUvRead
(
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
MS_TRACE
();
...
...
@@ -346,7 +346,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
this
->
bufferDataLen
+=
(
size_t
)
nread
;
// Notify the subclass.
userOnT
CP
ConnectionRead
();
userOnT
cp
ConnectionRead
();
}
// Client disconneted.
else
if
(
nread
==
UV_EOF
||
nread
==
UV_ECONNRESET
)
...
...
@@ -371,7 +371,7 @@ void TCPConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
}
inline
void
T
CP
Connection
::
onUvWriteError
(
int
error
)
void
T
cp
Connection
::
onUvWriteError
(
int
error
)
{
MS_TRACE
();
...
...
@@ -393,7 +393,7 @@ void TCPConnection::onUvWriteError(int error)
}
inline
void
T
CP
Connection
::
onUvShutdown
(
uv_shutdown_t
*
req
,
int
status
)
void
T
cp
Connection
::
onUvShutdown
(
uv_shutdown_t
*
req
,
int
status
)
{
MS_TRACE
();
...
...
@@ -409,12 +409,12 @@ void TCPConnection::onUvShutdown(uv_shutdown_t* req, int status)
}
inline
void
T
CP
Connection
::
onUvClosed
()
void
T
cp
Connection
::
onUvClosed
()
{
MS_TRACE
();
// Notify the listener.
this
->
listener
->
onT
CP
ConnectionClosed
(
this
,
this
->
isClosedByPeer
);
this
->
listener
->
onT
cp
ConnectionClosed
(
this
,
this
->
isClosedByPeer
);
// And delete this.
delete
this
;
...
...
worker/src/handles/T
CP
Server.cpp
→
worker/src/handles/T
cp
Server.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "T
CP
Server"
#define MS_CLASS "T
cp
Server"
#include "handles/T
CP
Server.h"
#include "handles/T
cp
Server.h"
#include "Utils.h"
#include "DepLibUV.h"
#include "MediaSoupError.h"
...
...
@@ -11,13 +11,13 @@
static
inline
void
on_connection
(
uv_stream_t
*
handle
,
int
status
)
{
static_cast
<
T
CP
Server
*>
(
handle
->
data
)
->
onUvConnection
(
status
);
static_cast
<
T
cp
Server
*>
(
handle
->
data
)
->
onUvConnection
(
status
);
}
static
inline
void
on_close
(
uv_handle_t
*
handle
)
{
static_cast
<
T
CP
Server
*>
(
handle
->
data
)
->
onUvClosed
();
static_cast
<
T
cp
Server
*>
(
handle
->
data
)
->
onUvClosed
();
}
static
inline
...
...
@@ -28,7 +28,7 @@ void on_error_close(uv_handle_t* handle)
/* Instance methods. */
T
CPServer
::
TCP
Server
(
const
std
::
string
&
ip
,
uint16_t
port
,
int
backlog
)
T
cpServer
::
Tcp
Server
(
const
std
::
string
&
ip
,
uint16_t
port
,
int
backlog
)
{
MS_TRACE
();
...
...
@@ -92,7 +92,7 @@ TCPServer::TCPServer(const std::string &ip, uint16_t port, int backlog)
}
}
T
CPServer
::
TCP
Server
(
uv_tcp_t
*
uvHandle
,
int
backlog
)
:
T
cpServer
::
Tcp
Server
(
uv_tcp_t
*
uvHandle
,
int
backlog
)
:
uvHandle
(
uvHandle
)
{
MS_TRACE
();
...
...
@@ -116,7 +116,7 @@ TCPServer::TCPServer(uv_tcp_t* uvHandle, int backlog) :
}
}
T
CPServer
::~
TCP
Server
()
T
cpServer
::~
Tcp
Server
()
{
MS_TRACE
();
...
...
@@ -124,7 +124,7 @@ TCPServer::~TCPServer()
delete
this
->
uvHandle
;
}
void
T
CP
Server
::
Close
()
void
T
cp
Server
::
Close
()
{
MS_TRACE
();
...
...
@@ -145,13 +145,13 @@ void TCPServer::Close()
for
(
auto
it
=
this
->
connections
.
begin
();
it
!=
this
->
connections
.
end
();
++
it
)
{
T
CP
Connection
*
connection
=
*
it
;
T
cp
Connection
*
connection
=
*
it
;
connection
->
Close
();
}
}
}
void
T
CP
Server
::
Dump
()
void
T
cp
Server
::
Dump
()
{
MS_DEBUG
(
"[TCP, local:%s :%"
PRIu16
", status:%s, connections:%zu]"
,
this
->
localIP
.
c_str
(),
(
uint16_t
)
this
->
localPort
,
...
...
@@ -159,28 +159,28 @@ void TCPServer::Dump()
this
->
connections
.
size
());
}
const
struct
sockaddr
*
T
CP
Server
::
GetLocalAddress
()
const
struct
sockaddr
*
T
cp
Server
::
GetLocalAddress
()
{
MS_TRACE
();
return
(
const
struct
sockaddr
*
)
&
this
->
localAddr
;
}
const
std
::
string
&
T
CP
Server
::
GetLocalIP
()
const
std
::
string
&
T
cp
Server
::
GetLocalIP
()
{
MS_TRACE
();
return
this
->
localIP
;
}
uint16_t
T
CP
Server
::
GetLocalPort
()
uint16_t
T
cp
Server
::
GetLocalPort
()
{
MS_TRACE
();
return
this
->
localPort
;
}
bool
T
CP
Server
::
SetLocalAddress
()
bool
T
cp
Server
::
SetLocalAddress
()
{
MS_TRACE
();
...
...
@@ -202,7 +202,7 @@ bool TCPServer::SetLocalAddress()
}
inline
void
T
CP
Server
::
onUvConnection
(
int
status
)
void
T
cp
Server
::
onUvConnection
(
int
status
)
{
MS_TRACE
();
...
...
@@ -219,9 +219,9 @@ void TCPServer::onUvConnection(int status)
}
// Notify the subclass so it provides an allocated derived class of TCPConnection.
T
CP
Connection
*
connection
=
nullptr
;
userOnT
CP
ConnectionAlloc
(
&
connection
);
MS_ASSERT
(
connection
!=
nullptr
,
"T
CP
Connection pointer was not allocated by the user"
);
T
cp
Connection
*
connection
=
nullptr
;
userOnT
cp
ConnectionAlloc
(
&
connection
);
MS_ASSERT
(
connection
!=
nullptr
,
"T
cp
Connection pointer was not allocated by the user"
);
try
{
...
...
@@ -238,7 +238,7 @@ void TCPServer::onUvConnection(int status)
if
(
err
)
MS_ABORT
(
"uv_accept() failed: %s"
,
uv_strerror
(
err
));
// Insert the T
CP
Connection in the set.
// Insert the T
cp
Connection in the set.
this
->
connections
.
insert
(
connection
);
// Start receiving data.
...
...
@@ -249,56 +249,55 @@ void TCPServer::onUvConnection(int status)
catch
(
const
MediaSoupError
&
error
)
{
MS_ERROR
(
"cannot run the TCP connection, closing the connection: %s"
,
error
.
what
());
connection
->
Close
();
// NOTE: Don't return here so the user won't be notified about a "onclose" for a TCP connection
// for which there was not a previous "onnew" event.
}
MS_DEBUG
(
"new TCP connection:"
);
connection
->
Dump
();
// NOTE: Don't return here so the user won't be notified about a TCP connection
// closure for which there was not a previous creation event.
}
// Notify the subclass.
userOnNewT
CP
Connection
(
connection
);
userOnNewT
cp
Connection
(
connection
);
}
inline
void
T
CP
Server
::
onUvClosed
()
void
T
cp
Server
::
onUvClosed
()
{
MS_TRACE
();
// Motify the subclass.
userOnT
CP
ServerClosed
();
userOnT
cp
ServerClosed
();
// And delete this.
delete
this
;
}
inline
void
T
CPServer
::
onTCPConnectionClosed
(
TCP
Connection
*
connection
,
bool
is_closed_by_peer
)
void
T
cpServer
::
onTcpConnectionClosed
(
Tcp
Connection
*
connection
,
bool
is_closed_by_peer
)
{
MS_TRACE
();
// NOTE:
// Worst scenario is that in which this is the latest connection,
// which is remotely closed (no T
CP
Server.Close() was called) and the user
// call T
CPServer.Close() on userOnTCP
ConnectionClosed() callback, so Close()
// which is remotely closed (no T
cp
Server.Close() was called) and the user
// call T
cpServer.Close() on userOnTcp
ConnectionClosed() callback, so Close()
// is called with zero connections and calls uv_close(), but then
// onT
CP
ConnectionClosed() continues and finds that isClosing is true and
// onT
cp
ConnectionClosed() continues and finds that isClosing is true and
// there are zero connections, so calls uv_close() again and get a crash.
//
// SOLUTION:
// Check isClosing value *before* onT
CP
ConnectionClosed() callback.
// Check isClosing value *before* onT
cp
ConnectionClosed() callback.
bool
wasClosing
=
this
->
isClosing
;
MS_DEBUG
(
"TCP connection closed:"
);
connection
->
Dump
();
// Remove the T
CP
Connection from the set.
// Remove the T
cp
Connection from the set.
this
->
connections
.
erase
(
connection
);
// Notify the subclass.
userOnT
CP
ConnectionClosed
(
connection
,
is_closed_by_peer
);
userOnT
cp
ConnectionClosed
(
connection
,
is_closed_by_peer
);
// Check if the server was closing connections, and if this is the last
// connection then close the server now.
...
...
worker/src/handles/U
DP
Socket.cpp
→
worker/src/handles/U
dp
Socket.cpp
浏览文件 @
e5ee62f1
#define MS_CLASS "U
DP
Socket"
#define MS_CLASS "U
dp
Socket"
#include "handles/U
DP
Socket.h"
#include "handles/U
dp
Socket.h"
#include "Utils.h"
#include "DepLibUV.h"
#include "MediaSoupError.h"
...
...
@@ -13,25 +13,25 @@
static
inline
void
on_alloc
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
static_cast
<
U
DP
Socket
*>
(
handle
->
data
)
->
onUvRecvAlloc
(
suggested_size
,
buf
);
static_cast
<
U
dp
Socket
*>
(
handle
->
data
)
->
onUvRecvAlloc
(
suggested_size
,
buf
);
}
static
inline
void
on_recv
(
uv_udp_t
*
handle
,
ssize_t
nread
,
const
uv_buf_t
*
buf
,
const
struct
sockaddr
*
addr
,
unsigned
int
flags
)
{
static_cast
<
U
DP
Socket
*>
(
handle
->
data
)
->
onUvRecv
(
nread
,
buf
,
addr
,
flags
);
static_cast
<
U
dp
Socket
*>
(
handle
->
data
)
->
onUvRecv
(
nread
,
buf
,
addr
,
flags
);
}
static
inline
void
on_send
(
uv_udp_send_t
*
req
,
int
status
)
{
U
DPSocket
::
UvSendData
*
send_data
=
static_cast
<
UDP
Socket
::
UvSendData
*>
(
req
->
data
);
U
DP
Socket
*
socket
=
send_data
->
socket
;
U
dpSocket
::
UvSendData
*
send_data
=
static_cast
<
Udp
Socket
::
UvSendData
*>
(
req
->
data
);
U
dp
Socket
*
socket
=
send_data
->
socket
;
// Delete the UvSendData struct (which includes the uv_req_t and the store char[]).
std
::
free
(
send_data
);
// Just notify the U
DP
Socket when error.
// Just notify the U
dp
Socket when error.
if
(
status
)
socket
->
onUvSendError
(
status
);
}
...
...
@@ -39,7 +39,7 @@ void on_send(uv_udp_send_t* req, int status)
static
inline
void
on_close
(
uv_handle_t
*
handle
)
{
static_cast
<
U
DP
Socket
*>
(
handle
->
data
)
->
onUvClosed
();
static_cast
<
U
dp
Socket
*>
(
handle
->
data
)
->
onUvClosed
();
}
static
inline
...
...
@@ -50,11 +50,11 @@ void on_error_close(uv_handle_t* handle)
/* Class variables. */
uint8_t
U
DP
Socket
::
readBuffer
[
MS_READ_BUFFER_SIZE
];
uint8_t
U
dp
Socket
::
readBuffer
[
MS_READ_BUFFER_SIZE
];
/* Instance methods. */
U
DPSocket
::
UDP
Socket
(
const
std
::
string
&
ip
,
uint16_t
port
)
U
dpSocket
::
Udp
Socket
(
const
std
::
string
&
ip
,
uint16_t
port
)
{
MS_TRACE
();
...
...
@@ -118,7 +118,7 @@ UDPSocket::UDPSocket(const std::string &ip, uint16_t port)
}
}
U
DPSocket
::
UDP
Socket
(
uv_udp_t
*
uvHandle
)
:
U
dpSocket
::
Udp
Socket
(
uv_udp_t
*
uvHandle
)
:
uvHandle
(
uvHandle
)
{
MS_TRACE
();
...
...
@@ -142,7 +142,7 @@ UDPSocket::UDPSocket(uv_udp_t* uvHandle) :
}
}
U
DPSocket
::~
UDP
Socket
()
U
dpSocket
::~
Udp
Socket
()
{
MS_TRACE
();
...
...
@@ -150,7 +150,7 @@ UDPSocket::~UDPSocket()
delete
this
->
uvHandle
;
}
void
U
DP
Socket
::
Close
()
void
U
dp
Socket
::
Close
()
{
MS_TRACE
();
...
...
@@ -169,14 +169,14 @@ void UDPSocket::Close()
uv_close
((
uv_handle_t
*
)
this
->
uvHandle
,
(
uv_close_cb
)
on_close
);
}
void
U
DP
Socket
::
Dump
()
void
U
dp
Socket
::
Dump
()
{
MS_DEBUG
(
"[UDP, local:%s :%"
PRIu16
", status:%s]"
,
this
->
localIP
.
c_str
(),
(
uint16_t
)
this
->
localPort
,
(
!
this
->
isClosing
)
?
"open"
:
"closed"
);
}
void
U
DP
Socket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
void
U
dp
Socket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
{
MS_TRACE
();
...
...
@@ -239,7 +239,7 @@ void UDPSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
}
}
void
U
DP
Socket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
uint16_t
port
)
void
U
dp
Socket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
uint16_t
port
)
{
MS_TRACE
();
...
...
@@ -276,7 +276,7 @@ void UDPSocket::Send(const uint8_t* data, size_t len, const std::string &ip, uin
Send
(
data
,
len
,
(
struct
sockaddr
*
)
&
addr
);
}
bool
U
DP
Socket
::
SetLocalAddress
()
bool
U
dp
Socket
::
SetLocalAddress
()
{
MS_TRACE
();
...
...
@@ -298,18 +298,18 @@ bool UDPSocket::SetLocalAddress()
}
inline
void
U
DP
Socket
::
onUvRecvAlloc
(
size_t
suggested_size
,
uv_buf_t
*
buf
)
void
U
dp
Socket
::
onUvRecvAlloc
(
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
MS_TRACE
();
// Tell UV to write into the static buffer.
buf
->
base
=
(
char
*
)
U
DP
Socket
::
readBuffer
;
buf
->
base
=
(
char
*
)
U
dp
Socket
::
readBuffer
;
// Give UV all the buffer space.
buf
->
len
=
MS_READ_BUFFER_SIZE
;
}
inline
void
U
DP
Socket
::
onUvRecv
(
ssize_t
nread
,
const
uv_buf_t
*
buf
,
const
struct
sockaddr
*
addr
,
unsigned
int
flags
)
void
U
dp
Socket
::
onUvRecv
(
ssize_t
nread
,
const
uv_buf_t
*
buf
,
const
struct
sockaddr
*
addr
,
unsigned
int
flags
)
{
MS_TRACE
();
...
...
@@ -333,7 +333,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
if
(
nread
>
0
)
{
// Notify the subclass.
userOnU
DP
DatagramRecv
((
uint8_t
*
)
buf
->
base
,
nread
,
addr
);
userOnU
dp
DatagramRecv
((
uint8_t
*
)
buf
->
base
,
nread
,
addr
);
}
// Some error.
...
...
@@ -344,7 +344,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
}
inline
void
U
DP
Socket
::
onUvSendError
(
int
error
)
void
U
dp
Socket
::
onUvSendError
(
int
error
)
{
MS_TRACE
();
...
...
@@ -355,12 +355,12 @@ void UDPSocket::onUvSendError(int error)
}
inline
void
U
DP
Socket
::
onUvClosed
()
void
U
dp
Socket
::
onUvClosed
()
{
MS_TRACE
();
// Notify the subclass.
userOnU
DP
SocketClosed
();
userOnU
dp
SocketClosed
();
// And delete this.
delete
this
;
...
...
worker/src/main.cpp
浏览文件 @
e5ee62f1
...
...
@@ -8,10 +8,10 @@
#include "DepUsrSCTP.h"
#include "Utils.h"
#include "Channel/UnixStreamSocket.h"
#include "RTC/U
DP
Socket.h"
#include "RTC/T
CP
Server.h"
#include "RTC/D
TLS
Transport.h"
#include "RTC/S
RTP
Session.h"
#include "RTC/U
dp
Socket.h"
#include "RTC/T
cp
Server.h"
#include "RTC/D
tls
Transport.h"
#include "RTC/S
rtp
Session.h"
#include "Loop.h"
#include "MediaSoupError.h"
#include "Logger.h"
...
...
@@ -115,10 +115,10 @@ void init()
DepOpenSSL
::
ClassInit
();
DepLibSRTP
::
ClassInit
();
DepUsrSCTP
::
ClassInit
();
RTC
::
U
DP
Socket
::
ClassInit
();
RTC
::
T
CP
Server
::
ClassInit
();
RTC
::
D
TLS
Transport
::
ClassInit
();
RTC
::
S
RTP
Session
::
ClassInit
();
RTC
::
U
dp
Socket
::
ClassInit
();
RTC
::
T
cp
Server
::
ClassInit
();
RTC
::
D
tls
Transport
::
ClassInit
();
RTC
::
S
rtp
Session
::
ClassInit
();
Utils
::
Crypto
::
ClassInit
();
}
...
...
@@ -163,7 +163,7 @@ void destroy()
DepOpenSSL
::
ClassDestroy
();
DepLibSRTP
::
ClassDestroy
();
DepUsrSCTP
::
ClassDestroy
();
RTC
::
D
TLS
Transport
::
ClassDestroy
();
RTC
::
D
tls
Transport
::
ClassDestroy
();
Utils
::
Crypto
::
ClassDestroy
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论