Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
767e7e76
提交
767e7e76
authored
1月 07, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Work in ICE and TransportTuple.
上级
779269a9
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
406 行增加
和
278 行删除
+406
-278
Peer.js
lib/Peer.js
+12
-1
Room.js
lib/Room.js
+0
-2
Transport.js
lib/Transport.js
+2
-5
server.js
tester/server/server.js
+5
-5
IceServer.h
worker/include/RTC/IceServer.h
+42
-6
Transport.h
worker/include/RTC/Transport.h
+22
-160
TransportTuple.h
worker/include/RTC/TransportTuple.h
+19
-21
IceServer.cpp
worker/src/RTC/IceServer.cpp
+236
-11
Transport.cpp
worker/src/RTC/Transport.cpp
+64
-64
TransportTuple.cpp
worker/src/RTC/TransportTuple.cpp
+4
-3
没有找到文件。
lib/Peer.js
浏览文件 @
767e7e76
...
@@ -28,7 +28,15 @@ class Peer extends EventEmitter
...
@@ -28,7 +28,15 @@ class Peer extends EventEmitter
// Closed flag
// Closed flag
this
.
_closed
=
false
;
this
.
_closed
=
false
;
// TODO: subscribe to channel notifications from the worker
// Subscribe to notifications
this
.
_channel
.
on
(
this
.
_internal
.
peerId
,
(
event
)
=>
{
switch
(
event
)
{
default
:
logger
.
error
(
'ignoring unknown event "%s"'
,
event
);
}
});
}
}
get
closed
()
get
closed
()
...
@@ -51,6 +59,9 @@ class Peer extends EventEmitter
...
@@ -51,6 +59,9 @@ class Peer extends EventEmitter
this
.
_closed
=
true
;
this
.
_closed
=
true
;
// Remove notification subscriptions (wait a bit so closure events arrive)
setTimeout
(()
=>
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
peerId
),
1000
);
// Close every Transport
// Close every Transport
this
.
_transports
.
forEach
((
transport
)
=>
transport
.
close
(
undefined
,
true
));
this
.
_transports
.
forEach
((
transport
)
=>
transport
.
close
(
undefined
,
true
));
...
...
lib/Room.js
浏览文件 @
767e7e76
...
@@ -27,8 +27,6 @@ class Room extends EventEmitter
...
@@ -27,8 +27,6 @@ class Room extends EventEmitter
// Closed flag
// Closed flag
this
.
_closed
=
false
;
this
.
_closed
=
false
;
// TODO: subscribe to channel notifications from the worker
}
}
get
closed
()
get
closed
()
...
...
lib/Transport.js
浏览文件 @
767e7e76
...
@@ -35,10 +35,8 @@ class Transport extends EventEmitter
...
@@ -35,10 +35,8 @@ class Transport extends EventEmitter
case
'dtlsstatechange'
:
case
'dtlsstatechange'
:
{
{
this
.
_data
.
dtlsState
=
data
.
dtlsState
;
this
.
_data
.
dtlsState
=
data
.
dtlsState
;
// Emit it to the app
// Emit it to the app
this
.
emit
(
event
,
data
);
this
.
emit
(
event
,
data
);
break
;
break
;
}
}
...
@@ -93,9 +91,8 @@ class Transport extends EventEmitter
...
@@ -93,9 +91,8 @@ class Transport extends EventEmitter
this
.
_closed
=
true
;
this
.
_closed
=
true
;
// Remove notification subscriptions (do it in the next iteration to
// Remove notification subscriptions (wait a bit so closure events arrive)
// ensure the user receives closure events)
setTimeout
(()
=>
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
transportId
),
1000
);
setImmediate
(()
=>
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
transportId
));
if
(
!
dontSendChannel
)
if
(
!
dontSendChannel
)
{
{
...
...
tester/server/server.js
浏览文件 @
767e7e76
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
'use strict'
;
'use strict'
;
//
process.env.DEBUG = '*ERROR* *WARN* mediasoup* mediasoup-tester*';
process
.
env
.
DEBUG
=
'*ERROR* *WARN* mediasoup* mediasoup-tester*'
;
process
.
env
.
DEBUG
=
'*ERROR* *WARN* mediasoup* mediasoup-tester* -mediasoup:mediasoup-worker*'
;
//
process.env.DEBUG = '*ERROR* *WARN* mediasoup* mediasoup-tester* -mediasoup:mediasoup-worker*';
const
http
=
require
(
'http'
);
const
http
=
require
(
'http'
);
const
url
=
require
(
'url'
);
const
url
=
require
(
'url'
);
...
@@ -169,7 +169,7 @@ app.put('/test-transport', function(req)
...
@@ -169,7 +169,7 @@ app.put('/test-transport', function(req)
// Create transports promises
// Create transports promises
for
(
let
i
=
0
;
i
<
numTransports
;
i
++
)
for
(
let
i
=
0
;
i
<
numTransports
;
i
++
)
{
{
let
promise
=
mediaPeer
.
createTransport
({
udp
:
true
,
tcp
:
fals
e
});
let
promise
=
mediaPeer
.
createTransport
({
udp
:
true
,
tcp
:
tru
e
});
// Set transport event listeners
// Set transport event listeners
promise
.
then
((
transport
)
=>
promise
.
then
((
transport
)
=>
...
@@ -183,7 +183,7 @@ app.put('/test-transport', function(req)
...
@@ -183,7 +183,7 @@ app.put('/test-transport', function(req)
{
{
debug
(
'transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]'
,
data
.
dtlsState
,
transport
.
dtlsState
);
debug
(
'transport "dtlsstatechange" event [data.dtlsState:%s, transport.dtlsState:%s]'
,
data
.
dtlsState
,
transport
.
dtlsState
);
});
});
})
})
;
// Add the transport promise to the array of promises
// Add the transport promise to the array of promises
transportPromises
.
push
(
promise
);
transportPromises
.
push
(
promise
);
...
@@ -267,7 +267,7 @@ app.put('/test-transport', function(req)
...
@@ -267,7 +267,7 @@ app.put('/test-transport', function(req)
// Create a promise
// Create a promise
let
promise
=
transport
.
setRemoteDtlsParameters
(
let
promise
=
transport
.
setRemoteDtlsParameters
(
{
{
role
:
'
client
'
,
// SDP offer MUST always have a=setup:actpass so we can choose whatever we want
role
:
'
auto
'
,
// SDP offer MUST always have a=setup:actpass so we can choose whatever we want
fingerprint
:
fingerprint
:
{
{
algorithm
:
remoteFingerprint
.
type
,
algorithm
:
remoteFingerprint
.
type
,
...
...
worker/include/RTC/IceServer.h
浏览文件 @
767e7e76
...
@@ -2,16 +2,23 @@
...
@@ -2,16 +2,23 @@
#define MS_RTC_ICE_SERVER_H
#define MS_RTC_ICE_SERVER_H
#include "common.h"
#include "common.h"
#include "RTC/TransportSource.h"
#include "RTC/STUNMessage.h"
#include "RTC/STUNMessage.h"
#include "RTC/UDPSocket.h"
#include "RTC/TransportTuple.h"
#include "RTC/TCPConnection.h"
#include <string>
#include <string>
#include <list>
namespace
RTC
namespace
RTC
{
{
class
IceServer
class
IceServer
{
{
public
:
enum
class
IceState
{
NEW
=
1
,
CONNECTED
,
COMPLETED
};
public
:
public
:
class
Listener
class
Listener
{
{
...
@@ -20,17 +27,37 @@ namespace RTC
...
@@ -20,17 +27,37 @@ namespace RTC
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* returns, so the given pointers are still usable.
* returns, so the given pointers are still usable.
*/
*/
virtual
void
onOutgoingSTUNMessage
(
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
=
0
;
virtual
void
onOutgoingSTUNMessage
(
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onICEValidPair
(
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
=
0
;
virtual
void
onICESelectedTuple
(
IceServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
=
0
;
virtual
void
onICEConnected
(
IceServer
*
iceServer
)
=
0
;
virtual
void
onICECompleted
(
IceServer
*
iceServer
)
=
0
;
};
};
public
:
public
:
IceServer
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
);
IceServer
(
Listener
*
listener
,
const
std
::
string
&
usernameFragment
,
const
std
::
string
password
);
void
Close
();
void
Close
();
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Source
*
sourc
e
);
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Tuple
*
tupl
e
);
std
::
string
&
GetUsernameFragment
();
std
::
string
&
GetUsernameFragment
();
std
::
string
&
GetPassword
();
std
::
string
&
GetPassword
();
IceState
GetState
();
bool
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
);
private
:
void
HandleTuple
(
RTC
::
TransportTuple
*
tuple
,
bool
has_use_candidate
);
/**
* Store the given tuple and return its stored address.
*/
RTC
::
TransportTuple
*
AddTuple
(
RTC
::
TransportTuple
*
tuple
);
/**
* If the given tuple exists return its stored address, nullptr otherwise.
*/
RTC
::
TransportTuple
*
HasTuple
(
RTC
::
TransportTuple
*
tuple
);
/**
* Set the given tuple as the selected tuple.
* NOTE: The given tuple MUST be already stored within the list.
*/
void
SetSelectedTuple
(
RTC
::
TransportTuple
*
stored_tuple
);
private
:
private
:
// Passed by argument.
// Passed by argument.
...
@@ -38,6 +65,9 @@ namespace RTC
...
@@ -38,6 +65,9 @@ namespace RTC
// Others.
// Others.
std
::
string
usernameFragment
;
std
::
string
usernameFragment
;
std
::
string
password
;
std
::
string
password
;
IceState
state
=
IceState
::
NEW
;
std
::
list
<
RTC
::
TransportTuple
>
tuples
;
RTC
::
TransportTuple
*
selectedTuple
=
nullptr
;
};
};
/* Inline methods. */
/* Inline methods. */
...
@@ -53,6 +83,12 @@ namespace RTC
...
@@ -53,6 +83,12 @@ namespace RTC
{
{
return
this
->
password
;
return
this
->
password
;
}
}
inline
IceServer
::
IceState
IceServer
::
GetState
()
{
return
this
->
state
;
}
}
}
#endif
#endif
worker/include/RTC/Transport.h
浏览文件 @
767e7e76
...
@@ -2,18 +2,17 @@
...
@@ -2,18 +2,17 @@
#define MS_RTC_TRANSPORT_H
#define MS_RTC_TRANSPORT_H
#include "common.h"
#include "common.h"
#include "RTC/IceCandidate.h"
#include "RTC/IceServer.h"
#include "RTC/DTLSTransport.h"
#include "RTC/STUNMessage.h"
#include "RTC/TransportSource.h"
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPServer.h"
#include "RTC/TCPServer.h"
#include "RTC/TCPConnection.h"
#include "RTC/TCPConnection.h"
#include "RTC/IceCandidate.h"
#include "RTC/IceServer.h"
#include "RTC/STUNMessage.h"
#include "RTC/TransportTuple.h"
#include "RTC/DTLSTransport.h"
#include "Channel/Notifier.h"
#include "Channel/Notifier.h"
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <list>
#include <json/json.h>
#include <json/json.h>
namespace
RTC
namespace
RTC
...
@@ -25,13 +24,6 @@ namespace RTC
...
@@ -25,13 +24,6 @@ namespace RTC
public
RTC
::
IceServer
::
Listener
,
public
RTC
::
IceServer
::
Listener
,
public
RTC
::
DTLSTransport
::
Listener
public
RTC
::
DTLSTransport
::
Listener
{
{
public
:
class
Listener
{
public
:
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
};
public
:
public
:
enum
class
IceComponent
enum
class
IceComponent
{
{
...
@@ -49,8 +41,15 @@ namespace RTC
...
@@ -49,8 +41,15 @@ namespace RTC
FAILED
FAILED
};
};
public
:
class
Listener
{
public
:
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
};
private
:
private
:
static
size_t
max
Sourc
es
;
static
size_t
max
Tupl
es
;
public
:
public
:
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
unsigned
int
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
=
nullptr
);
Transport
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
unsigned
int
transportId
,
Json
::
Value
&
data
,
Transport
*
rtpTransport
=
nullptr
);
...
@@ -66,17 +65,14 @@ namespace RTC
...
@@ -66,17 +65,14 @@ namespace RTC
private
:
private
:
void
Terminate
();
void
Terminate
();
bool
IsAlive
();
bool
IsAlive
();
int
SetSendingSource
(
RTC
::
TransportSource
*
source
);
int
IsValidSource
(
RTC
::
TransportSource
*
source
);
bool
RemoveSource
(
RTC
::
TransportSource
*
source
);
void
MayRunDTLSTransport
();
void
MayRunDTLSTransport
();
/* Private methods to unify UDP and TCP behavior. */
/* Private methods to unify UDP and TCP behavior. */
private
:
private
:
void
onSTUNDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onSTUNDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onDTLSDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onDTLSDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTPDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTPDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTCPDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTCPDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
);
/* Pure virtual methods inherited from RTC::UDPSocket::Listener. */
/* Pure virtual methods inherited from RTC::UDPSocket::Listener. */
public
:
public
:
...
@@ -98,8 +94,10 @@ namespace RTC
...
@@ -98,8 +94,10 @@ namespace RTC
/* Pure virtual methods inherited from RTC::IceServer::Listener. */
/* Pure virtual methods inherited from RTC::IceServer::Listener. */
public
:
public
:
virtual
void
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
override
;
virtual
void
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onICEValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
override
;
virtual
void
onICESelectedTuple
(
IceServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
virtual
void
onICEConnected
(
IceServer
*
iceServer
)
override
;
virtual
void
onICECompleted
(
IceServer
*
iceServer
)
override
;
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public
:
public
:
...
@@ -136,10 +134,7 @@ namespace RTC
...
@@ -136,10 +134,7 @@ namespace RTC
// Others (ICE).
// Others (ICE).
RTC
::
Transport
::
IceComponent
iceComponent
;
RTC
::
Transport
::
IceComponent
iceComponent
;
std
::
vector
<
IceCandidate
>
iceLocalCandidates
;
std
::
vector
<
IceCandidate
>
iceLocalCandidates
;
std
::
list
<
RTC
::
TransportSource
>
sources
;
RTC
::
TransportTuple
*
selectedTuple
=
nullptr
;
RTC
::
TransportSource
*
sendingSource
=
nullptr
;
bool
icePaired
=
false
;
bool
icePairedWithUseCandidate
=
false
;
// Others (DTLS).
// Others (DTLS).
DtlsTransportState
dtlsState
=
DtlsTransportState
::
NEW
;
DtlsTransportState
dtlsState
=
DtlsTransportState
::
NEW
;
bool
remoteDtlsParametersGiven
=
false
;
bool
remoteDtlsParametersGiven
=
false
;
...
@@ -171,139 +166,6 @@ namespace RTC
...
@@ -171,139 +166,6 @@ namespace RTC
{
{
return
this
->
iceServer
->
GetPassword
();
return
this
->
iceServer
->
GetPassword
();
}
}
/**
* Set the given source as a valid one and mark it as the sending source for
* outgoing data.
*
* @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,
* 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
int
Transport
::
SetSendingSource
(
RTC
::
TransportSource
*
source
)
{
// Check whether this is already a valid source.
// NOTE: The IsValidSource() method will also mark it as sending source.
switch
(
IsValidSource
(
source
))
{
// 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
(
this
->
sources
.
size
()
==
Transport
::
maxSources
)
{
RTC
::
TransportSource
*
last_source
=
&
(
*
this
->
sources
.
end
());
last_source
->
Close
();
this
->
sources
.
pop_back
();
}
// Add the new source at the beginning.
this
->
sources
.
push_front
(
*
source
);
// Set it as sending source (make it point to the first source in the list).
this
->
sendingSource
=
&
(
*
this
->
sources
.
begin
());
// If it is UDP then we must store the remote address (until now it is
// just a pointer that will be freed soon).
if
(
this
->
sendingSource
->
IsUDP
())
this
->
sendingSource
->
StoreUdpRemoteAddress
();
return
0
;
}
/**
* Check whether the given source is contained in the list of valid sources for
* this transport. In case it is, the given source is also marked as sending
* source for the outgoing data.
*
* @param source: The RTC::TransportSource to check.
* @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
int
Transport
::
IsValidSource
(
RTC
::
TransportSource
*
source
)
{
// If there is no sending source yet then we know that the sources list
// is empty, so return 0.
if
(
!
this
->
sendingSource
)
return
0
;
// First check the current sending source. If it matches then return 1.
if
(
this
->
sendingSource
->
Compare
(
source
))
return
1
;
// Otherwise check other valid source in the sources list.
for
(
auto
it
=
this
->
sources
.
begin
();
it
!=
this
->
sources
.
end
();
++
it
)
{
RTC
::
TransportSource
*
valid_source
=
&
(
*
it
);
// If found set it as sending source and return 2.
if
(
valid_source
->
Compare
(
source
))
{
this
->
sendingSource
=
valid_source
;
return
2
;
}
}
// Otherwise it is not a valid source so return 0.
return
0
;
}
/**
* Remove the given source from the list of valid sources. Also update the
* sending source if the given source was the sending source and make it point
* to the next valid source (if any).
*
* @param source: The RTC::TransportSource to remove.
* @return: true if the given source was present in the list of valid
* sources, false otherwise.
*/
inline
bool
Transport
::
RemoveSource
(
RTC
::
TransportSource
*
source
)
{
for
(
auto
it
=
this
->
sources
.
begin
();
it
!=
this
->
sources
.
end
();
++
it
)
{
RTC
::
TransportSource
*
valid_source
=
&
(
*
it
);
// If the source was a valid source then remove it.
if
(
valid_source
->
Compare
(
source
))
{
this
->
sources
.
erase
(
it
);
// If it was the sending source then unset it and set the sending
// source to the first valid source (if any).
if
(
this
->
sendingSource
==
valid_source
)
{
if
(
this
->
sources
.
begin
()
!=
this
->
sources
.
end
())
{
this
->
sendingSource
=
&
(
*
this
->
sources
.
begin
());
}
else
{
this
->
sendingSource
=
nullptr
;
// This is just useful is there are just TCP sources.
this
->
icePaired
=
false
;
this
->
icePairedWithUseCandidate
=
false
;
// TODO: This should fire a 'icefailed' event.
}
}
return
true
;
}
}
return
false
;
}
}
}
#endif
#endif
worker/include/RTC/Transport
Sourc
e.h
→
worker/include/RTC/Transport
Tupl
e.h
浏览文件 @
767e7e76
#ifndef MS_RTC_TRANSPORT_
SOURC
E_H
#ifndef MS_RTC_TRANSPORT_
TUPL
E_H
#define MS_RTC_TRANSPORT_
SOURC
E_H
#define MS_RTC_TRANSPORT_
TUPL
E_H
#include "common.h"
#include "common.h"
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPConnection.h"
#include "RTC/TCPConnection.h"
#include "Channel/Request.h"
#include "Utils.h"
#include "Utils.h"
#include <string>
namespace
RTC
namespace
RTC
{
{
class
Transport
Sourc
e
class
Transport
Tupl
e
{
{
public
:
public
:
enum
class
Type
enum
class
Type
...
@@ -20,15 +18,15 @@ namespace RTC
...
@@ -20,15 +18,15 @@ namespace RTC
};
};
public
:
public
:
Transport
Sourc
e
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
Transport
Tupl
e
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
Transport
Sourc
e
(
RTC
::
TCPConnection
*
tcpConnection
);
Transport
Tupl
e
(
RTC
::
TCPConnection
*
tcpConnection
);
void
Close
();
void
Close
();
void
Dump
();
void
Dump
();
void
StoreUdpRemoteAddress
();
void
StoreUdpRemoteAddress
();
bool
IsUDP
();
bool
IsUDP
();
bool
IsTCP
();
bool
IsTCP
();
bool
Compare
(
Transport
Source
*
sourc
e
);
bool
Compare
(
Transport
Tuple
*
tupl
e
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
const
struct
sockaddr
*
GetRemoteAddress
();
const
struct
sockaddr
*
GetRemoteAddress
();
...
@@ -45,27 +43,27 @@ namespace RTC
...
@@ -45,27 +43,27 @@ namespace RTC
/* Inline methods. */
/* Inline methods. */
inline
inline
void
Transport
Sourc
e
::
Close
()
void
Transport
Tupl
e
::
Close
()
{
{
if
(
this
->
type
==
Type
::
TCP
)
if
(
this
->
type
==
Type
::
TCP
)
this
->
tcpConnection
->
Close
();
this
->
tcpConnection
->
Close
();
}
}
inline
inline
Transport
Source
::
TransportSourc
e
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
Transport
Tuple
::
TransportTupl
e
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
udpSocket
(
udpSocket
),
udpSocket
(
udpSocket
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
type
(
Type
::
UDP
)
type
(
Type
::
UDP
)
{}
{}
inline
inline
Transport
Source
::
TransportSourc
e
(
RTC
::
TCPConnection
*
tcpConnection
)
:
Transport
Tuple
::
TransportTupl
e
(
RTC
::
TCPConnection
*
tcpConnection
)
:
tcpConnection
(
tcpConnection
),
tcpConnection
(
tcpConnection
),
type
(
Type
::
TCP
)
type
(
Type
::
TCP
)
{}
{}
inline
inline
void
Transport
Sourc
e
::
StoreUdpRemoteAddress
()
void
Transport
Tupl
e
::
StoreUdpRemoteAddress
()
{
{
// Clone the given address into our address storage and make the sockaddr
// Clone the given address into our address storage and make the sockaddr
// pointer point to it.
// pointer point to it.
...
@@ -74,27 +72,27 @@ namespace RTC
...
@@ -74,27 +72,27 @@ namespace RTC
}
}
inline
inline
bool
Transport
Sourc
e
::
IsUDP
()
bool
Transport
Tupl
e
::
IsUDP
()
{
{
return
(
this
->
type
==
Type
::
UDP
);
return
(
this
->
type
==
Type
::
UDP
);
}
}
inline
inline
bool
Transport
Sourc
e
::
IsTCP
()
bool
Transport
Tupl
e
::
IsTCP
()
{
{
return
(
this
->
type
==
Type
::
TCP
);
return
(
this
->
type
==
Type
::
TCP
);
}
}
inline
inline
bool
Transport
Source
::
Compare
(
TransportSource
*
sourc
e
)
bool
Transport
Tuple
::
Compare
(
TransportTuple
*
tupl
e
)
{
{
if
(
this
->
type
==
Type
::
UDP
&&
sourc
e
->
IsUDP
())
if
(
this
->
type
==
Type
::
UDP
&&
tupl
e
->
IsUDP
())
{
{
return
(
this
->
udpSocket
==
source
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
sourc
e
->
GetRemoteAddress
()));
return
(
this
->
udpSocket
==
tuple
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
tupl
e
->
GetRemoteAddress
()));
}
}
else
if
(
this
->
type
==
Type
::
TCP
&&
sourc
e
->
IsTCP
())
else
if
(
this
->
type
==
Type
::
TCP
&&
tupl
e
->
IsTCP
())
{
{
return
(
this
->
tcpConnection
==
sourc
e
->
tcpConnection
);
return
(
this
->
tcpConnection
==
tupl
e
->
tcpConnection
);
}
}
else
else
{
{
...
@@ -103,7 +101,7 @@ namespace RTC
...
@@ -103,7 +101,7 @@ namespace RTC
}
}
inline
inline
void
Transport
Sourc
e
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
Tupl
e
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
{
{
if
(
this
->
type
==
Type
::
UDP
)
if
(
this
->
type
==
Type
::
UDP
)
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
...
@@ -112,7 +110,7 @@ namespace RTC
...
@@ -112,7 +110,7 @@ namespace RTC
}
}
inline
inline
const
struct
sockaddr
*
Transport
Sourc
e
::
GetRemoteAddress
()
const
struct
sockaddr
*
Transport
Tupl
e
::
GetRemoteAddress
()
{
{
if
(
this
->
type
==
Type
::
UDP
)
if
(
this
->
type
==
Type
::
UDP
)
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
...
...
worker/src/RTC/IceServer.cpp
浏览文件 @
767e7e76
...
@@ -24,7 +24,7 @@ namespace RTC
...
@@ -24,7 +24,7 @@ namespace RTC
delete
this
;
delete
this
;
}
}
void
IceServer
::
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Source
*
sourc
e
)
void
IceServer
::
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Tuple
*
tupl
e
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -38,7 +38,7 @@ namespace RTC
...
@@ -38,7 +38,7 @@ namespace RTC
// Reply 400.
// Reply 400.
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
}
}
else
else
...
@@ -59,7 +59,7 @@ namespace RTC
...
@@ -59,7 +59,7 @@ namespace RTC
// Reply 400.
// Reply 400.
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
}
}
else
else
...
@@ -82,7 +82,7 @@ namespace RTC
...
@@ -82,7 +82,7 @@ namespace RTC
// Reply 400.
// Reply 400.
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
return
;
return
;
...
@@ -101,7 +101,7 @@ namespace RTC
...
@@ -101,7 +101,7 @@ namespace RTC
// Reply 401.
// Reply 401.
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
401
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
401
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
return
;
return
;
...
@@ -114,7 +114,7 @@ namespace RTC
...
@@ -114,7 +114,7 @@ namespace RTC
// Reply 400.
// Reply 400.
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
400
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
return
;
return
;
...
@@ -129,7 +129,7 @@ namespace RTC
...
@@ -129,7 +129,7 @@ namespace RTC
// Reply 487 (Role Conflict).
// Reply 487 (Role Conflict).
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
487
);
RTC
::
STUNMessage
*
response
=
msg
->
CreateErrorResponse
(
487
);
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
return
;
return
;
...
@@ -141,18 +141,18 @@ namespace RTC
...
@@ -141,18 +141,18 @@ namespace RTC
RTC
::
STUNMessage
*
response
=
msg
->
CreateSuccessResponse
();
RTC
::
STUNMessage
*
response
=
msg
->
CreateSuccessResponse
();
// Add XOR-MAPPED-ADDRESS.
// Add XOR-MAPPED-ADDRESS.
response
->
SetXorMappedAddress
(
sourc
e
->
GetRemoteAddress
());
response
->
SetXorMappedAddress
(
tupl
e
->
GetRemoteAddress
());
// Authenticate the response.
// Authenticate the response.
response
->
Authenticate
(
this
->
password
);
response
->
Authenticate
(
this
->
password
);
// Send back.
// Send back.
response
->
Serialize
();
response
->
Serialize
();
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
sourc
e
);
this
->
listener
->
onOutgoingSTUNMessage
(
this
,
response
,
tupl
e
);
delete
response
;
delete
response
;
//
Notify the listener with the valid pair
.
//
Handle the tuple
.
this
->
listener
->
onICEValidPair
(
this
,
sourc
e
,
msg
->
HasUseCandidate
());
HandleTuple
(
tupl
e
,
msg
->
HasUseCandidate
());
break
;
break
;
}
}
...
@@ -160,20 +160,245 @@ namespace RTC
...
@@ -160,20 +160,245 @@ namespace RTC
case
RTC
:
:
STUNMessage
::
Class
::
Indication
:
case
RTC
:
:
STUNMessage
::
Class
::
Indication
:
{
{
MS_DEBUG
(
"STUN Binding Indication processed"
);
MS_DEBUG
(
"STUN Binding Indication processed"
);
break
;
break
;
}
}
case
RTC
:
:
STUNMessage
::
Class
::
SuccessResponse
:
case
RTC
:
:
STUNMessage
::
Class
::
SuccessResponse
:
{
{
MS_DEBUG
(
"STUN Binding Success Response processed"
);
MS_DEBUG
(
"STUN Binding Success Response processed"
);
break
;
break
;
}
}
case
RTC
:
:
STUNMessage
::
Class
::
ErrorResponse
:
case
RTC
:
:
STUNMessage
::
Class
::
ErrorResponse
:
{
{
MS_DEBUG
(
"STUN Binding Error Response processed"
);
MS_DEBUG
(
"STUN Binding Error Response processed"
);
break
;
}
}
}
bool
IceServer
::
IsValidTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
if
(
HasTuple
(
tuple
))
return
true
;
else
return
false
;
}
void
IceServer
::
HandleTuple
(
RTC
::
TransportTuple
*
tuple
,
bool
has_use_candidate
)
{
MS_TRACE
();
switch
(
this
->
state
)
{
case
IceState
:
:
NEW
:
{
// There should be no tuples.
MS_ASSERT
(
this
->
tuples
.
size
()
==
0
,
"state is 'new' but there are %zu tuples"
,
this
->
tuples
.
size
());
// There shouldn't be a selected tuple.
MS_ASSERT
(
this
->
selectedTuple
==
nullptr
,
"state is 'new' but there is selected tuple"
);
if
(
!
has_use_candidate
)
{
MS_DEBUG
(
"transition from state 'new' 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
->
onICESelectedTuple
(
this
,
stored_tuple
);
this
->
listener
->
onICEConnected
(
this
);
}
else
{
MS_DEBUG
(
"transition from state 'new' 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
->
onICESelectedTuple
(
this
,
stored_tuple
);
this
->
listener
->
onICECompleted
(
this
);
}
break
;
}
case
IceState
:
:
CONNECTED
:
{
// There should be some tuples.
MS_ASSERT
(
this
->
tuples
.
size
()
>
0
,
"state is 'connected' but there are no tuples"
);
// There should be a selected tuple.
MS_ASSERT
(
this
->
selectedTuple
!=
nullptr
,
"state is 'connected' but there is not selected tuple"
);
if
(
!
has_use_candidate
)
{
// If a new tuple store it.
if
(
!
HasTuple
(
tuple
))
AddTuple
(
tuple
);
}
else
{
MS_DEBUG
(
"transition from state 'connected' to 'completed'"
);
auto
stored_tuple
=
HasTuple
(
tuple
);
// If a new tuple store it.
if
(
!
stored_tuple
)
stored_tuple
=
AddTuple
(
tuple
);
// Mark it as selected tuple.
SetSelectedTuple
(
stored_tuple
);
// Update state.
this
->
state
=
IceState
::
COMPLETED
;
// Notify the listener.
this
->
listener
->
onICESelectedTuple
(
this
,
stored_tuple
);
this
->
listener
->
onICECompleted
(
this
);
}
break
;
}
case
IceState
:
:
COMPLETED
:
{
// There should be some tuples.
MS_ASSERT
(
this
->
tuples
.
size
()
>
0
,
"state is 'completed' but there are no tuples"
);
// There should be a selected tuple.
MS_ASSERT
(
this
->
selectedTuple
!=
nullptr
,
"state is 'completed' but there is not selected tuple"
);
if
(
!
has_use_candidate
)
{
// If a new tuple store it.
if
(
!
HasTuple
(
tuple
))
AddTuple
(
tuple
);
}
else
{
auto
stored_tuple
=
HasTuple
(
tuple
);
// If a new tuple store it.
if
(
!
stored_tuple
)
stored_tuple
=
AddTuple
(
tuple
);
// Mark it as selected tuple.
SetSelectedTuple
(
stored_tuple
);
// Notify the listener.
this
->
listener
->
onICESelectedTuple
(
this
,
stored_tuple
);
}
break
;
break
;
}
}
}
}
}
}
RTC
::
TransportTuple
*
IceServer
::
AddTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
// Add the new tuple at the beginning of the list.
this
->
tuples
.
push_front
(
*
tuple
);
auto
stored_tuple
=
&
(
*
this
->
tuples
.
begin
());
// If it is UDP then we must store the remote address (until now it is
// just a pointer that will be freed soon).
if
(
stored_tuple
->
IsUDP
())
stored_tuple
->
StoreUdpRemoteAddress
();
// Return the address of the inserted tuple.
return
stored_tuple
;
}
RTC
::
TransportTuple
*
IceServer
::
HasTuple
(
RTC
::
TransportTuple
*
tuple
)
{
MS_TRACE
();
// If there is no selected tuple yet then we know that the tuples list
// is empty.
if
(
!
this
->
selectedTuple
)
return
nullptr
;
// Check the current selected tuple.
if
(
this
->
selectedTuple
->
Compare
(
tuple
))
return
this
->
selectedTuple
;
// Otherwise check other stored tuples.
for
(
auto
it
=
this
->
tuples
.
begin
();
it
!=
this
->
tuples
.
end
();
++
it
)
{
RTC
::
TransportTuple
*
stored_tuple
=
&
(
*
it
);
if
(
stored_tuple
->
Compare
(
tuple
))
return
stored_tuple
;
}
return
nullptr
;
}
void
IceServer
::
SetSelectedTuple
(
RTC
::
TransportTuple
*
stored_tuple
)
{
MS_TRACE
();
this
->
selectedTuple
=
stored_tuple
;
}
// 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/Transport.cpp
浏览文件 @
767e7e76
...
@@ -28,7 +28,7 @@ namespace RTC
...
@@ -28,7 +28,7 @@ namespace RTC
{
{
/* Class variables. */
/* Class variables. */
size_t
Transport
::
max
Sourc
es
=
8
;
size_t
Transport
::
max
Tupl
es
=
8
;
/* Instance methods. */
/* Instance methods. */
...
@@ -513,10 +513,11 @@ namespace RTC
...
@@ -513,10 +513,11 @@ namespace RTC
// Check our local DTLS role.
// Check our local DTLS role.
switch
(
this
->
dtlsLocalRole
)
switch
(
this
->
dtlsLocalRole
)
{
{
// If still 'auto' then transition to 'server' if ICE is
complete (with
or
// If still 'auto' then transition to 'server' if ICE is
'connected'
or
//
without UseCandidate)
.
//
'completed'
.
case
RTC
:
:
DTLSTransport
::
Role
::
AUTO
:
case
RTC
:
:
DTLSTransport
::
Role
::
AUTO
:
if
(
this
->
icePaired
)
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
IceServer
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
IceServer
::
IceState
::
COMPLETED
)
{
{
MS_DEBUG
(
"transition from local 'auto' role to 'server' and running DTLS transport"
);
MS_DEBUG
(
"transition from local 'auto' role to 'server' and running DTLS transport"
);
...
@@ -527,9 +528,9 @@ namespace RTC
...
@@ -527,9 +528,9 @@ namespace RTC
// 'client' is only set if a 'setRemoteDtlsParameters' request was previously
// 'client' is only set if a 'setRemoteDtlsParameters' request was previously
// received with remote DTLS role 'server'.
// received with remote DTLS role 'server'.
// If 'client' then wait for
the first Binding with USE-CANDIDATE
.
// If 'client' then wait for
ICE to be 'completed'
.
case
RTC
:
:
DTLSTransport
::
Role
::
CLIENT
:
case
RTC
:
:
DTLSTransport
::
Role
::
CLIENT
:
if
(
this
->
ice
PairedWithUseCandidate
)
if
(
this
->
ice
Server
->
GetState
()
==
RTC
::
IceServer
::
IceState
::
COMPLETED
)
{
{
MS_DEBUG
(
"running DTLS transport in 'client' role"
);
MS_DEBUG
(
"running DTLS transport in 'client' role"
);
...
@@ -537,9 +538,11 @@ namespace RTC
...
@@ -537,9 +538,11 @@ namespace RTC
}
}
break
;
break
;
// If 'server' then run the DTLS handler upon first valid ICE pair.
// If 'server' then run the DTLS handler if ICE is 'connected' or
// 'completed'.
case
RTC
:
:
DTLSTransport
::
Role
::
SERVER
:
case
RTC
:
:
DTLSTransport
::
Role
::
SERVER
:
if
(
this
->
icePaired
)
if
(
this
->
iceServer
->
GetState
()
==
RTC
::
IceServer
::
IceState
::
CONNECTED
||
this
->
iceServer
->
GetState
()
==
RTC
::
IceServer
::
IceState
::
COMPLETED
)
{
{
MS_DEBUG
(
"running DTLS transport in 'server' role"
);
MS_DEBUG
(
"running DTLS transport in 'server' role"
);
...
@@ -553,7 +556,7 @@ namespace RTC
...
@@ -553,7 +556,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onSTUNDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onSTUNDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -566,19 +569,19 @@ namespace RTC
...
@@ -566,19 +569,19 @@ namespace RTC
}
}
// Pass it to the IceServer.
// Pass it to the IceServer.
this
->
iceServer
->
ProcessSTUNMessage
(
msg
,
sourc
e
);
this
->
iceServer
->
ProcessSTUNMessage
(
msg
,
tupl
e
);
delete
msg
;
delete
msg
;
}
}
inline
inline
void
Transport
::
onDTLSDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onDTLSDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
if
(
!
IsValidSource
(
sourc
e
))
if
(
!
this
->
iceServer
->
IsValidTuple
(
tupl
e
))
{
{
MS_DEBUG
(
"ignoring DTLS data coming from an invalid
sourc
e"
);
MS_DEBUG
(
"ignoring DTLS data coming from an invalid
tupl
e"
);
return
;
return
;
}
}
...
@@ -600,7 +603,7 @@ namespace RTC
...
@@ -600,7 +603,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onRTPDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTPDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -608,7 +611,7 @@ namespace RTC
...
@@ -608,7 +611,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onRTCPDataRecv
(
RTC
::
Transport
Source
*
sourc
e
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTCPDataRecv
(
RTC
::
Transport
Tuple
*
tupl
e
,
const
MS_BYTE
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -622,8 +625,8 @@ namespace RTC
...
@@ -622,8 +625,8 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
socket
,
remote_addr
);
RTC
::
Transport
Tuple
tupl
e
(
socket
,
remote_addr
);
onSTUNDataRecv
(
&
sourc
e
,
data
,
len
);
onSTUNDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
void
Transport
::
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
...
@@ -633,8 +636,8 @@ namespace RTC
...
@@ -633,8 +636,8 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
socket
,
remote_addr
);
RTC
::
Transport
Tuple
tupl
e
(
socket
,
remote_addr
);
onDTLSDataRecv
(
&
sourc
e
,
data
,
len
);
onDTLSDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
void
Transport
::
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
...
@@ -644,8 +647,8 @@ namespace RTC
...
@@ -644,8 +647,8 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
socket
,
remote_addr
);
RTC
::
Transport
Tuple
tupl
e
(
socket
,
remote_addr
);
onRTPDataRecv
(
&
sourc
e
,
data
,
len
);
onRTPDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
void
Transport
::
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
...
@@ -655,8 +658,8 @@ namespace RTC
...
@@ -655,8 +658,8 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
socket
,
remote_addr
);
RTC
::
Transport
Tuple
tupl
e
(
socket
,
remote_addr
);
onRTCPDataRecv
(
&
sourc
e
,
data
,
len
);
onRTCPDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
void
Transport
::
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
...
@@ -666,12 +669,14 @@ namespace RTC
...
@@ -666,12 +669,14 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
TransportSource
source
(
connection
);
// TODO
if
(
RemoveSource
(
&
source
))
// RTC::TransportTuple tuple(connection);
{
MS_DEBUG
(
"valid source %s:"
,
is_closed_by_peer
?
"closed by peer"
:
"locally closed"
);
// if (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
)
...
@@ -681,8 +686,8 @@ namespace RTC
...
@@ -681,8 +686,8 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
connection
);
RTC
::
Transport
Tuple
tupl
e
(
connection
);
onSTUNDataRecv
(
&
sourc
e
,
data
,
len
);
onSTUNDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
...
@@ -692,16 +697,16 @@ namespace RTC
...
@@ -692,16 +697,16 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
connection
);
RTC
::
Transport
Tuple
tupl
e
(
connection
);
onDTLSDataRecv
(
&
sourc
e
,
data
,
len
);
onDTLSDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
RTC
::
Transport
Source
sourc
e
(
connection
);
RTC
::
Transport
Tuple
tupl
e
(
connection
);
onRTPDataRecv
(
&
sourc
e
,
data
,
len
);
onRTPDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
...
@@ -711,28 +716,30 @@ namespace RTC
...
@@ -711,28 +716,30 @@ namespace RTC
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
RTC
::
Transport
Source
sourc
e
(
connection
);
RTC
::
Transport
Tuple
tupl
e
(
connection
);
onRTCPDataRecv
(
&
sourc
e
,
data
,
len
);
onRTCPDataRecv
(
&
tupl
e
,
data
,
len
);
}
}
void
Transport
::
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Source
*
sourc
e
)
void
Transport
::
onOutgoingSTUNMessage
(
RTC
::
IceServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
Transport
Tuple
*
tupl
e
)
{
{
MS_TRACE
();
MS_TRACE
();
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
// Send the STUN response over the same transport
sourc
e.
// Send the STUN response over the same transport
tupl
e.
sourc
e
->
Send
(
msg
->
GetRaw
(),
msg
->
GetLength
());
tupl
e
->
Send
(
msg
->
GetRaw
(),
msg
->
GetLength
());
}
}
void
Transport
::
onICE
ValidPair
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidat
e
)
void
Transport
::
onICE
SelectedTuple
(
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportTuple
*
tupl
e
)
{
{
MS_TRACE
();
MS_TRACE
();
if
(
!
IsAlive
())
if
(
!
IsAlive
())
return
;
return
;
this
->
selectedTuple
=
tuple
;
/*
/*
* RFC 5245 section 11.2 "Receiving Media":
* RFC 5245 section 11.2 "Receiving Media":
*
*
...
@@ -740,29 +747,22 @@ namespace RTC
...
@@ -740,29 +747,22 @@ namespace RTC
* on any candidates provided for that component.
* on any candidates provided for that component.
*/
*/
this
->
icePaired
=
true
;
// If ready, run the DTLS handler.
if
(
has_use_candidate
)
MayRunDTLSTransport
();
this
->
icePairedWithUseCandidate
=
true
;
}
switch
(
SetSendingSource
(
source
))
void
Transport
::
onICEConnected
(
RTC
::
IceServer
*
iceServer
)
{
{
// This is a new source.
MS_TRACE
();
case
0
:
MS_DEBUG
(
"got a new ICE valid pair [UseCandidate:%s]"
,
has_use_candidate
?
"true"
:
"false"
);
break
;
// This is already the sending source.
MS_DEBUG
(
"ICE connected"
);
case
1
:
}
break
;
// This is another valid source.
void
Transport
::
onICECompleted
(
RTC
::
IceServer
*
iceServer
)
case
2
:
{
MS_DEBUG
(
"got a previous ICE valid pair [UseCandidate:%s]"
,
has_use_candidate
?
"true"
:
"false"
);
MS_TRACE
();
break
;
}
// If ready, run the DTLS handler.
MS_DEBUG
(
"ICE completed"
);
MayRunDTLSTransport
();
}
}
void
Transport
::
onDTLSConnecting
(
RTC
::
DTLSTransport
*
dtlsTransport
)
void
Transport
::
onDTLSConnecting
(
RTC
::
DTLSTransport
*
dtlsTransport
)
...
@@ -880,17 +880,17 @@ namespace RTC
...
@@ -880,17 +880,17 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
if
(
!
this
->
se
ndingSourc
e
)
if
(
!
this
->
se
lectedTupl
e
)
{
{
MS_DEBUG
(
"no
sending
address set, cannot send DTLS packet"
);
MS_DEBUG
(
"no
media
address set, cannot send DTLS packet"
);
return
;
return
;
}
}
// TODO: remove
// TODO: remove
MS_DEBUG
(
"
sending
DTLS data to to:"
);
MS_DEBUG
(
"
media
DTLS data to to:"
);
this
->
se
ndingSourc
e
->
Dump
();
this
->
se
lectedTupl
e
->
Dump
();
this
->
se
ndingSourc
e
->
Send
(
data
,
len
);
this
->
se
lectedTupl
e
->
Send
(
data
,
len
);
}
}
void
Transport
::
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
...
...
worker/src/RTC/Transport
Sourc
e.cpp
→
worker/src/RTC/Transport
Tupl
e.cpp
浏览文件 @
767e7e76
#define MS_CLASS "RTC::Transport
Sourc
e"
#define MS_CLASS "RTC::Transport
Tupl
e"
#include "RTC/Transport
Sourc
e.h"
#include "RTC/Transport
Tupl
e.h"
#include "Logger.h"
#include "Logger.h"
#include <string>
namespace
RTC
namespace
RTC
{
{
/* Instance methods. */
/* Instance methods. */
void
Transport
Sourc
e
::
Dump
()
void
Transport
Tupl
e
::
Dump
()
{
{
MS_TRACE
();
MS_TRACE
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论