Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
d318e260
提交
d318e260
authored
1月 03, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Work in DTLS stuff
上级
b13a9214
全部展开
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
343 行增加
和
108 行删除
+343
-108
Transport.js
lib/Transport.js
+11
-1
server.js
tester/server/server.js
+1
-1
DTLSTransport.h
worker/include/RTC/DTLSTransport.h
+73
-35
Transport.h
worker/include/RTC/Transport.h
+53
-24
TCPConnection.h
worker/include/handles/TCPConnection.h
+2
-2
UDPSocket.h
worker/include/handles/UDPSocket.h
+2
-2
UnixStreamSocket.h
worker/include/handles/UnixStreamSocket.h
+2
-2
DTLSTransport.cpp
worker/src/RTC/DTLSTransport.cpp
+0
-0
TCPConnection.cpp
worker/src/RTC/TCPConnection.cpp
+2
-2
Transport.cpp
worker/src/RTC/Transport.cpp
+191
-33
UDPSocket.cpp
worker/src/RTC/UDPSocket.cpp
+2
-2
TCPConnection.cpp
worker/src/handles/TCPConnection.cpp
+1
-1
main.cpp
worker/src/main.cpp
+3
-3
没有找到文件。
lib/Transport.js
浏览文件 @
d318e260
...
@@ -128,6 +128,11 @@ class Transport extends EventEmitter
...
@@ -128,6 +128,11 @@ class Transport extends EventEmitter
});
});
}
}
/**
* Start the DTLS stack
* @param {Object} remoteDtlsParameters Remote DTLS parameters
* @return {Promise}
*/
start
(
remoteDtlsParameters
)
start
(
remoteDtlsParameters
)
{
{
logger
.
debug
(
'start() [remoteDtlsParameters:%o]'
,
remoteDtlsParameters
);
logger
.
debug
(
'start() [remoteDtlsParameters:%o]'
,
remoteDtlsParameters
);
...
@@ -140,7 +145,8 @@ class Transport extends EventEmitter
...
@@ -140,7 +145,8 @@ class Transport extends EventEmitter
roomId
:
this
.
_roomId
,
roomId
:
this
.
_roomId
,
peerId
:
this
.
_peerId
,
peerId
:
this
.
_peerId
,
transportId
:
this
.
_transportId
,
transportId
:
this
.
_transportId
,
remoteDtlsParameters
:
remoteDtlsParameters
role
:
remoteDtlsParameters
.
role
,
fingerprint
:
remoteDtlsParameters
.
fingerprint
};
};
// Send Channel request
// Send Channel request
...
@@ -155,6 +161,10 @@ class Transport extends EventEmitter
...
@@ -155,6 +161,10 @@ class Transport extends EventEmitter
});
});
}
}
/**
* Create an asociated Transport for RTCP
* @return {Promise}
*/
createAssociatedTransport
()
createAssociatedTransport
()
{
{
logger
.
debug
(
'createAssociatedTransport()'
);
logger
.
debug
(
'createAssociatedTransport()'
);
...
...
tester/server/server.js
浏览文件 @
d318e260
...
@@ -177,7 +177,7 @@ app.put('/test-transport', function(req)
...
@@ -177,7 +177,7 @@ app.put('/test-transport', function(req)
});
});
});
});
set
Interval
(()
=>
set
Timeout
(()
=>
{
{
room
.
dump
()
room
.
dump
()
.
then
((
data
)
=>
debug
(
'ROOM DUMP:
\
n%s'
,
JSON
.
stringify
(
data
,
null
,
'
\
t'
)))
.
then
((
data
)
=>
debug
(
'ROOM DUMP:
\
n%s'
,
JSON
.
stringify
(
data
,
null
,
'
\
t'
)))
...
...
worker/include/RTC/DTLS
Agen
t.h
→
worker/include/RTC/DTLS
Transpor
t.h
浏览文件 @
d318e260
#ifndef MS_RTC_DTLS_
AGEN
T_H
#ifndef MS_RTC_DTLS_
TRANSPOR
T_H
#define MS_RTC_DTLS_
AGEN
T_H
#define MS_RTC_DTLS_
TRANSPOR
T_H
#include "common.h"
#include "common.h"
#include "RTC/SRTPSession.h"
#include "RTC/SRTPSession.h"
#include "handles/Timer.h"
#include "handles/Timer.h"
#include <string>
#include <string>
#include <map>
#include <vector>
#include <vector>
#include <openssl/ssl.h>
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/bio.h>
...
@@ -13,19 +14,20 @@
...
@@ -13,19 +14,20 @@
namespace
RTC
namespace
RTC
{
{
class
DTLS
Agen
t
:
class
DTLS
Transpor
t
:
public
Timer
::
Listener
public
Timer
::
Listener
{
{
public
:
public
:
enum
class
DTLS
Role
enum
class
Role
{
{
NONE
=
0
,
NONE
=
0
,
SERVER
=
1
,
AUTO
=
1
,
CLIENT
CLIENT
,
SERVER
};
};
public
:
public
:
enum
class
Fingerprint
Hash
enum
class
Fingerprint
Algorithm
{
{
NONE
=
0
,
NONE
=
0
,
SHA1
=
1
,
SHA1
=
1
,
...
@@ -35,6 +37,13 @@ namespace RTC
...
@@ -35,6 +37,13 @@ namespace RTC
SHA512
SHA512
};
};
public
:
struct
Fingerprint
{
FingerprintAlgorithm
algorithm
;
std
::
string
value
;
};
private
:
private
:
struct
SrtpProfileMapEntry
struct
SrtpProfileMapEntry
{
{
...
@@ -48,20 +57,22 @@ namespace RTC
...
@@ -48,20 +57,22 @@ namespace RTC
public
:
public
:
// NOTE: The caller MUST NOT call Reset() or Close() during the
// NOTE: The caller MUST NOT call Reset() or Close() during the
// onOutgoingDTLSData() callback.
// onOutgoingDTLSData() callback.
virtual
void
onOutgoingDTLSData
(
DTLS
Agent
*
dtlsAgen
t
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onOutgoingDTLSData
(
DTLS
Transport
*
dtlsTranspor
t
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// onDTLSDisconnected or onDTLSFailed callbacks.
// onDTLSDisconnected or onDTLSFailed callbacks.
virtual
void
onDTLSConnected
(
DTLS
Agent
*
dtlsAgen
t
)
=
0
;
virtual
void
onDTLSConnected
(
DTLS
Transport
*
dtlsTranspor
t
)
=
0
;
virtual
void
onDTLSDisconnected
(
DTLS
Agent
*
dtlsAgen
t
)
=
0
;
virtual
void
onDTLSDisconnected
(
DTLS
Transport
*
dtlsTranspor
t
)
=
0
;
virtual
void
onDTLSFailed
(
DTLS
Agent
*
dtlsAgen
t
)
=
0
;
virtual
void
onDTLSFailed
(
DTLS
Transport
*
dtlsTranspor
t
)
=
0
;
virtual
void
onSRTPKeyMaterial
(
DTLS
Agent
*
dtlsAgen
t
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onSRTPKeyMaterial
(
DTLS
Transport
*
dtlsTranspor
t
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLS
Agent
*
dtlsAgen
t
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLS
Transport
*
dtlsTranspor
t
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
};
public
:
public
:
static
void
ClassInit
();
static
void
ClassInit
();
static
void
ClassDestroy
();
static
void
ClassDestroy
();
static
Json
::
Value
&
GetLocalFingerprints
();
static
Json
::
Value
&
GetLocalFingerprints
();
static
Role
GetRole
(
std
::
string
role
);
static
FingerprintAlgorithm
GetFingerprintAlgorithm
(
std
::
string
fingerprint
);
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
private
:
private
:
...
@@ -74,21 +85,22 @@ namespace RTC
...
@@ -74,21 +85,22 @@ namespace RTC
static
X509
*
certificate
;
static
X509
*
certificate
;
static
EVP_PKEY
*
privateKey
;
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
static
SSL_CTX
*
sslCtx
;
static
Json
::
Value
localFingerprints
;
typedef
std
::
vector
<
SrtpProfileMapEntry
>
SRTPProfiles
;
static
SRTPProfiles
srtpProfiles
;
static
MS_BYTE
sslReadBuffer
[];
static
MS_BYTE
sslReadBuffer
[];
static
std
::
map
<
std
::
string
,
Role
>
string2Role
;
static
std
::
map
<
std
::
string
,
FingerprintAlgorithm
>
string2FingerprintAlgorithm
;
static
Json
::
Value
localFingerprints
;
static
std
::
vector
<
SrtpProfileMapEntry
>
srtpProfiles
;
public
:
public
:
DTLS
Agen
t
(
Listener
*
listener
);
DTLS
Transpor
t
(
Listener
*
listener
);
virtual
~
DTLS
Agen
t
();
virtual
~
DTLS
Transpor
t
();
void
Run
(
DTLS
Role
role
);
void
Start
(
Role
role
);
void
SetRemoteFingerprint
(
Fingerprint
Hash
hash
,
std
::
string
&
fingerprint
);
void
SetRemoteFingerprint
(
Fingerprint
fingerprint
);
void
Reset
();
void
Reset
();
void
Close
();
void
Close
();
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
Is
Running
();
bool
Is
Started
();
bool
IsConnected
();
bool
IsConnected
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Dump
();
void
Dump
();
...
@@ -119,15 +131,13 @@ namespace RTC
...
@@ -119,15 +131,13 @@ namespace RTC
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
Timer
*
timer
=
nullptr
;
Timer
*
timer
=
nullptr
;
// Others.
// Others.
// TODO: rename to localRole
Role
localRole
=
Role
::
NONE
;
DTLSRole
role
=
DTLSRole
::
NONE
;
Fingerprint
remoteFingerprint
=
{
FingerprintAlgorithm
::
NONE
,
""
};
FingerprintHash
remoteFingerprintHash
=
FingerprintHash
::
NONE
;
bool
started
=
false
;
std
::
string
remoteFingerprint
;
bool
handshakeDone
=
false
;
bool
isRunning
=
false
;
bool
handshakeDoneNow
=
false
;
bool
isHandshakeDone
=
false
;
bool
connected
=
false
;
bool
isHandshakeDoneNow
=
false
;
bool
checkingStatus
=
false
;
bool
isConnected
=
false
;
bool
isCheckingStatus
=
false
;
bool
doReset
=
false
;
bool
doReset
=
false
;
bool
doClose
=
false
;
bool
doClose
=
false
;
};
};
...
@@ -135,7 +145,35 @@ namespace RTC
...
@@ -135,7 +145,35 @@ namespace RTC
/* Inline static methods. */
/* Inline static methods. */
inline
inline
bool
DTLSAgent
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
Json
::
Value
&
DTLSTransport
::
GetLocalFingerprints
()
{
return
DTLSTransport
::
localFingerprints
;
}
inline
DTLSTransport
::
Role
DTLSTransport
::
GetRole
(
std
::
string
role
)
{
auto
it
=
DTLSTransport
::
string2Role
.
find
(
role
);
if
(
it
!=
DTLSTransport
::
string2Role
.
end
())
return
it
->
second
;
else
return
DTLSTransport
::
Role
::
NONE
;
}
inline
DTLSTransport
::
FingerprintAlgorithm
DTLSTransport
::
GetFingerprintAlgorithm
(
std
::
string
fingerprint
)
{
auto
it
=
DTLSTransport
::
string2FingerprintAlgorithm
.
find
(
fingerprint
);
if
(
it
!=
DTLSTransport
::
string2FingerprintAlgorithm
.
end
())
return
it
->
second
;
else
return
DTLSTransport
::
FingerprintAlgorithm
::
NONE
;
}
inline
bool
DTLSTransport
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
{
{
return
(
return
(
// Minimum DTLS record length is 13 bytes.
// Minimum DTLS record length is 13 bytes.
...
@@ -148,15 +186,15 @@ namespace RTC
...
@@ -148,15 +186,15 @@ namespace RTC
/* Inline instance methods. */
/* Inline instance methods. */
inline
inline
bool
DTLS
Agen
t
::
IsConnected
()
bool
DTLS
Transpor
t
::
IsConnected
()
{
{
return
this
->
isC
onnected
;
return
this
->
c
onnected
;
}
}
inline
inline
bool
DTLS
Agent
::
IsRunning
()
bool
DTLS
Transport
::
IsStarted
()
{
{
return
this
->
isRunning
;
return
this
->
started
;
}
}
}
}
...
...
worker/include/RTC/Transport.h
浏览文件 @
d318e260
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include "common.h"
#include "common.h"
#include "RTC/IceCandidate.h"
#include "RTC/IceCandidate.h"
#include "RTC/IceServer.h"
#include "RTC/IceServer.h"
#include "RTC/DTLS
Agen
t.h"
#include "RTC/DTLS
Transpor
t.h"
#include "RTC/STUNMessage.h"
#include "RTC/STUNMessage.h"
#include "RTC/TransportSource.h"
#include "RTC/TransportSource.h"
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
...
@@ -18,10 +18,11 @@
...
@@ -18,10 +18,11 @@
namespace
RTC
namespace
RTC
{
{
class
Transport
:
class
Transport
:
public
RTC
::
IceServer
::
Listener
,
public
RTC
::
UDPSocket
::
Listener
,
public
RTC
::
UDPSocket
::
Listener
,
public
RTC
::
TCPServer
::
Listener
,
public
RTC
::
TCPServer
::
Listener
,
public
RTC
::
TCPConnection
::
Reader
public
RTC
::
TCPConnection
::
Reader
,
public
RTC
::
IceServer
::
Listener
,
public
RTC
::
DTLSTransport
::
Listener
{
{
public
:
public
:
class
Listener
class
Listener
...
@@ -52,14 +53,10 @@ namespace RTC
...
@@ -52,14 +53,10 @@ namespace RTC
Transport
*
CreateAssociatedTransport
(
unsigned
int
transportId
);
Transport
*
CreateAssociatedTransport
(
unsigned
int
transportId
);
private
:
private
:
bool
SetSendingSource
(
RTC
::
TransportSource
*
source
);
int
SetSendingSource
(
RTC
::
TransportSource
*
source
);
bool
IsValidSource
(
RTC
::
TransportSource
*
source
);
int
IsValidSource
(
RTC
::
TransportSource
*
source
);
bool
RemoveSource
(
RTC
::
TransportSource
*
source
);
bool
RemoveSource
(
RTC
::
TransportSource
*
source
);
void
RunDTLSTransportIfReady
();
/* Pure virtual methods inherited from RTC::IceServer::Listener. */
public
:
virtual
void
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
override
;
virtual
void
onICEValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
override
;
/* Private methods to unify UDP and TCP behavior. */
/* Private methods to unify UDP and TCP behavior. */
private
:
private
:
...
@@ -86,6 +83,20 @@ namespace RTC
...
@@ -86,6 +83,20 @@ namespace RTC
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
/* Pure virtual methods inherited from RTC::IceServer::Listener. */
public
:
virtual
void
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
override
;
virtual
void
onICEValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
override
;
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public
:
virtual
void
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onDTLSConnected
(
RTC
::
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSDisconnected
(
RTC
::
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSFailed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onSRTPKeyMaterial
(
RTC
::
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
override
;
virtual
void
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
public
:
public
:
// Passed by argument.
// Passed by argument.
unsigned
int
transportId
;
unsigned
int
transportId
;
...
@@ -103,13 +114,18 @@ namespace RTC
...
@@ -103,13 +114,18 @@ namespace RTC
RTC
::
IceServer
*
iceServer
=
nullptr
;
RTC
::
IceServer
*
iceServer
=
nullptr
;
std
::
vector
<
RTC
::
UDPSocket
*>
udpSockets
;
std
::
vector
<
RTC
::
UDPSocket
*>
udpSockets
;
std
::
vector
<
RTC
::
TCPServer
*>
tcpServers
;
std
::
vector
<
RTC
::
TCPServer
*>
tcpServers
;
RTC
::
DTLSTransport
*
dtlsTransport
=
nullptr
;
// Others.
// Others.
bool
allocated
=
false
;
bool
allocated
=
false
;
// Others (ICE).
std
::
vector
<
IceCandidate
>
iceLocalCandidates
;
std
::
vector
<
IceCandidate
>
iceLocalCandidates
;
std
::
list
<
RTC
::
TransportSource
>
sources
;
std
::
list
<
RTC
::
TransportSource
>
sources
;
RTC
::
TransportSource
*
sendingSource
=
nullptr
;
RTC
::
TransportSource
*
sendingSource
=
nullptr
;
bool
icePaired
=
false
;
bool
icePaired
=
false
;
bool
icePairedWithUseCandidate
=
false
;
bool
icePairedWithUseCandidate
=
false
;
// Others (DTLS).
bool
started
=
false
;
RTC
::
DTLSTransport
::
Role
dtlsLocalRole
=
RTC
::
DTLSTransport
::
Role
::
CLIENT
;
};
};
/* Inline methods. */
/* Inline methods. */
...
@@ -133,14 +149,23 @@ namespace RTC
...
@@ -133,14 +149,23 @@ namespace RTC
* @param source: A RTC::TransportSource (which is a UDP tuple or TCP connection).
* @param source: A RTC::TransportSource (which is a UDP tuple or TCP connection).
* @return: true if the given source was not an already valid source,
* @return: true if the given source was not an already valid source,
* false otherwise.
* false otherwise.
* @return: 1 if it's the current sending source, 2 if it's another
* valid source, 0 if it's not a valid source.
*/
*/
inline
inline
bool
Transport
::
SetSendingSource
(
RTC
::
TransportSource
*
source
)
int
Transport
::
SetSendingSource
(
RTC
::
TransportSource
*
source
)
{
{
//
If the give source is already a valid one return
.
//
Check whether this is already a valid source
.
// NOTE: The IsValidSource() method will also mark it as sending source.
// NOTE: The IsValidSource() method will also mark it as sending source.
if
(
IsValidSource
(
source
))
switch
(
IsValidSource
(
source
))
return
false
;
{
// This is already the sending source.
case
1
:
return
1
;
// This is another valid source.
case
2
:
return
2
;
}
// If there are Transport::maxSources sources then close and remove the last one.
// If there are Transport::maxSources sources then close and remove the last one.
if
(
this
->
sources
.
size
()
==
Transport
::
maxSources
)
if
(
this
->
sources
.
size
()
==
Transport
::
maxSources
)
...
@@ -162,7 +187,7 @@ namespace RTC
...
@@ -162,7 +187,7 @@ namespace RTC
if
(
this
->
sendingSource
->
IsUDP
())
if
(
this
->
sendingSource
->
IsUDP
())
this
->
sendingSource
->
StoreUdpRemoteAddress
();
this
->
sendingSource
->
StoreUdpRemoteAddress
();
return
true
;
return
0
;
}
}
/**
/**
...
@@ -171,34 +196,36 @@ namespace RTC
...
@@ -171,34 +196,36 @@ namespace RTC
* source for the outgoing data.
* source for the outgoing data.
*
*
* @param source: The RTC::TransportSource to check.
* @param source: The RTC::TransportSource to check.
* @return: true if it is a valid source, false otherwise.
* @return: 1 if it's the current sending source, 2 if it's another
* valid source, 0 if it's not a valid source.
*/
*/
inline
inline
bool
Transport
::
IsValidSource
(
RTC
::
TransportSource
*
source
)
int
Transport
::
IsValidSource
(
RTC
::
TransportSource
*
source
)
{
{
// If there is no sending source yet then we know that the sources list
// If there is no sending source yet then we know that the sources list
// is empty, so return
false
.
// is empty, so return
0
.
if
(
!
this
->
sendingSource
)
if
(
!
this
->
sendingSource
)
return
false
;
return
0
;
// First check the current sending source. If it matches then return
true
.
// First check the current sending source. If it matches then return
1
.
if
(
this
->
sendingSource
->
Compare
(
source
))
if
(
this
->
sendingSource
->
Compare
(
source
))
return
true
;
return
1
;
// Otherwise check other valid source in the sources list.
// Otherwise check other valid source in the sources list.
for
(
auto
it
=
this
->
sources
.
begin
();
it
!=
this
->
sources
.
end
();
++
it
)
for
(
auto
it
=
this
->
sources
.
begin
();
it
!=
this
->
sources
.
end
();
++
it
)
{
{
RTC
::
TransportSource
*
valid_source
=
&
(
*
it
);
RTC
::
TransportSource
*
valid_source
=
&
(
*
it
);
// If found set it as sending source.
// If found set it as sending source
and return 2
.
if
(
valid_source
->
Compare
(
source
))
if
(
valid_source
->
Compare
(
source
))
{
{
this
->
sendingSource
=
valid_source
;
this
->
sendingSource
=
valid_source
;
return
true
;
return
2
;
}
}
}
}
return
false
;
// Otherwise it is not a valid source so return 0.
return
0
;
}
}
/**
/**
...
@@ -236,6 +263,8 @@ namespace RTC
...
@@ -236,6 +263,8 @@ namespace RTC
// This is just useful is there are just TCP sources.
// This is just useful is there are just TCP sources.
this
->
icePaired
=
false
;
this
->
icePaired
=
false
;
this
->
icePairedWithUseCandidate
=
false
;
this
->
icePairedWithUseCandidate
=
false
;
// TODO: This should fire a 'icefailed' event.
}
}
}
}
...
...
worker/include/handles/TCPConnection.h
浏览文件 @
d318e260
...
@@ -16,12 +16,12 @@ public:
...
@@ -16,12 +16,12 @@ public:
public
:
public
:
/* Struct for the data field of uv_req_t when writing into the connection. */
/* Struct for the data field of uv_req_t when writing into the connection. */
typedef
struct
UvWriteData
struct
UvWriteData
{
{
TCPConnection
*
connection
;
TCPConnection
*
connection
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
}
UvWriteData
;
};
public
:
public
:
TCPConnection
(
size_t
bufferSize
);
TCPConnection
(
size_t
bufferSize
);
...
...
worker/include/handles/UDPSocket.h
浏览文件 @
d318e260
...
@@ -9,12 +9,12 @@ class UDPSocket
...
@@ -9,12 +9,12 @@ class UDPSocket
{
{
public
:
public
:
/* Struct for the data field of uv_req_t when sending a datagram. */
/* Struct for the data field of uv_req_t when sending a datagram. */
typedef
struct
UvSendData
struct
UvSendData
{
{
UDPSocket
*
socket
;
UDPSocket
*
socket
;
uv_udp_send_t
req
;
uv_udp_send_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
}
UvSendData
;
};
private
:
private
:
static
MS_BYTE
readBuffer
[];
static
MS_BYTE
readBuffer
[];
...
...
worker/include/handles/UnixStreamSocket.h
浏览文件 @
d318e260
...
@@ -9,12 +9,12 @@ class UnixStreamSocket
...
@@ -9,12 +9,12 @@ class UnixStreamSocket
{
{
public
:
public
:
/* Struct for the data field of uv_req_t when writing data. */
/* Struct for the data field of uv_req_t when writing data. */
typedef
struct
UvWriteData
struct
UvWriteData
{
{
UnixStreamSocket
*
socket
;
UnixStreamSocket
*
socket
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
}
UvWriteData
;
};
public
:
public
:
UnixStreamSocket
(
int
fd
,
size_t
bufferSize
);
UnixStreamSocket
(
int
fd
,
size_t
bufferSize
);
...
...
worker/src/RTC/DTLS
Agen
t.cpp
→
worker/src/RTC/DTLS
Transpor
t.cpp
浏览文件 @
d318e260
差异被折叠。
点击展开。
worker/src/RTC/TCPConnection.cpp
浏览文件 @
d318e260
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "RTC/TCPConnection.h"
#include "RTC/TCPConnection.h"
#include "RTC/STUNMessage.h"
#include "RTC/STUNMessage.h"
#include "RTC/DTLS
Agen
t.h"
#include "RTC/DTLS
Transpor
t.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include "Utils.h"
#include "Utils.h"
...
@@ -84,7 +84,7 @@ namespace RTC
...
@@ -84,7 +84,7 @@ namespace RTC
this
->
reader
->
onRTPDataRecv
(
this
,
packet
,
packet_len
);
this
->
reader
->
onRTPDataRecv
(
this
,
packet
,
packet_len
);
}
}
// Check if it's DTLS.
// Check if it's DTLS.
else
if
(
DTLS
Agen
t
::
IsDTLS
(
packet
,
packet_len
))
else
if
(
DTLS
Transpor
t
::
IsDTLS
(
packet
,
packet_len
))
{
{
this
->
reader
->
onDTLSDataRecv
(
this
,
packet
,
packet_len
);
this
->
reader
->
onDTLSDataRecv
(
this
,
packet
,
packet_len
);
}
}
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
d318e260
...
@@ -51,6 +51,7 @@ namespace RTC
...
@@ -51,6 +51,7 @@ namespace RTC
{
{
this
->
iceComponent
=
IceComponent
::
RTP
;
this
->
iceComponent
=
IceComponent
::
RTP
;
// Create a ICE server.
this
->
iceServer
=
new
RTC
::
IceServer
(
this
,
this
->
iceServer
=
new
RTC
::
IceServer
(
this
,
Utils
::
Crypto
::
GetRandomString
(
16
),
Utils
::
Crypto
::
GetRandomString
(
16
),
Utils
::
Crypto
::
GetRandomString
(
32
));
Utils
::
Crypto
::
GetRandomString
(
32
));
...
@@ -66,6 +67,7 @@ namespace RTC
...
@@ -66,6 +67,7 @@ namespace RTC
{
{
this
->
iceComponent
=
IceComponent
::
RTCP
;
this
->
iceComponent
=
IceComponent
::
RTCP
;
// Create a ICE server.
this
->
iceServer
=
new
RTC
::
IceServer
(
this
,
this
->
iceServer
=
new
RTC
::
IceServer
(
this
,
rtpTransport
->
GetIceUsernameFragment
(),
rtpTransport
->
GetIceUsernameFragment
(),
rtpTransport
->
GetIcePassword
());
rtpTransport
->
GetIcePassword
());
...
@@ -184,6 +186,9 @@ namespace RTC
...
@@ -184,6 +186,9 @@ namespace RTC
MS_THROW_ERROR
(
"could not open any IP:port"
);
MS_THROW_ERROR
(
"could not open any IP:port"
);
}
}
// Create a DTLS agent.
this
->
dtlsTransport
=
new
RTC
::
DTLSTransport
(
this
);
// Hack to avoid that Close() above attempts to delete this.
// Hack to avoid that Close() above attempts to delete this.
this
->
allocated
=
true
;
this
->
allocated
=
true
;
}
}
...
@@ -200,8 +205,8 @@ namespace RTC
...
@@ -200,8 +205,8 @@ namespace RTC
if
(
this
->
iceServer
)
if
(
this
->
iceServer
)
this
->
iceServer
->
Close
();
this
->
iceServer
->
Close
();
// if (this->dtlsAgen
t)
if
(
this
->
dtlsTranspor
t
)
// this->dtlsAgen
t->Close();
this
->
dtlsTranspor
t
->
Close
();
// if (this->srtpRecvSession)
// if (this->srtpRecvSession)
// this->srtpRecvSession->Close();
// this->srtpRecvSession->Close();
...
@@ -257,7 +262,7 @@ namespace RTC
...
@@ -257,7 +262,7 @@ namespace RTC
}
}
// Add `dtlsLocalFingerprints`.
// Add `dtlsLocalFingerprints`.
data
[
k_dtlsLocalFingerprints
]
=
RTC
::
DTLS
Agen
t
::
GetLocalFingerprints
();
data
[
k_dtlsLocalFingerprints
]
=
RTC
::
DTLS
Transpor
t
::
GetLocalFingerprints
();
return
data
;
return
data
;
}
}
...
@@ -291,7 +296,72 @@ namespace RTC
...
@@ -291,7 +296,72 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
transport_start
:
case
Channel
:
:
Request
::
MethodId
::
transport_start
:
{
{
// TODO
static
const
Json
::
StaticString
k_role
(
"role"
);
static
const
Json
::
StaticString
v_auto
(
"auto"
);
static
const
Json
::
StaticString
v_client
(
"client"
);
static
const
Json
::
StaticString
v_server
(
"server"
);
static
const
Json
::
StaticString
k_fingerprint
(
"fingerprint"
);
static
const
Json
::
StaticString
k_algorithm
(
"algorithm"
);
static
const
Json
::
StaticString
k_value
(
"value"
);
RTC
::
DTLSTransport
::
FingerprintAlgorithm
fingerprint_algorithm
;
std
::
string
fingerprint_value
;
RTC
::
DTLSTransport
::
Role
role
=
RTC
::
DTLSTransport
::
Role
::
AUTO
;
// Default value.
// Ensure this method is not called twice.
if
(
this
->
started
)
{
MS_ERROR
(
"method already called"
);
request
->
Reject
(
500
,
"method already called"
);
return
;
}
this
->
started
=
true
;
// Validate request data.
if
(
!
request
->
data
[
k_fingerprint
].
isObject
())
{
MS_ERROR
(
"missing .fingerprint"
);
request
->
Reject
(
500
,
"missing .fingerprint"
);
return
;
}
if
(
!
request
->
data
[
k_fingerprint
][
k_algorithm
].
isString
()
||
!
request
->
data
[
k_fingerprint
][
k_value
].
isString
())
{
MS_ERROR
(
"missing .fingerprint.algorithm and/or .fingerprint.value"
);
request
->
Reject
(
500
,
"missing .fingerprint.algorithm and/or .fingerprint.value"
);
return
;
}
fingerprint_algorithm
=
RTC
::
DTLSTransport
::
GetFingerprintAlgorithm
(
request
->
data
[
k_fingerprint
][
k_algorithm
].
asString
());
if
(
fingerprint_algorithm
==
RTC
::
DTLSTransport
::
FingerprintAlgorithm
::
NONE
)
{
MS_ERROR
(
"unsupported .fingerprint.algorithm"
);
request
->
Reject
(
500
,
"unsupported .fingerprint.algorithm"
);
return
;
}
fingerprint_value
=
request
->
data
[
k_fingerprint
][
k_value
].
asString
();
if
(
request
->
data
[
k_role
].
isString
())
{
role
=
RTC
::
DTLSTransport
::
GetRole
(
request
->
data
[
k_role
].
asString
());
if
(
role
==
RTC
::
DTLSTransport
::
Role
::
NONE
)
{
MS_ERROR
(
"invalid .role"
);
request
->
Reject
(
500
,
"invalid .role"
);
return
;
}
}
break
;
break
;
}
}
...
@@ -315,32 +385,12 @@ namespace RTC
...
@@ -315,32 +385,12 @@ namespace RTC
return
new
RTC
::
Transport
(
this
->
listener
,
transportId
,
nullData
,
this
);
return
new
RTC
::
Transport
(
this
->
listener
,
transportId
,
nullData
,
this
);
}
}
void
Transport
::
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
inline
{
void
Transport
::
RunDTLSTransportIfReady
()
MS_TRACE
();
// Send the STUN response over the same transport source.
source
->
Send
(
msg
->
GetRaw
(),
msg
->
GetLength
());
}
void
Transport
::
onICEValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
{
{
MS_TRACE
();
MS_TRACE
();
this
->
icePaired
=
true
;
// TODO
if
(
has_use_candidate
)
this
->
icePairedWithUseCandidate
=
true
;
/*
* RFC 5245 section 11.2 "Receiving Media":
*
* ICE implementations MUST be prepared to receive media on each component
* on any candidates provided for that component.
*/
if
(
SetSendingSource
(
source
))
MS_DEBUG
(
"got an ICE valid pair [UseCandidate:%s]"
,
has_use_candidate
?
"true"
:
"false"
);
// TODO: more
}
}
inline
inline
...
@@ -431,13 +481,12 @@ namespace RTC
...
@@ -431,13 +481,12 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
//
RTC::TransportSource source(connection);
RTC
::
TransportSource
source
(
connection
);
// if (RemoveSource(&source))
if
(
RemoveSource
(
&
source
))
// {
{
// MS_DEBUG("valid source %s:", is_closed_by_peer ? "closed by peer" : "locally closed");
MS_DEBUG
(
"valid source %s:"
,
is_closed_by_peer
?
"closed by peer"
:
"locally closed"
);
// source.Dump();
}
// }
}
}
void
Transport
::
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
...
@@ -471,4 +520,113 @@ namespace RTC
...
@@ -471,4 +520,113 @@ namespace RTC
RTC
::
TransportSource
source
(
connection
);
RTC
::
TransportSource
source
(
connection
);
onRTCPDataRecv
(
&
source
,
data
,
len
);
onRTCPDataRecv
(
&
source
,
data
,
len
);
}
}
void
Transport
::
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
{
MS_TRACE
();
// Send the STUN response over the same transport source.
source
->
Send
(
msg
->
GetRaw
(),
msg
->
GetLength
());
}
void
Transport
::
onICEValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
{
MS_TRACE
();
/*
* RFC 5245 section 11.2 "Receiving Media":
*
* ICE implementations MUST be prepared to receive media on each component
* on any candidates provided for that component.
*/
this
->
icePaired
=
true
;
if
(
has_use_candidate
)
this
->
icePairedWithUseCandidate
=
true
;
switch
(
SetSendingSource
(
source
))
{
// This is a new source.
case
0
:
MS_DEBUG
(
"got a new ICE valid pair [UseCandidate:%s]"
,
has_use_candidate
?
"true"
:
"false"
);
break
;
// This is already the sending source.
case
1
:
break
;
// This is another valid source.
case
2
:
MS_DEBUG
(
"got a previous ICE valid pair [UseCandidate:%s]"
,
has_use_candidate
?
"true"
:
"false"
);
break
;
}
// If ready, run the DTLS handler.
RunDTLSTransportIfReady
();
}
void
Transport
::
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
{
MS_TRACE
();
if
(
!
this
->
sendingSource
)
{
MS_DEBUG
(
"no sending address set, cannot send DTLS packet"
);
return
;
}
// TODO: remove
MS_DEBUG
(
"sending DTLS data to to:"
);
this
->
sendingSource
->
Dump
();
this
->
sendingSource
->
Send
(
data
,
len
);
}
void
Transport
::
onDTLSConnected
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
MS_TRACE
();
MS_DEBUG
(
"DTLS connected"
);
}
void
Transport
::
onDTLSDisconnected
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
MS_TRACE
();
MS_DEBUG
(
"DTLS disconnected"
);
// TODO
// Reset();
}
void
Transport
::
onDTLSFailed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
MS_TRACE
();
MS_DEBUG
(
"DTLS failed"
);
// TODO
// Reset();
}
void
Transport
::
onSRTPKeyMaterial
(
RTC
::
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
{
MS_TRACE
();
MS_DEBUG
(
"got SRTP key material"
);
// TODO
// SetLocalSRTPKey(srtp_profile, srtp_local_key, srtp_local_key_len);
// SetRemoteSRTPKey(srtp_profile, srtp_remote_key, srtp_remote_key_len);
}
void
Transport
::
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
{
MS_TRACE
();
MS_DEBUG
(
"DTLS application data received [size:%zu]"
,
len
);
// TMP
MS_DEBUG
(
"data: %s"
,
std
::
string
((
char
*
)
data
,
len
).
c_str
());
}
}
}
worker/src/RTC/UDPSocket.cpp
浏览文件 @
d318e260
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/STUNMessage.h"
#include "RTC/STUNMessage.h"
#include "RTC/DTLS
Agen
t.h"
#include "RTC/DTLS
Transpor
t.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include "Settings.h"
#include "Settings.h"
...
@@ -368,7 +368,7 @@ namespace RTC
...
@@ -368,7 +368,7 @@ namespace RTC
}
}
// Check if it's DTLS.
// Check if it's DTLS.
if
(
DTLS
Agen
t
::
IsDTLS
(
data
,
len
))
if
(
DTLS
Transpor
t
::
IsDTLS
(
data
,
len
))
{
{
this
->
listener
->
onDTLSDataRecv
(
this
,
data
,
len
,
addr
);
this
->
listener
->
onDTLSDataRecv
(
this
,
data
,
len
,
addr
);
return
;
return
;
...
...
worker/src/handles/TCPConnection.cpp
浏览文件 @
d318e260
...
@@ -326,7 +326,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
...
@@ -326,7 +326,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
if
(
this
->
bufferSize
>
this
->
bufferDataLen
)
if
(
this
->
bufferSize
>
this
->
bufferDataLen
)
{
{
buf
->
len
=
this
->
bufferSize
-
this
->
bufferDataLen
;
buf
->
len
=
this
->
bufferSize
-
this
->
bufferDataLen
;
MS_DEBUG
(
"available space in the buffer: %zu"
,
buf
->
len
);
//
MS_DEBUG("available space in the buffer: %zu", buf->len);
}
}
else
else
{
{
...
...
worker/src/main.cpp
浏览文件 @
d318e260
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include "Channel/UnixStreamSocket.h"
#include "Channel/UnixStreamSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPServer.h"
#include "RTC/TCPServer.h"
#include "RTC/DTLS
Agen
t.h"
#include "RTC/DTLS
Transpor
t.h"
#include "RTC/SRTPSession.h"
#include "RTC/SRTPSession.h"
#include "Loop.h"
#include "Loop.h"
#include "MediaSoupError.h"
#include "MediaSoupError.h"
...
@@ -113,7 +113,7 @@ void init()
...
@@ -113,7 +113,7 @@ void init()
DepUsrSCTP
::
ClassInit
();
DepUsrSCTP
::
ClassInit
();
RTC
::
UDPSocket
::
ClassInit
();
RTC
::
UDPSocket
::
ClassInit
();
RTC
::
TCPServer
::
ClassInit
();
RTC
::
TCPServer
::
ClassInit
();
RTC
::
DTLS
Agen
t
::
ClassInit
();
RTC
::
DTLS
Transpor
t
::
ClassInit
();
RTC
::
SRTPSession
::
ClassInit
();
RTC
::
SRTPSession
::
ClassInit
();
Utils
::
Crypto
::
ClassInit
();
Utils
::
Crypto
::
ClassInit
();
}
}
...
@@ -159,7 +159,7 @@ void destroy()
...
@@ -159,7 +159,7 @@ void destroy()
DepOpenSSL
::
ClassDestroy
();
DepOpenSSL
::
ClassDestroy
();
DepLibSRTP
::
ClassDestroy
();
DepLibSRTP
::
ClassDestroy
();
DepUsrSCTP
::
ClassDestroy
();
DepUsrSCTP
::
ClassDestroy
();
RTC
::
DTLS
Agen
t
::
ClassDestroy
();
RTC
::
DTLS
Transpor
t
::
ClassDestroy
();
Utils
::
Crypto
::
ClassDestroy
();
Utils
::
Crypto
::
ClassDestroy
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论