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 个修改的文件
包含
207 行增加
和
143 行删除
+207
-143
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
+50
-34
Crypto.cpp
worker/src/Utils/Crypto.cpp
+5
-5
没有找到文件。
lib/Transport.js
浏览文件 @
9f73fee8
...
...
@@ -77,6 +77,11 @@ class Transport extends EventEmitter
case
'icestatechange'
:
{
this
.
_data
.
iceState
=
data
.
iceState
;
// Unset .iceSelectedTuple if required
if
(
data
.
iceState
===
'disconnected'
)
{
delete
this
.
_data
.
iceSelectedTuple
;
}
// Emit it to the app
this
.
emit
(
event
,
data
);
break
;
...
...
@@ -157,6 +162,8 @@ class Transport extends EventEmitter
// We won't receive events anymore, so be nice and manually update
// some fields and emit events before firing 'close'
delete
this
.
_data
.
iceSelectedTuple
;
if
(
this
.
_data
.
iceState
!==
'closed'
)
{
this
.
_data
.
iceState
=
'closed'
;
...
...
tester/lib/index.js
浏览文件 @
9f73fee8
...
...
@@ -7,7 +7,7 @@ debugerror.log = console.error.bind(console);
const
domready
=
require
(
'domready'
);
const
rtcninja
=
require
(
'rtcninja'
);
//
const randomString = require('random-string');
const
randomString
=
require
(
'random-string'
);
const
Peer
=
require
(
'./Peer'
);
let
protooWsUrl
;
...
...
@@ -33,10 +33,10 @@ function run()
{
debug
(
'run()'
);
//
let username = randomString();
//
let uuid = randomString();
let
username
=
'alice'
;
let
uuid
=
'aaaa'
;
let
username
=
randomString
();
let
uuid
=
randomString
();
//
let username = 'alice';
//
let uuid = 'aaaa';
let
peer
=
new
Peer
(
protooWsUrl
,
username
,
uuid
);
...
...
tester/server/server.js
浏览文件 @
9f73fee8
...
...
@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
{
let
promise
=
mediaPeer
.
createTransport
(
{
udp
:
tru
e
,
udp
:
fals
e
,
tcp
:
true
,
preferIPv4
:
true
,
preferUdp
:
true
...
...
worker/include/Loop.h
浏览文件 @
9f73fee8
...
...
@@ -20,7 +20,7 @@ public:
private
:
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. */
public
:
...
...
@@ -43,7 +43,7 @@ private:
SignalsHandler
*
signalsHandler
=
nullptr
;
// Others.
bool
closed
=
false
;
std
::
unordered_map
<
u
nsigned
in
t
,
RTC
::
Room
*>
rooms
;
std
::
unordered_map
<
u
int32_
t
,
RTC
::
Room
*>
rooms
;
};
#endif
worker/include/RTC/ICEServer.h
浏览文件 @
9f73fee8
...
...
@@ -23,7 +23,8 @@ namespace RTC
{
NEW
=
1
,
CONNECTED
,
COMPLETED
COMPLETED
,
DISCONNECTED
};
public
:
...
...
@@ -38,6 +39,7 @@ namespace RTC
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
=
0
;
virtual
void
onICEDisconnected
(
ICEServer
*
iceServer
)
=
0
;
};
public
:
...
...
@@ -50,6 +52,7 @@ namespace RTC
std
::
string
&
GetPassword
();
IceState
GetState
();
bool
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
);
void
RemoveTuple
(
RTC
::
TransportTuple
*
tuple
);
// This should be just called in 'connected' or completed' state
// and the given tuple must be an already valid tuple.
void
ForceSelectedTuple
(
RTC
::
TransportTuple
*
tuple
);
...
...
worker/include/RTC/IceCandidate.h
浏览文件 @
9f73fee8
...
...
@@ -31,15 +31,15 @@ namespace RTC
};
public
:
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
64
_t
priority
);
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
64
_t
priority
);
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
32
_t
priority
);
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
32
_t
priority
);
Json
::
Value
toJson
();
private
:
// Others.
std
::
string
foundation
;
uint
64
_t
priority
;
uint
32
_t
priority
;
std
::
string
ip
;
Protocol
protocol
;
MS_PORT
port
;
...
...
worker/include/RTC/Peer.h
浏览文件 @
9f73fee8
#ifndef MS_RTC_PEER_H
#define MS_RTC_PEER_H
#include "common.h"
#include "RTC/Transport.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
...
...
@@ -21,7 +22,7 @@ namespace RTC
};
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
();
void
Close
();
...
...
@@ -29,7 +30,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
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. */
public
:
...
...
@@ -37,7 +38,7 @@ namespace RTC
public
:
// Passed by argument.
u
nsigned
in
t
peerId
;
u
int32_
t
peerId
;
std
::
string
peerName
;
private
:
...
...
@@ -45,7 +46,7 @@ namespace RTC
Listener
*
listener
=
nullptr
;
Channel
::
Notifier
*
notifier
=
nullptr
;
// 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
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
};
private
:
static
size_t
maxTuples
;
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
();
void
Close
();
...
...
@@ -43,7 +40,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
std
::
string
&
GetIceUsernameFragment
();
std
::
string
&
GetIcePassword
();
Transport
*
CreateAssociatedTransport
(
u
nsigned
in
t
transportId
);
Transport
*
CreateAssociatedTransport
(
u
int32_
t
transportId
);
private
:
void
ClosePorts
();
...
...
@@ -81,6 +78,7 @@ namespace RTC
virtual
void
onICESelectedTuple
(
ICEServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onICEConnected
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICECompleted
(
ICEServer
*
iceServer
)
override
;
virtual
void
onICEDisconnected
(
ICEServer
*
iceServer
)
override
;
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public
:
...
...
@@ -93,7 +91,7 @@ namespace RTC
public
:
// Passed by argument.
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
protected
:
// Others.
...
...
worker/include/Utils.h
浏览文件 @
9f73fee8
...
...
@@ -199,14 +199,13 @@ namespace Utils
public
:
static
void
ClassInit
();
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 char* GetRandomHexString(char* str, size_t len);
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
);
private
:
static
u
nsigned
in
t
seed
;
static
u
int32_
t
seed
;
static
HMAC_CTX
hmacSha1Ctx
;
static
MS_BYTE
hmacSha1Buffer
[];
static
const
MS_4BYTES
crc32Table
[
256
];
...
...
@@ -215,14 +214,14 @@ namespace Utils
/* Inline static methods. */
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.
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
// 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
;
}
...
...
@@ -247,23 +246,6 @@ namespace Utils
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
MS_4BYTES
Crypto
::
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
)
{
...
...
worker/include/common.h
浏览文件 @
9f73fee8
...
...
@@ -3,6 +3,7 @@
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <cinttypes> // PRIu64, etc
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
...
...
worker/src/Loop.cpp
浏览文件 @
9f73fee8
...
...
@@ -87,7 +87,7 @@ void Loop::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
();
...
...
@@ -177,7 +177,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case
Channel
:
:
Request
::
MethodId
::
worker_createRoom
:
{
RTC
::
Room
*
room
;
u
nsigned
in
t
roomId
;
u
int32_
t
roomId
;
try
{
...
...
@@ -209,7 +209,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
this
->
rooms
[
roomId
]
=
room
;
MS_DEBUG
(
"Room created [roomId:%
u
]"
,
roomId
);
MS_DEBUG
(
"Room created [roomId:%
"
PRIu32
"
]"
,
roomId
);
request
->
Accept
();
break
;
...
...
worker/src/RTC/DTLSTransport.cpp
浏览文件 @
9f73fee8
...
...
@@ -206,8 +206,8 @@ namespace RTC
LOG_OPENSSL_ERROR
(
"X509_get_subject_name() failed"
);
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
,
"CN"
,
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
int8_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
(
DTLSTransport
::
certificate
,
cert_name
);
...
...
@@ -418,7 +418,7 @@ namespace RTC
{
std
::
string
algorithm_str
=
it
->
first
;
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
;
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
const
EVP_MD
*
hash_function
;
...
...
@@ -960,7 +960,7 @@ namespace RTC
MS_ASSERT
(
this
->
remoteFingerprint
.
algorithm
!=
FingerprintAlgorithm
::
NONE
,
"remote fingerprint not set"
);
X509
*
certificate
;
u
nsigned
char
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
u
int8_t
binary_fingerprint
[
EVP_MAX_MD_SIZE
];
unsigned
int
size
=
0
;
char
hex_fingerprint
[(
EVP_MAX_MD_SIZE
*
2
)
+
1
];
const
EVP_MD
*
hash_function
;
...
...
worker/src/RTC/ICEServer.cpp
浏览文件 @
9f73fee8
...
...
@@ -136,7 +136,7 @@ namespace RTC
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.
RTC
::
STUNMessage
*
response
=
msg
->
CreateSuccessResponse
();
...
...
@@ -191,13 +191,63 @@ namespace RTC
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
)
{
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"
);
auto
stored_tuple
=
HasTuple
(
tuple
);
...
...
@@ -258,6 +308,50 @@ namespace RTC
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
:
{
// There should be some tuples.
...
...
@@ -385,42 +479,4 @@ namespace RTC
// Notify the listener.
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
{
/* Instance methods. */
IceCandidate
::
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
64
_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
UDPSocket
*
udpSocket
,
uint
32
_t
priority
)
:
foundation
(
"udpcandidate"
),
priority
(
priority
),
ip
(
udpSocket
->
GetLocalIP
()),
...
...
@@ -15,7 +15,7 @@ namespace RTC
type
(
CandidateType
::
HOST
)
{}
IceCandidate
::
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
64
_t
priority
)
:
IceCandidate
::
IceCandidate
(
RTC
::
TCPServer
*
tcpServer
,
uint
32
_t
priority
)
:
foundation
(
"tcpcandidate"
),
priority
(
priority
),
ip
(
tcpServer
->
GetLocalIP
()),
...
...
@@ -42,7 +42,7 @@ namespace RTC
Json
::
Value
data
;
data
[
k_foundation
]
=
this
->
foundation
;
data
[
k_priority
]
=
(
unsigned
int
)
this
->
priority
;
data
[
k_priority
]
=
this
->
priority
;
data
[
k_ip
]
=
this
->
ip
;
data
[
k_port
]
=
this
->
port
;
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
9f73fee8
...
...
@@ -8,7 +8,7 @@ namespace RTC
{
/* 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
),
peerName
(
peerName
),
listener
(
listener
),
...
...
@@ -75,11 +75,11 @@ namespace RTC
{
case
Channel
:
:
Request
::
MethodId
::
peer_close
:
{
u
nsigned
in
t
peerId
=
this
->
peerId
;
u
int32_
t
peerId
=
this
->
peerId
;
Close
();
MS_DEBUG
(
"Peer closed [peerId:%
u
]"
,
peerId
);
MS_DEBUG
(
"Peer closed [peerId:%
"
PRIu32
"
]"
,
peerId
);
request
->
Accept
();
break
;
...
...
@@ -97,7 +97,7 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
peer_createTransport
:
{
RTC
::
Transport
*
transport
;
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
try
{
...
...
@@ -129,7 +129,7 @@ namespace RTC
this
->
transports
[
transportId
]
=
transport
;
MS_DEBUG
(
"Transport created [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Transport created [transportId:%
"
PRIu32
"
]"
,
transportId
);
auto
data
=
transport
->
toJson
();
...
...
@@ -141,7 +141,7 @@ namespace RTC
case
Channel
:
:
Request
::
MethodId
::
peer_createAssociatedTransport
:
{
RTC
::
Transport
*
transport
;
u
nsigned
in
t
transportId
;
u
int32_
t
transportId
;
try
{
...
...
@@ -197,7 +197,7 @@ namespace RTC
this
->
transports
[
transportId
]
=
transport
;
MS_DEBUG
(
"Associated Transport created [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Associated Transport created [transportId:%
"
PRIu32
"
]"
,
transportId
);
auto
data
=
transport
->
toJson
();
...
...
@@ -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
();
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
9f73fee8
...
...
@@ -14,7 +14,7 @@
/* Static helpers. */
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
();
...
...
@@ -29,13 +29,9 @@ uint64_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer:
namespace
RTC
{
/* Class variables. */
size_t
Transport
::
maxTuples
=
8
;
/* 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
),
listener
(
listener
),
notifier
(
notifier
)
...
...
@@ -108,7 +104,7 @@ namespace RTC
if
(
preferUdp
)
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
{
...
...
@@ -135,7 +131,7 @@ namespace RTC
if
(
preferUdp
)
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
{
...
...
@@ -162,7 +158,7 @@ namespace RTC
if
(
preferTcp
)
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
{
...
...
@@ -189,7 +185,7 @@ namespace RTC
if
(
preferTcp
)
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
{
...
...
@@ -283,6 +279,7 @@ namespace RTC
static
const
Json
::
StaticString
v_new
(
"new"
);
static
const
Json
::
StaticString
v_connected
(
"connected"
);
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_fingerprints
(
"fingerprints"
);
static
const
Json
::
StaticString
k_role
(
"role"
);
...
...
@@ -329,6 +326,9 @@ namespace RTC
case
RTC
:
:
ICEServer
::
IceState
::
COMPLETED
:
data
[
k_iceState
]
=
v_completed
;
break
;
case
RTC
:
:
ICEServer
::
IceState
::
DISCONNECTED
:
data
[
k_iceState
]
=
v_disconnected
;
break
;
}
// Add `dtlsLocalParameters.fingerprints`.
...
...
@@ -381,11 +381,11 @@ namespace RTC
{
case
Channel
:
:
Request
::
MethodId
::
transport_close
:
{
u
nsigned
in
t
transportId
=
this
->
transportId
;
u
int32_
t
transportId
=
this
->
transportId
;
Close
();
MS_DEBUG
(
"Transport closed [transportId:%
u
]"
,
transportId
);
MS_DEBUG
(
"Transport closed [transportId:%
"
PRIu32
"
]"
,
transportId
);
request
->
Accept
();
break
;
...
...
@@ -522,6 +522,8 @@ namespace RTC
{
MS_TRACE
();
this
->
selectedTuple
=
nullptr
;
for
(
auto
socket
:
this
->
udpSockets
)
socket
->
Close
();
this
->
udpSockets
.
clear
();
...
...
@@ -531,7 +533,7 @@ namespace RTC
this
->
tcpServers
.
clear
();
}
Transport
*
Transport
::
CreateAssociatedTransport
(
u
nsigned
in
t
transportId
)
Transport
*
Transport
::
CreateAssociatedTransport
(
u
int32_
t
transportId
)
{
MS_TRACE
();
...
...
@@ -738,14 +740,9 @@ namespace RTC
if
(
!
IsAlive
())
return
;
// TODO
// RTC::TransportTuple tuple(connection);
RTC
::
TransportTuple
tuple
(
connection
);
// if (RemoveTuple(&tuple))
// {
// MS_DEBUG("valid tuple %s:", is_closed_by_peer ? "closed by peer" : "locally closed");
// }
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
}
void
Transport
::
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
...
...
@@ -820,11 +817,12 @@ namespace RTC
this
->
selectedTuple
=
tuple
;
// Notify.
eventData
[
k_iceSelectedTuple
]
=
tuple
->
toJson
();
// Notify.
this
->
notifier
->
Emit
(
this
->
transportId
,
"iceselectedtuplechange"
,
eventData
);
// Notify if tuple is given.
if
(
tuple
)
{
eventData
[
k_iceSelectedTuple
]
=
tuple
->
toJson
();
this
->
notifier
->
Emit
(
this
->
transportId
,
"iceselectedtuplechange"
,
eventData
);
}
}
void
Transport
::
onICEConnected
(
RTC
::
ICEServer
*
iceServer
)
...
...
@@ -865,6 +863,24 @@ namespace RTC
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
)
{
MS_TRACE
();
...
...
@@ -901,39 +917,39 @@ namespace RTC
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
();
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
;
MS_DEBUG
(
"DTLS
remotely disconnect
ed"
);
MS_DEBUG
(
"DTLS
fail
ed"
);
ClosePorts
();
// Notify.
eventData
[
k_dtlsState
]
=
v_
clos
ed
;
eventData
[
k_dtlsState
]
=
v_
fail
ed
;
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
();
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
;
MS_DEBUG
(
"DTLS
fail
ed"
);
MS_DEBUG
(
"DTLS
remotely disconnect
ed"
);
ClosePorts
();
// Notify.
eventData
[
k_dtlsState
]
=
v_
fail
ed
;
eventData
[
k_dtlsState
]
=
v_
clos
ed
;
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
}
...
...
@@ -943,7 +959,7 @@ namespace RTC
if
(
!
this
->
selectedTuple
)
{
MS_DEBUG
(
"no
media address
set, cannot send DTLS packet"
);
MS_DEBUG
(
"no
selected tuple
set, cannot send DTLS packet"
);
return
;
}
...
...
worker/src/Utils/Crypto.cpp
浏览文件 @
9f73fee8
...
...
@@ -8,7 +8,7 @@ namespace Utils
{
/* Static variables. */
u
nsigned
in
t
Crypto
::
seed
;
u
int32_
t
Crypto
::
seed
;
HMAC_CTX
Crypto
::
hmacSha1Ctx
;
MS_BYTE
Crypto
::
hmacSha1Buffer
[
20
];
// SHA-1 result is 20 bytes long.
const
MS_4BYTES
Crypto
::
crc32Table
[]
=
...
...
@@ -66,7 +66,7 @@ namespace Utils
// Init the vrypto seed with a random number taken from the address
// 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.
HMAC_CTX_init
(
&
Crypto
::
hmacSha1Ctx
);
...
...
@@ -88,11 +88,11 @@ namespace Utils
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
());
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
);
u
nsigned
in
t
result_len
;
ret
=
HMAC_Final
(
&
Crypto
::
hmacSha1Ctx
,
(
u
nsigned
char
*
)
Crypto
::
hmacSha1Buffer
,
&
result_len
);
u
int32_
t
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
(
result_len
==
20
,
"OpenSSL HMAC_Final() result_len is %u instead of 20"
,
result_len
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论