Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
9f73fee8
提交
9f73fee8
authored
1月 09, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
C++ cleanup and add ICE state "disconnected".
上级
4743f0e4
显示空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
205 行增加
和
141 行删除
+205
-141
Transport.js
lib/Transport.js
+7
-0
index.js
tester/lib/index.js
+5
-5
server.js
tester/server/server.js
+1
-1
Loop.h
worker/include/Loop.h
+2
-2
ICEServer.h
worker/include/RTC/ICEServer.h
+4
-1
IceCandidate.h
worker/include/RTC/IceCandidate.h
+3
-3
Peer.h
worker/include/RTC/Peer.h
+5
-4
Transport.h
worker/include/RTC/Transport.h
+4
-6
Utils.h
worker/include/Utils.h
+4
-22
common.h
worker/include/common.h
+1
-0
Loop.cpp
worker/src/Loop.cpp
+3
-3
DTLSTransport.cpp
worker/src/RTC/DTLSTransport.cpp
+4
-4
ICEServer.cpp
worker/src/RTC/ICEServer.cpp
+98
-42
IceCandidate.cpp
worker/src/RTC/IceCandidate.cpp
+3
-3
Peer.cpp
worker/src/RTC/Peer.cpp
+8
-8
Transport.cpp
worker/src/RTC/Transport.cpp
+48
-32
Crypto.cpp
worker/src/Utils/Crypto.cpp
+5
-5
没有找到文件。
lib/Transport.js
浏览文件 @
9f73fee8
...
@@ -77,6 +77,11 @@ class Transport extends EventEmitter
...
@@ -77,6 +77,11 @@ class Transport extends EventEmitter
case
'icestatechange'
:
case
'icestatechange'
:
{
{
this
.
_data
.
iceState
=
data
.
iceState
;
this
.
_data
.
iceState
=
data
.
iceState
;
// Unset .iceSelectedTuple if required
if
(
data
.
iceState
===
'disconnected'
)
{
delete
this
.
_data
.
iceSelectedTuple
;
}
// Emit it to the app
// Emit it to the app
this
.
emit
(
event
,
data
);
this
.
emit
(
event
,
data
);
break
;
break
;
...
@@ -157,6 +162,8 @@ class Transport extends EventEmitter
...
@@ -157,6 +162,8 @@ class Transport extends EventEmitter
// We won't receive events anymore, so be nice and manually update
// We won't receive events anymore, so be nice and manually update
// some fields and emit events before firing 'close'
// some fields and emit events before firing 'close'
delete
this
.
_data
.
iceSelectedTuple
;
if
(
this
.
_data
.
iceState
!==
'closed'
)
if
(
this
.
_data
.
iceState
!==
'closed'
)
{
{
this
.
_data
.
iceState
=
'closed'
;
this
.
_data
.
iceState
=
'closed'
;
...
...
tester/lib/index.js
浏览文件 @
9f73fee8
...
@@ -7,7 +7,7 @@ debugerror.log = console.error.bind(console);
...
@@ -7,7 +7,7 @@ debugerror.log = console.error.bind(console);
const
domready
=
require
(
'domready'
);
const
domready
=
require
(
'domready'
);
const
rtcninja
=
require
(
'rtcninja'
);
const
rtcninja
=
require
(
'rtcninja'
);
//
const randomString = require('random-string');
const
randomString
=
require
(
'random-string'
);
const
Peer
=
require
(
'./Peer'
);
const
Peer
=
require
(
'./Peer'
);
let
protooWsUrl
;
let
protooWsUrl
;
...
@@ -33,10 +33,10 @@ function run()
...
@@ -33,10 +33,10 @@ function run()
{
{
debug
(
'run()'
);
debug
(
'run()'
);
//
let username = randomString();
let
username
=
randomString
();
//
let uuid = randomString();
let
uuid
=
randomString
();
let
username
=
'alice'
;
//
let username = 'alice';
let
uuid
=
'aaaa'
;
//
let uuid = 'aaaa';
let
peer
=
new
Peer
(
protooWsUrl
,
username
,
uuid
);
let
peer
=
new
Peer
(
protooWsUrl
,
username
,
uuid
);
...
...
tester/server/server.js
浏览文件 @
9f73fee8
...
@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
...
@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
{
{
let
promise
=
mediaPeer
.
createTransport
(
let
promise
=
mediaPeer
.
createTransport
(
{
{
udp
:
tru
e
,
udp
:
fals
e
,
tcp
:
true
,
tcp
:
true
,
preferIPv4
:
true
,
preferIPv4
:
true
,
preferUdp
:
true
preferUdp
:
true
...
...
worker/include/Loop.h
浏览文件 @
9f73fee8
...
@@ -20,7 +20,7 @@ public:
...
@@ -20,7 +20,7 @@ public:
private
:
private
:
void
Close
();
void
Close
();
RTC
::
Room
*
GetRoomFromRequest
(
Channel
::
Request
*
request
,
u
nsigned
in
t
*
roomId
=
nullptr
);
RTC
::
Room
*
GetRoomFromRequest
(
Channel
::
Request
*
request
,
u
int32_
t
*
roomId
=
nullptr
);
/* Methods inherited from SignalsHandler::Listener. */
/* Methods inherited from SignalsHandler::Listener. */
public
:
public
:
...
@@ -43,7 +43,7 @@ private:
...
@@ -43,7 +43,7 @@ private:
SignalsHandler
*
signalsHandler
=
nullptr
;
SignalsHandler
*
signalsHandler
=
nullptr
;
// Others.
// Others.
bool
closed
=
false
;
bool
closed
=
false
;
std
::
unordered_map
<
u
nsigned
in
t
,
RTC
::
Room
*>
rooms
;
std
::
unordered_map
<
u
int32_
t
,
RTC
::
Room
*>
rooms
;
};
};
#endif
#endif
worker/include/RTC/ICEServer.h
浏览文件 @
9f73fee8
...
@@ -23,7 +23,8 @@ namespace RTC
...
@@ -23,7 +23,8 @@ namespace RTC
{
{
NEW
=
1
,
NEW
=
1
,
CONNECTED
,
CONNECTED
,
COMPLETED
COMPLETED
,
DISCONNECTED
};
};
public
:
public
:
...
@@ -38,6 +39,7 @@ namespace RTC
...
@@ -38,6 +39,7 @@ namespace RTC
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICEDisconnected
(
ICEServer
*
iceServer
)
=
0
;
};
};
public
:
public
:
...
@@ -50,6 +52,7 @@ namespace RTC
...
@@ -50,6 +52,7 @@ namespace RTC
std
::
string
&
GetPassword
();
std
::
string
&
GetPassword
();
IceState
GetState
();
IceState
GetState
();
bool
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
);
bool
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
);
void
RemoveTuple
(
RTC
::
TransportTuple
*
tuple
);
// This should be just called in 'connected' or completed' state
// This should be just called in 'connected' or completed' state
// and the given tuple must be an already valid tuple.
// and the given tuple must be an already valid tuple.
void
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
);
void
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
);
...
...
worker/include/RTC/IceCandidate.h
浏览文件 @
9f73fee8
...
@@ -31,15 +31,15 @@ namespace RTC
...
@@ -31,15 +31,15 @@ namespace RTC
};
};
public
:
public
:
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
64
_t
priority
);
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
32
_t
priority
);
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
64
_t
priority
);
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
32
_t
priority
);
Json
::
Value
toJson
();
Json
::
Value
toJson
();
private
:
private
:
// Others.
// Others.
std
::
string
foundation
;
std
::
string
foundation
;
uint
64
_t
priority
;
uint
32
_t
priority
;
std
::
string
ip
;
std
::
string
ip
;
Protocol
protocol
;
Protocol
protocol
;
MS_PORT
port
;
MS_PORT
port
;
...
...
worker/include/RTC/Peer.h
浏览文件 @
9f73fee8
#ifndef MS_RTC_PEER_H
#ifndef MS_RTC_PEER_H
#define MS_RTC_PEER_H
#define MS_RTC_PEER_H
#include "common.h"
#include "RTC/Transport.h"
#include "RTC/Transport.h"
#include "Channel/Request.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include "Channel/Notifier.h"
...
@@ -21,7 +22,7 @@ namespace RTC
...
@@ -21,7 +22,7 @@ namespace RTC
};
};
public
:
public
:
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
nsigned
in
t
peerId
,
std
::
string
&
peerName
);
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
int32_
t
peerId
,
std
::
string
&
peerName
);
virtual
~
Peer
();
virtual
~
Peer
();
void
Close
();
void
Close
();
...
@@ -29,7 +30,7 @@ namespace RTC
...
@@ -29,7 +30,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
void
HandleRequest
(
Channel
::
Request
*
request
);
private
:
private
:
RTC
::
Transport
*
GetTransportFromRequest
(
Channel
::
Request
*
request
,
u
nsigned
in
t
*
iceTransportId
=
nullptr
);
RTC
::
Transport
*
GetTransportFromRequest
(
Channel
::
Request
*
request
,
u
int32_
t
*
iceTransportId
=
nullptr
);
/* Pure virtual methods inherited from RTC::Transport::Listener. */
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public
:
public
:
...
@@ -37,7 +38,7 @@ namespace RTC
...
@@ -37,7 +38,7 @@ namespace RTC
public
:
public
:
// Passed by argument.
// Passed by argument.
u
nsigned
in
t
peerId
;
u
int32_
t
peerId
;
std
::
string
peerName
;
std
::
string
peerName
;
private
:
private
:
...
@@ -45,7 +46,7 @@ namespace RTC
...
@@ -45,7 +46,7 @@ namespace RTC
Listener
*
listener
=
nullptr
;
Listener
*
listener
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
// Others.
// Others.
std
::
unordered_map
<
u
nsigned
in
t
,
RTC
::
Transport
*>
transports
;
std
::
unordered_map
<
u
int32_
t
,
RTC
::
Transport
*>
transports
;
};
};
}
}
...
...
worker/include/RTC/Transport.h
浏览文件 @
9f73fee8
...
@@ -31,11 +31,8 @@ namespace RTC
...
@@ -31,11 +31,8 @@ namespace RTC
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
};
};
private
:
static
size_t
maxTuples
;
public
:
public
:
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
nsigned
in
t
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
=
nullptr
);
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
int32_
t
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
=
nullptr
);
virtual
~
Transport
();
virtual
~
Transport
();
void
Close
();
void
Close
();
...
@@ -43,7 +40,7 @@ namespace RTC
...
@@ -43,7 +40,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
void
HandleRequest
(
Channel
::
Request
*
request
);
std
::
string
&
GetIceUsernameFragment
();
std
::
string
&
GetIceUsernameFragment
();
std
::
string
&
GetIcePassword
();
std
::
string
&
GetIcePassword
();
Transport
*
CreateAssociatedTransport
(
u
nsigned
in
t
transportId
);
Transport
*
CreateAssociatedTransport
(
u
int32_
t
transportId
);
private
:
private
:
void
ClosePorts
();
void
ClosePorts
();
...
@@ -81,6 +78,7 @@ namespace RTC
...
@@ -81,6 +78,7 @@ namespace RTC
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICEDisconnected
(
ICEServer
*
iceServer
)
override
;
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public
:
public
:
...
@@ -93,7 +91,7 @@ namespace RTC
...
@@ -93,7 +91,7 @@ namespace RTC
public
:
public
:
// Passed by argument.
// Passed by argument.
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
protected
:
protected
:
// Others.
// Others.
...
...
worker/include/Utils.h
浏览文件 @
9f73fee8
...
@@ -199,14 +199,13 @@ namespace Utils
...
@@ -199,14 +199,13 @@ namespace Utils
public
:
public
:
static
void
ClassInit
();
static
void
ClassInit
();
static
void
ClassDestroy
();
static
void
ClassDestroy
();
static
u
nsigned
int
GetRandomUInt
(
unsigned
int
min
,
unsigned
in
t
max
);
static
u
int32_t
GetRandomUInt
(
uint32_t
min
,
uint32_
t
max
);
static
const
std
::
string
GetRandomString
(
size_t
len
);
static
const
std
::
string
GetRandomString
(
size_t
len
);
// static const char* GetRandomHexString(char* str, size_t len);
static
MS_4BYTES
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
);
static
MS_4BYTES
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
);
static
const
MS_BYTE
*
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
MS_BYTE
*
data
,
size_t
len
);
static
const
MS_BYTE
*
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
MS_BYTE
*
data
,
size_t
len
);
private
:
private
:
static
u
nsigned
in
t
seed
;
static
u
int32_
t
seed
;
static
HMAC_CTX
hmacSha1Ctx
;
static
HMAC_CTX
hmacSha1Ctx
;
static
MS_BYTE
hmacSha1Buffer
[];
static
MS_BYTE
hmacSha1Buffer
[];
static
const
MS_4BYTES
crc32Table
[
256
];
static
const
MS_4BYTES
crc32Table
[
256
];
...
@@ -215,14 +214,14 @@ namespace Utils
...
@@ -215,14 +214,14 @@ namespace Utils
/* Inline static methods. */
/* Inline static methods. */
inline
inline
u
nsigned
int
Crypto
::
GetRandomUInt
(
unsigned
int
min
,
unsigned
in
t
max
)
u
int32_t
Crypto
::
GetRandomUInt
(
uint32_t
min
,
uint32_
t
max
)
{
{
// NOTE: This is the original, but produces very small values.
// NOTE: This is the original, but produces very small values.
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
// This seems to produce better results.
// This seems to produce better results.
Crypto
::
seed
=
(
u
nsigned
in
t
)((
214013
*
Crypto
::
seed
)
+
2531011
);
Crypto
::
seed
=
(
u
int32_
t
)((
214013
*
Crypto
::
seed
)
+
2531011
);
return
(((
Crypto
::
seed
>>
4
)
&
0x7FFF7FFF
)
%
(
max
-
min
+
1
))
+
min
;
return
(((
Crypto
::
seed
>>
4
)
&
0x7FFF7FFF
)
%
(
max
-
min
+
1
))
+
min
;
}
}
...
@@ -247,23 +246,6 @@ namespace Utils
...
@@ -247,23 +246,6 @@ namespace Utils
return
std
::
string
(
buffer
,
len
);
return
std
::
string
(
buffer
,
len
);
}
}
// inline
// const char* Crypto::GetRandomHexString(char* buffer, size_t len)
// {
// static const char hex_chars[] =
// {
// '0','1','2','3','4','5','6','7','8','9',
// 'A','B','C','D','E','F','G','H','I','J',
// 'K','L','M','N','O','P','Q','R','S','T',
// 'U','V','W','X','Y','Z'
// };
// for (size_t i = 0; i < len; ++i)
// buffer[i] = hex_chars[GetRandomUInt(0, sizeof(hex_chars) - 1)];
// return buffer;
// }
inline
inline
MS_4BYTES
Crypto
::
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
)
MS_4BYTES
Crypto
::
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
)
{
{
...
...
worker/include/common.h
浏览文件 @
9f73fee8
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <cstddef> // size_t
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <cstdint> // uint8_t, etc
#include <cinttypes> // PRIu64, etc
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
...
...
worker/src/Loop.cpp
浏览文件 @
9f73fee8
...
@@ -87,7 +87,7 @@ void Loop::Close()
...
@@ -87,7 +87,7 @@ void Loop::Close()
this
->
channel
->
Close
();
this
->
channel
->
Close
();
}
}
RTC
::
Room
*
Loop
::
GetRoomFromRequest
(
Channel
::
Request
*
request
,
u
nsigned
in
t
*
roomId
)
RTC
::
Room
*
Loop
::
GetRoomFromRequest
(
Channel
::
Request
*
request
,
u
int32_
t
*
roomId
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -177,7 +177,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -177,7 +177,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case
Channel
:
:
Request
::
MethodId
::
worker_createRoom
:
case
Channel
:
:
Request
::
MethodId
::
worker_createRoom
:
{
{
RTC
::
Room
*
room
;
RTC
::
Room
*
room
;
u
nsigned
in
t
roomId
;
u
int32_
t
roomId
;
try
try
{
{
...
@@ -209,7 +209,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
...
@@ -209,7 +209,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
this
->
rooms
[
roomId
]
=
room
;
this
->
rooms
[
roomId
]
=
room
;
MS_DEBUG
(
"Room created [roomId:%
u
]"
,
roomId
);
MS_DEBUG
(
"Room created [roomId:%
"
PRIu32
"
]"
,
roomId
);
request
->
Accept
();
request
->
Accept
();
break
;
break
;
...
...
worker/src/RTC/DTLSTransport.cpp
浏览文件 @
9f73fee8
...
@@ -206,8 +206,8 @@ namespace RTC
...
@@ -206,8 +206,8 @@ namespace RTC
LOG_OPENSSL_ERROR
(
"X509_get_subject_name() failed"
);
LOG_OPENSSL_ERROR
(
"X509_get_subject_name() failed"
);
goto
error
;
goto
error
;
}
}
X509_NAME_add_entry_by_txt
(
cert_name
,
"O"
,
MBSTRING_ASC
,
(
u
nsigned
char
*
)
MS_APP_NAME
,
-
1
,
-
1
,
0
);
X509_NAME_add_entry_by_txt
(
cert_name
,
"O"
,
MBSTRING_ASC
,
(
u
int8_t
*
)
MS_APP_NAME
,
-
1
,
-
1
,
0
);
X509_NAME_add_entry_by_txt
(
cert_name
,
"CN"
,
MBSTRING_ASC
,
(
u
nsigned
char
*
)
MS_APP_NAME
,
-
1
,
-
1
,
0
);
X509_NAME_add_entry_by_txt
(
cert_name
,
"CN"
,
MBSTRING_ASC
,
(
u
int8_t
*
)
MS_APP_NAME
,
-
1
,
-
1
,
0
);
// It is self-signed so set the issuer name to be the same as the subject.
// It is self-signed so set the issuer name to be the same as the subject.
ret
=
X509_set_issuer_name
(
DTLSTransport
::
certificate
,
cert_name
);
ret
=
X509_set_issuer_name
(
DTLSTransport
::
certificate
,
cert_name
);
...
@@ -418,7 +418,7 @@ namespace RTC
...
@@ -418,7 +418,7 @@ namespace RTC
{
{
std
::
string
algorithm_str
=
it
->
first
;
std
::
string
algorithm_str
=
it
->
first
;
FingerprintAlgorithm
algorithm
=
it
->
second
;
FingerprintAlgorithm
algorithm
=
it
->
second
;
u
nsigned
char
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
u
int8_t
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
unsigned
int
size
=
0
;
unsigned
int
size
=
0
;
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
const
EVP_MD
*
hash_function
;
const
EVP_MD
*
hash_function
;
...
@@ -960,7 +960,7 @@ namespace RTC
...
@@ -960,7 +960,7 @@ namespace RTC
MS_ASSERT
(
this
->
remoteFingerprint
.
algorithm
!=
FingerprintAlgorithm
::
NONE
,
"remote fingerprint not set"
);
MS_ASSERT
(
this
->
remoteFingerprint
.
algorithm
!=
FingerprintAlgorithm
::
NONE
,
"remote fingerprint not set"
);
X509
*
certificate
;
X509
*
certificate
;
u
nsigned
char
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
u
int8_t
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
unsigned
int
size
=
0
;
unsigned
int
size
=
0
;
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
const
EVP_MD
*
hash_function
;
const
EVP_MD
*
hash_function
;
...
...
worker/src/RTC/ICEServer.cpp
浏览文件 @
9f73fee8
...
@@ -136,7 +136,7 @@ namespace RTC
...
@@ -136,7 +136,7 @@ namespace RTC
return
;
return
;
}
}
MS_DEBUG
(
"processing STUN Binding Request [Priority:%
u, UseCandidate:%s]"
,
(
unsigned
in
t
)
msg
->
GetPriority
(),
msg
->
HasUseCandidate
()
?
"true"
:
"false"
);
MS_DEBUG
(
"processing STUN Binding Request [Priority:%
"
PRIu32
", UseCandidate:%s]"
,
(
uint32_
t
)
msg
->
GetPriority
(),
msg
->
HasUseCandidate
()
?
"true"
:
"false"
);
// Create a success response.
// Create a success response.
RTC
::
STUNMessage
*
response
=
msg
->
CreateSuccessResponse
();
RTC
::
STUNMessage
*
response
=
msg
->
CreateSuccessResponse
();
...
@@ -191,13 +191,63 @@ namespace RTC
...
@@ -191,13 +191,63 @@ namespace RTC
return
false
;
return
false
;
}
}
void
ICEServer
::
RemoveTuple
(
RTC
::
TransportTuple
*
tuple
)
{
auto
it
=
this
->
tuples
.
begin
();
RTC
::
TransportTuple
*
removed_tuple
=
nullptr
;
// Find the removed tuple.
for
(;
it
!=
this
->
tuples
.
end
();
++
it
)
{
RTC
::
TransportTuple
*
stored_tuple
=
&
(
*
it
);
if
(
stored_tuple
->
Compare
(
tuple
))
{
removed_tuple
=
stored_tuple
;
break
;
}
}
// If not found, ignore.
if
(
!
removed_tuple
)
return
;
// If this is not the selected tuple just remove it.
if
(
removed_tuple
!=
this
->
selectedTuple
)
{
this
->
tuples
.
erase
(
it
);
return
;
}
// Otherwise this was the selected tuple.
else
{
this
->
tuples
.
erase
(
it
);
this
->
selectedTuple
=
nullptr
;
// Mark the first tuple as selected tuple (if any).
if
(
this
->
tuples
.
begin
()
!=
this
->
tuples
.
end
())
{
SetSelectedTuple
(
&
(
*
this
->
tuples
.
begin
()));
}
// Or just emit 'disconnected' and the null selected tuple..
else
{
// Update state.
this
->
state
=
IceState
::
DISCONNECTED
;
// Notify the listener.
this
->
listener
->
onICESelectedTuple
(
this
,
nullptr
);
this
->
listener
->
onICEDisconnected
(
this
);
}
}
}
void
ICEServer
::
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
)
void
ICEServer
::
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
)
{
{
MS_TRACE
();
MS_TRACE
();
MS_ASSERT
(
this
->
state
!=
IceState
::
NEW
,
"cannot force the selected tuple if not in 'connecting' or 'connected' state"
);
// TODO: Remove as this assert is reduntant.
MS_ASSERT
(
this
->
selectedTuple
!=
nullptr
,
"cannot force the selected tuple if there was not a selected tuple"
);
MS_ASSERT
(
this
->
selectedTuple
!=
nullptr
,
"cannot force the selected tuple if there was not a selected tuple"
);
auto
stored_tuple
=
HasTuple
(
tuple
);
auto
stored_tuple
=
HasTuple
(
tuple
);
...
@@ -258,6 +308,50 @@ namespace RTC
...
@@ -258,6 +308,50 @@ namespace RTC
break
;
break
;
}
}
case
IceState
:
:
DISCONNECTED
:
{
// There should be no tuples.
MS_ASSERT
(
this
->
tuples
.
size
()
==
0
,
"state is 'disconnected' but there are %zu tuples"
,
this
->
tuples
.
size
());
// There shouldn't be a selected tuple.
MS_ASSERT
(
this
->
selectedTuple
==
nullptr
,
"state is 'disconnected' but there is selected tuple"
);
if
(
!
has_use_candidate
)
{
MS_DEBUG
(
"transition from state 'disconnected' to 'connected'"
);
// Store the tuple.
auto
stored_tuple
=
AddTuple
(
tuple
);
// Mark it as selected tuple.
SetSelectedTuple
(
stored_tuple
);
// Update state.
this
->
state
=
IceState
::
CONNECTED
;
// Notify the listener.
this
->
listener
->
onICEConnected
(
this
);
}
else
{
MS_DEBUG
(
"transition from state 'disconnected' to 'completed'"
);
// Store the tuple.
auto
stored_tuple
=
AddTuple
(
tuple
);
// Mark it as selected tuple.
SetSelectedTuple
(
stored_tuple
);
// Update state.
this
->
state
=
IceState
::
COMPLETED
;
// Notify the listener.
this
->
listener
->
onICECompleted
(
this
);
}
break
;
}
case
IceState
:
:
CONNECTED
:
case
IceState
:
:
CONNECTED
:
{
{
// There should be some tuples.
// There should be some tuples.
...
@@ -385,42 +479,4 @@ namespace RTC
...
@@ -385,42 +479,4 @@ namespace RTC
// Notify the listener.
// Notify the listener.
this
->
listener
->
onICESelectedTuple
(
this
,
this
->
selectedTuple
);
this
->
listener
->
onICESelectedTuple
(
this
,
this
->
selectedTuple
);
}
}
// TODO
// bool Transport::RemoveTuple(RTC::TransportTuple* tuple)
// {
// for (auto it = this->tuples.begin(); it != this->tuples.end(); ++it)
// {
// RTC::TransportTuple* valid_tuple = &(*it);
// // If the tuple was a valid tuple then remove it.
// if (valid_tuple->Compare(tuple))
// {
// this->tuples.erase(it);
// // If it was the media tuple then unset it and set the media
// // tuple to the first valid tuple (if any).
// if (this->mediaTuple == valid_tuple)
// {
// if (this->tuples.begin() != this->tuples.end())
// {
// this->mediaTuple = &(*this->tuples.begin());
// }
// else
// {
// this->mediaTuple = nullptr;
// // This is just useful is there are just TCP tuples.
// this->icePaired = false;
// this->icePairedWithUseCandidate = false;
// // TODO: This should fire a 'icefailed' event.
// }
// }
// return true;
// }
// }
// return false;
// }
}
}
worker/src/RTC/IceCandidate.cpp
浏览文件 @
9f73fee8
...
@@ -6,7 +6,7 @@ namespace RTC
...
@@ -6,7 +6,7 @@ namespace RTC
{
{
/* Instance methods. */
/* Instance methods. */
IceCandidate
::
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
64
_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
32
_t
priority
)
:
foundation
(
"udpcandidate"
),
foundation
(
"udpcandidate"
),
priority
(
priority
),
priority
(
priority
),
ip
(
udpSocket
->
GetLocalIP
()),
ip
(
udpSocket
->
GetLocalIP
()),
...
@@ -15,7 +15,7 @@ namespace RTC
...
@@ -15,7 +15,7 @@ namespace RTC
type
(
CandidateType
::
HOST
)
type
(
CandidateType
::
HOST
)
{}
{}
IceCandidate
::
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
64
_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
32
_t
priority
)
:
foundation
(
"tcpcandidate"
),
foundation
(
"tcpcandidate"
),
priority
(
priority
),
priority
(
priority
),
ip
(
tcpServer
->
GetLocalIP
()),
ip
(
tcpServer
->
GetLocalIP
()),
...
@@ -42,7 +42,7 @@ namespace RTC
...
@@ -42,7 +42,7 @@ namespace RTC
Json
::
Value
data
;
Json
::
Value
data
;
data
[
k_foundation
]
=
this
->
foundation
;
data
[
k_foundation
]
=
this
->
foundation
;
data
[
k_priority
]
=
(
unsigned
int
)
this
->
priority
;
data
[
k_priority
]
=
this
->
priority
;
data
[
k_ip
]
=
this
->
ip
;
data
[
k_ip
]
=
this
->
ip
;
data
[
k_port
]
=
this
->
port
;
data
[
k_port
]
=
this
->
port
;
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
9f73fee8
...
@@ -8,7 +8,7 @@ namespace RTC
...
@@ -8,7 +8,7 @@ namespace RTC
{
{
/* Instance methods. */
/* Instance methods. */
Peer
::
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
nsigned
in
t
peerId
,
std
::
string
&
peerName
)
:
Peer
::
Peer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
int32_
t
peerId
,
std
::
string
&
peerName
)
:
peerId
(
peerId
),
peerId
(
peerId
),
peerName
(
peerName
),
peerName
(
peerName
),
listener
(
listener
),
listener
(
listener
),
...
@@ -75,11 +75,11 @@ namespace RTC
...
@@ -75,11 +75,11 @@ namespace RTC
{
{
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
{
{
u
nsigned
in
t
peerId
=
this
->
peerId
;
u
int32_
t
peerId
=
this
->
peerId
;
Close
();
Close
();
MS_DEBUG
(
"Peer closed [peerId:%
u
]"
,
peerId
);
MS_DEBUG
(
"Peer closed [peerId:%
"
PRIu32
"
]"
,
peerId
);
request
->
Accept
();
request
->
Accept
();
break
;
break
;
...
@@ -97,7 +97,7 @@ namespace RTC
...
@@ -97,7 +97,7 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
{
{
RTC
::
Transport
*
transport
;
RTC
::
Transport
*
transport
;
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
try
try
{
{
...
@@ -129,7 +129,7 @@ namespace RTC
...
@@ -129,7 +129,7 @@ namespace RTC
this
->
transports
[
transportId
]
=
transport
;
this
->
transports
[
transportId
]
=
transport
;
MS_DEBUG
(
"Transport created [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Transport created [transportId:%
"
PRIu32
"
]"
,
transportId
);
auto
data
=
transport
->
toJson
();
auto
data
=
transport
->
toJson
();
...
@@ -141,7 +141,7 @@ namespace RTC
...
@@ -141,7 +141,7 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
peer_createAssociatedTransport
:
case
Channel
:
:
Request
::
MethodId
::
peer_createAssociatedTransport
:
{
{
RTC
::
Transport
*
transport
;
RTC
::
Transport
*
transport
;
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
try
try
{
{
...
@@ -197,7 +197,7 @@ namespace RTC
...
@@ -197,7 +197,7 @@ namespace RTC
this
->
transports
[
transportId
]
=
transport
;
this
->
transports
[
transportId
]
=
transport
;
MS_DEBUG
(
"Associated Transport created [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Associated Transport created [transportId:%
"
PRIu32
"
]"
,
transportId
);
auto
data
=
transport
->
toJson
();
auto
data
=
transport
->
toJson
();
...
@@ -242,7 +242,7 @@ namespace RTC
...
@@ -242,7 +242,7 @@ namespace RTC
}
}
}
}
RTC
::
Transport
*
Peer
::
GetTransportFromRequest
(
Channel
::
Request
*
request
,
u
nsigned
in
t
*
transportId
)
RTC
::
Transport
*
Peer
::
GetTransportFromRequest
(
Channel
::
Request
*
request
,
u
int32_
t
*
transportId
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
9f73fee8
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
/* Static helpers. */
/* Static helpers. */
static
inline
static
inline
uint
64
_t
generateIceCandidatePriority
(
uint16_t
local_preference
,
RTC
::
ICEServer
::
IceComponent
component
)
uint
32
_t
generateIceCandidatePriority
(
uint16_t
local_preference
,
RTC
::
ICEServer
::
IceComponent
component
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -29,13 +29,9 @@ uint64_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer:
...
@@ -29,13 +29,9 @@ uint64_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer:
namespace
RTC
namespace
RTC
{
{
/* Class variables. */
size_t
Transport
::
maxTuples
=
8
;
/* Instance methods. */
/* Instance methods. */
Transport
::
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
nsigned
in
t
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
)
:
Transport
::
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
u
int32_
t
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
)
:
transportId
(
transportId
),
transportId
(
transportId
),
listener
(
listener
),
listener
(
listener
),
notifier
(
notifier
)
notifier
(
notifier
)
...
@@ -108,7 +104,7 @@ namespace RTC
...
@@ -108,7 +104,7 @@ namespace RTC
if
(
preferUdp
)
if
(
preferUdp
)
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
uint
64
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
uint
32
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
try
try
{
{
...
@@ -135,7 +131,7 @@ namespace RTC
...
@@ -135,7 +131,7 @@ namespace RTC
if
(
preferUdp
)
if
(
preferUdp
)
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
uint
64
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
uint
32
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
try
try
{
{
...
@@ -162,7 +158,7 @@ namespace RTC
...
@@ -162,7 +158,7 @@ namespace RTC
if
(
preferTcp
)
if
(
preferTcp
)
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
uint
64
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
uint
32
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
try
try
{
{
...
@@ -189,7 +185,7 @@ namespace RTC
...
@@ -189,7 +185,7 @@ namespace RTC
if
(
preferTcp
)
if
(
preferTcp
)
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
local_preference
+=
ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT
;
uint
64
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
uint
32
_t
priority
=
generateIceCandidatePriority
(
local_preference
,
this
->
iceServer
->
GetComponent
());
try
try
{
{
...
@@ -283,6 +279,7 @@ namespace RTC
...
@@ -283,6 +279,7 @@ namespace RTC
static
const
Json
::
StaticString
v_new
(
"new"
);
static
const
Json
::
StaticString
v_new
(
"new"
);
static
const
Json
::
StaticString
v_connected
(
"connected"
);
static
const
Json
::
StaticString
v_connected
(
"connected"
);
static
const
Json
::
StaticString
v_completed
(
"completed"
);
static
const
Json
::
StaticString
v_completed
(
"completed"
);
static
const
Json
::
StaticString
v_disconnected
(
"disconnected"
);
static
const
Json
::
StaticString
k_dtlsLocalParameters
(
"dtlsLocalParameters"
);
static
const
Json
::
StaticString
k_dtlsLocalParameters
(
"dtlsLocalParameters"
);
static
const
Json
::
StaticString
k_fingerprints
(
"fingerprints"
);
static
const
Json
::
StaticString
k_fingerprints
(
"fingerprints"
);
static
const
Json
::
StaticString
k_role
(
"role"
);
static
const
Json
::
StaticString
k_role
(
"role"
);
...
@@ -329,6 +326,9 @@ namespace RTC
...
@@ -329,6 +326,9 @@ namespace RTC
case
RTC
:
:
ICEServer
::
IceState
::
COMPLETED
:
case
RTC
:
:
ICEServer
::
IceState
::
COMPLETED
:
data
[
k_iceState
]
=
v_completed
;
data
[
k_iceState
]
=
v_completed
;
break
;
break
;
case
RTC
:
:
ICEServer
::
IceState
::
DISCONNECTED
:
data
[
k_iceState
]
=
v_disconnected
;
break
;
}
}
// Add `dtlsLocalParameters.fingerprints`.
// Add `dtlsLocalParameters.fingerprints`.
...
@@ -381,11 +381,11 @@ namespace RTC
...
@@ -381,11 +381,11 @@ namespace RTC
{
{
case
Channel
:
:
Request
::
MethodId
::
transport_close
:
case
Channel
:
:
Request
::
MethodId
::
transport_close
:
{
{
u
nsigned
in
t
transportId
=
this
->
transportId
;
u
int32_
t
transportId
=
this
->
transportId
;
Close
();
Close
();
MS_DEBUG
(
"Transport closed [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Transport closed [transportId:%
"
PRIu32
"
]"
,
transportId
);
request
->
Accept
();
request
->
Accept
();
break
;
break
;
...
@@ -522,6 +522,8 @@ namespace RTC
...
@@ -522,6 +522,8 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
this
->
selectedTuple
=
nullptr
;
for
(
auto
socket
:
this
->
udpSockets
)
for
(
auto
socket
:
this
->
udpSockets
)
socket
->
Close
();
socket
->
Close
();
this
->
udpSockets
.
clear
();
this
->
udpSockets
.
clear
();
...
@@ -531,7 +533,7 @@ namespace RTC
...
@@ -531,7 +533,7 @@ namespace RTC
this
->
tcpServers
.
clear
();
this
->
tcpServers
.
clear
();
}
}
Transport
*
Transport
::
CreateAssociatedTransport
(
u
nsigned
in
t
transportId
)
Transport
*
Transport
::
CreateAssociatedTransport
(
u
int32_
t
transportId
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -738,14 +740,9 @@ namespace RTC
...
@@ -738,14 +740,9 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
// TODO
RTC
::
TransportTuple
tuple
(
connection
);
// RTC::TransportTuple tuple(connection);
// if (RemoveTuple(&tuple))
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
// {
// MS_DEBUG("valid tuple %s:", is_closed_by_peer ? "closed by peer" : "locally closed");
// }
}
}
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
)
...
@@ -820,12 +817,13 @@ namespace RTC
...
@@ -820,12 +817,13 @@ namespace RTC
this
->
selectedTuple
=
tuple
;
this
->
selectedTuple
=
tuple
;
// Notify.
// Notify if tuple is given.
if
(
tuple
)
{
eventData
[
k_iceSelectedTuple
]
=
tuple
->
toJson
();
eventData
[
k_iceSelectedTuple
]
=
tuple
->
toJson
();
// Notify.
this
->
notifier
->
Emit
(
this
->
transportId
,
"iceselectedtuplechange"
,
eventData
);
this
->
notifier
->
Emit
(
this
->
transportId
,
"iceselectedtuplechange"
,
eventData
);
}
}
}
void
Transport
::
onICEConnected
(
RTC
::
ICEServer
*
iceServer
)
void
Transport
::
onICEConnected
(
RTC
::
ICEServer
*
iceServer
)
{
{
...
@@ -865,6 +863,24 @@ namespace RTC
...
@@ -865,6 +863,24 @@ namespace RTC
MayRunDTLSTransport
();
MayRunDTLSTransport
();
}
}
void
Transport
::
onICEDisconnected
(
RTC
::
ICEServer
*
iceServer
)
{
MS_TRACE
();
static
const
Json
::
StaticString
k_iceState
(
"iceState"
);
static
const
Json
::
StaticString
v_disconnected
(
"disconnected"
);
Json
::
Value
eventData
;
MS_DEBUG
(
"ICE disconnected"
);
// Unset the
// Notify.
eventData
[
k_iceState
]
=
v_disconnected
;
this
->
notifier
->
Emit
(
this
->
transportId
,
"icestatechange"
,
eventData
);
}
void
Transport
::
onDTLSConnecting
(
RTC
::
DTLSTransport
*
dtlsTransport
)
void
Transport
::
onDTLSConnecting
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -901,39 +917,39 @@ namespace RTC
...
@@ -901,39 +917,39 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
}
}
void
Transport
::
onDTLS
Clos
ed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
void
Transport
::
onDTLS
Fail
ed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
{
MS_TRACE
();
MS_TRACE
();
static
const
Json
::
StaticString
k_dtlsState
(
"dtlsState"
);
static
const
Json
::
StaticString
k_dtlsState
(
"dtlsState"
);
static
const
Json
::
StaticString
v_
closed
(
"clos
ed"
);
static
const
Json
::
StaticString
v_
failed
(
"fail
ed"
);
Json
::
Value
eventData
;
Json
::
Value
eventData
;
MS_DEBUG
(
"DTLS
remotely disconnect
ed"
);
MS_DEBUG
(
"DTLS
fail
ed"
);
ClosePorts
();
ClosePorts
();
// Notify.
// Notify.
eventData
[
k_dtlsState
]
=
v_
clos
ed
;
eventData
[
k_dtlsState
]
=
v_
fail
ed
;
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
}
}
void
Transport
::
onDTLS
Fail
ed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
void
Transport
::
onDTLS
Clos
ed
(
RTC
::
DTLSTransport
*
dtlsTransport
)
{
{
MS_TRACE
();
MS_TRACE
();
static
const
Json
::
StaticString
k_dtlsState
(
"dtlsState"
);
static
const
Json
::
StaticString
k_dtlsState
(
"dtlsState"
);
static
const
Json
::
StaticString
v_
failed
(
"fail
ed"
);
static
const
Json
::
StaticString
v_
closed
(
"clos
ed"
);
Json
::
Value
eventData
;
Json
::
Value
eventData
;
MS_DEBUG
(
"DTLS
fail
ed"
);
MS_DEBUG
(
"DTLS
remotely disconnect
ed"
);
ClosePorts
();
ClosePorts
();
// Notify.
// Notify.
eventData
[
k_dtlsState
]
=
v_
fail
ed
;
eventData
[
k_dtlsState
]
=
v_
clos
ed
;
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
}
}
...
@@ -943,7 +959,7 @@ namespace RTC
...
@@ -943,7 +959,7 @@ namespace RTC
if
(
!
this
->
selectedTuple
)
if
(
!
this
->
selectedTuple
)
{
{
MS_DEBUG
(
"no
media address
set, cannot send DTLS packet"
);
MS_DEBUG
(
"no
selected tuple
set, cannot send DTLS packet"
);
return
;
return
;
}
}
...
...
worker/src/Utils/Crypto.cpp
浏览文件 @
9f73fee8
...
@@ -8,7 +8,7 @@ namespace Utils
...
@@ -8,7 +8,7 @@ namespace Utils
{
{
/* Static variables. */
/* Static variables. */
u
nsigned
in
t
Crypto
::
seed
;
u
int32_
t
Crypto
::
seed
;
HMAC_CTX
Crypto
::
hmacSha1Ctx
;
HMAC_CTX
Crypto
::
hmacSha1Ctx
;
MS_BYTE
Crypto
::
hmacSha1Buffer
[
20
];
// SHA-1 result is 20 bytes long.
MS_BYTE
Crypto
::
hmacSha1Buffer
[
20
];
// SHA-1 result is 20 bytes long.
const
MS_4BYTES
Crypto
::
crc32Table
[]
=
const
MS_4BYTES
Crypto
::
crc32Table
[]
=
...
@@ -66,7 +66,7 @@ namespace Utils
...
@@ -66,7 +66,7 @@ namespace Utils
// Init the vrypto seed with a random number taken from the address
// Init the vrypto seed with a random number taken from the address
// of the seed variable itself (which is random).
// of the seed variable itself (which is random).
Crypto
::
seed
=
(
u
nsigned
in
t
)(
unsigned
long
)
&
Crypto
::
seed
;
Crypto
::
seed
=
(
u
int32_
t
)(
unsigned
long
)
&
Crypto
::
seed
;
// Create an OpenSSL HMAC_CTX context for HMAC SHA1 calculation.
// Create an OpenSSL HMAC_CTX context for HMAC SHA1 calculation.
HMAC_CTX_init
(
&
Crypto
::
hmacSha1Ctx
);
HMAC_CTX_init
(
&
Crypto
::
hmacSha1Ctx
);
...
@@ -88,11 +88,11 @@ namespace Utils
...
@@ -88,11 +88,11 @@ namespace Utils
ret
=
HMAC_Init_ex
(
&
Crypto
::
hmacSha1Ctx
,
key
.
c_str
(),
key
.
length
(),
EVP_sha1
(),
nullptr
);
ret
=
HMAC_Init_ex
(
&
Crypto
::
hmacSha1Ctx
,
key
.
c_str
(),
key
.
length
(),
EVP_sha1
(),
nullptr
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Init_ex() failed with key '%s'"
,
key
.
c_str
());
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Init_ex() failed with key '%s'"
,
key
.
c_str
());
ret
=
HMAC_Update
(
&
Crypto
::
hmacSha1Ctx
,
(
const
u
nsigned
char
*
)
data
,
(
int
)
len
);
ret
=
HMAC_Update
(
&
Crypto
::
hmacSha1Ctx
,
(
const
u
int8_t
*
)
data
,
(
int
)
len
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
u
nsigned
in
t
result_len
;
u
int32_
t
result_len
;
ret
=
HMAC_Final
(
&
Crypto
::
hmacSha1Ctx
,
(
u
nsigned
char
*
)
Crypto
::
hmacSha1Buffer
,
&
result_len
);
ret
=
HMAC_Final
(
&
Crypto
::
hmacSha1Ctx
,
(
u
int8_t
*
)
Crypto
::
hmacSha1Buffer
,
&
result_len
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
MS_ASSERT
(
result_len
==
20
,
"OpenSSL HMAC_Final() result_len is %u instead of 20"
,
result_len
);
MS_ASSERT
(
result_len
==
20
,
"OpenSSL HMAC_Final() result_len is %u instead of 20"
,
result_len
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论