Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
6262224c
提交
6262224c
authored
11月 22, 2015
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New C++ style.
上级
9fbdf500
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
95 个修改的文件
包含
1199 行增加
和
1309 行删除
+1199
-1309
Message.h
include/ControlProtocol/Message.h
+44
-48
Parser.h
include/ControlProtocol/Parser.h
+54
-59
Request.h
include/ControlProtocol/Request.h
+21
-25
TCPConnection.h
include/ControlProtocol/TCPConnection.h
+23
-27
TCPServer.h
include/ControlProtocol/TCPServer.h
+23
-27
UnixStreamSocket.h
include/ControlProtocol/UnixStreamSocket.h
+25
-29
messages.h
include/ControlProtocol/messages.h
+0
-2
RequestAuthenticate.h
include/ControlProtocol/messages/RequestAuthenticate.h
+14
-19
RequestCreateConference.h
include/ControlProtocol/messages/RequestCreateConference.h
+9
-14
RequestHello.h
include/ControlProtocol/messages/RequestHello.h
+9
-14
Daemon.h
include/Daemon.h
+2
-3
Dispatcher.h
include/Dispatcher.h
+0
-3
LibSRTP.h
include/LibSRTP.h
+6
-8
LibUV.h
include/LibUV.h
+4
-6
Logger.h
include/Logger.h
+66
-42
MediaSoup.h
include/MediaSoup.h
+2
-3
MediaSoupError.h
include/MediaSoupError.h
+7
-10
OpenSSL.h
include/OpenSSL.h
+4
-6
DTLSHandler.h
include/RTC/DTLSHandler.h
+120
-125
DTLSRole.h
include/RTC/DTLSRole.h
+6
-11
FingerprintHash.h
include/RTC/FingerprintHash.h
+11
-15
ICEServer.h
include/RTC/ICEServer.h
+56
-60
Peer.h
include/RTC/Peer.h
+40
-48
RTCPPacket.h
include/RTC/RTCPPacket.h
+72
-76
RTPPacket.h
include/RTC/RTPPacket.h
+192
-195
Room.h
include/RTC/Room.h
+19
-26
SRTPProfile.h
include/RTC/SRTPProfile.h
+8
-12
SRTPSession.h
include/RTC/SRTPSession.h
+45
-49
STUNMessage.h
include/RTC/STUNMessage.h
+0
-0
Stream.h
include/RTC/Stream.h
+12
-17
TCPConnection.h
include/RTC/TCPConnection.h
+25
-29
TCPServer.h
include/RTC/TCPServer.h
+47
-51
Transport.h
include/RTC/Transport.h
+0
-0
TransportSource.h
include/RTC/TransportSource.h
+102
-105
UDPSocket.h
include/RTC/UDPSocket.h
+45
-49
Settings.h
include/Settings.h
+12
-9
Utils.h
include/Utils.h
+0
-0
Version.h
include/Version.h
+2
-4
Worker.h
include/Worker.h
+0
-3
common.h
include/common.h
+0
-3
SignalsHandler.h
include/handles/SignalsHandler.h
+4
-5
TCPConnection.h
include/handles/TCPConnection.h
+24
-24
TCPServer.h
include/handles/TCPServer.h
+10
-12
Timer.h
include/handles/Timer.h
+4
-5
UDPSocket.h
include/handles/UDPSocket.h
+18
-19
UnixStreamSocket.h
include/handles/UnixStreamSocket.h
+10
-11
Message.cpp
src/ControlProtocol/Message.cpp
+0
-0
Parser.cpp
src/ControlProtocol/Parser.cpp
+0
-0
Parser.rl
src/ControlProtocol/Parser.rl
+0
-0
Request.cpp
src/ControlProtocol/Request.cpp
+0
-0
TCPConnection.cpp
src/ControlProtocol/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/ControlProtocol/TCPServer.cpp
+0
-0
UnixStreamSocket.cpp
src/ControlProtocol/UnixStreamSocket.cpp
+0
-0
RequestAuthenticate.rl
src/ControlProtocol/grammar/RequestAuthenticate.rl
+0
-0
RequestCreateConference.rl
src/ControlProtocol/grammar/RequestCreateConference.rl
+2
-1
RequestHello.rl
src/ControlProtocol/grammar/RequestHello.rl
+0
-0
RequestAuthenticate.cpp
src/ControlProtocol/messages/RequestAuthenticate.cpp
+0
-0
RequestCreateConference.cpp
src/ControlProtocol/messages/RequestCreateConference.cpp
+0
-0
RequestHello.cpp
src/ControlProtocol/messages/RequestHello.cpp
+0
-0
Daemon.cpp
src/Daemon.cpp
+0
-0
Dispatcher.cpp
src/Dispatcher.cpp
+0
-0
LibSRTP.cpp
src/LibSRTP.cpp
+0
-0
LibUV.cpp
src/LibUV.cpp
+0
-0
Logger.cpp
src/Logger.cpp
+0
-0
MediaSoup.cpp
src/MediaSoup.cpp
+0
-0
OpenSSL.cpp
src/OpenSSL.cpp
+0
-0
DTLSHandler.cpp
src/RTC/DTLSHandler.cpp
+0
-0
ICEServer.cpp
src/RTC/ICEServer.cpp
+0
-0
Peer.cpp
src/RTC/Peer.cpp
+0
-0
RTCPPacket.cpp
src/RTC/RTCPPacket.cpp
+0
-0
RTPPacket.cpp
src/RTC/RTPPacket.cpp
+0
-0
Room.cpp
src/RTC/Room.cpp
+0
-0
SRTPSession.cpp
src/RTC/SRTPSession.cpp
+0
-0
STUNMessage.cpp
src/RTC/STUNMessage.cpp
+0
-0
Stream.cpp
src/RTC/Stream.cpp
+0
-0
TCPConnection.cpp
src/RTC/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/RTC/TCPServer.cpp
+0
-0
Transport.cpp
src/RTC/Transport.cpp
+0
-0
TransportSource.cpp
src/RTC/TransportSource.cpp
+0
-0
UDPSocket.cpp
src/RTC/UDPSocket.cpp
+0
-0
Settings.cpp
src/Settings.cpp
+0
-0
Crypto.cpp
src/Utils/Crypto.cpp
+0
-0
File.cpp
src/Utils/File.cpp
+0
-0
IP.cpp
src/Utils/IP.cpp
+0
-0
IP.rl
src/Utils/IP.rl
+0
-0
Socket.cpp
src/Utils/Socket.cpp
+0
-0
Version.cpp
src/Version.cpp
+0
-0
Worker.cpp
src/Worker.cpp
+0
-0
SignalsHandler.cpp
src/handles/SignalsHandler.cpp
+0
-0
TCPConnection.cpp
src/handles/TCPConnection.cpp
+0
-0
TCPServer.cpp
src/handles/TCPServer.cpp
+0
-0
Timer.cpp
src/handles/Timer.cpp
+0
-0
UDPSocket.cpp
src/handles/UDPSocket.cpp
+0
-0
UnixStreamSocket.cpp
src/handles/UnixStreamSocket.cpp
+0
-0
main.cpp
src/main.cpp
+0
-0
没有找到文件。
include/ControlProtocol/Message.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_MESSAGE_H
#ifndef MS_CONTROL_PROTOCOL_MESSAGE_H
#define MS_CONTROL_PROTOCOL_MESSAGE_H
#define MS_CONTROL_PROTOCOL_MESSAGE_H
#include "common.h"
#include "common.h"
namespace
ControlProtocol
namespace
ControlProtocol
{
{
class
Message
{
class
Message
{
public
:
public
:
enum
class
Kind
enum
class
Kind
{
{
Request
=
1
,
Request
=
1
,
Response
,
Response
,
Notification
Notification
};
public
:
Message
(
Kind
);
virtual
~
Message
();
Kind
GetKind
();
virtual
bool
IsValid
();
// TODO: Must be pure virtual.
void
SetTransaction
(
int32_t
transaction
);
int32_t
GetTransaction
();
virtual
void
Dump
()
=
0
;
protected
:
Kind
kind
;
int32_t
transaction
=
0
;
};
};
public
:
/* Inlime methods. */
Message
(
Kind
);
virtual
~
Message
();
inline
Message
::
Kind
Message
::
GetKind
()
Kind
GetKind
();
{
virtual
bool
IsValid
();
// TODO: Must be pure virtual.
return
this
->
kind
;
void
SetTransaction
(
int32_t
transaction
);
}
int32_t
GetTransaction
();
virtual
void
Dump
()
=
0
;
inline
void
Message
::
SetTransaction
(
int32_t
transaction
)
protected
:
{
Kind
kind
;
this
->
transaction
=
transaction
;
int32_t
transaction
=
0
;
}
};
inline
int32_t
Message
::
GetTransaction
()
/* Inlime methods. */
{
return
this
->
transaction
;
inline
}
Message
::
Kind
Message
::
GetKind
()
{
return
this
->
kind
;
}
inline
void
Message
::
SetTransaction
(
int32_t
transaction
)
{
this
->
transaction
=
transaction
;
}
inline
int32_t
Message
::
GetTransaction
()
{
return
this
->
transaction
;
}
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/Parser.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_PARSER_H
#ifndef MS_CONTROL_PROTOCOL_PARSER_H
#define MS_CONTROL_PROTOCOL_PARSER_H
#define MS_CONTROL_PROTOCOL_PARSER_H
#include "common.h"
#include "common.h"
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
namespace
ControlProtocol
{
{
class
Parser
{
class
Parser
{
public
:
public
:
Parser
();
Parser
();
virtual
~
Parser
();
virtual
~
Parser
();
/**
/**
* Parses the given buffer.
* Parses the given buffer.
*
*
* @param buffer The buffer to parse.
* @param buffer The buffer to parse.
* @param len The lenght of the buffer.
* @param len The lenght of the buffer.
*
*
* @return Returns a pointer to ControlProtocol::Message if parsing succeded,
* @return Returns a pointer to ControlProtocol::Message if parsing succeded,
* or nullptr if the message is not completed or parsing failed.
* or nullptr if the message is not completed or parsing failed.
*/
*/
Message
*
Parse
(
const
MS_BYTE
*
buffer
,
size_t
len
);
Message
*
Parse
(
const
MS_BYTE
*
buffer
,
size_t
len
);
/**
/**
* Checks whether the ongoing parsing has error or not.
* Checks whether the ongoing parsing has error or not.
*
*
* @return true if there is parsing error, false otherwise.
* @return true if there is parsing error, false otherwise.
*/
*/
bool
HasError
();
bool
HasError
();
/**
/**
* Get the length of the complete or uncomplete message parsed or being parsed.
* Get the length of the complete or uncomplete message parsed or being parsed.
*
*
* @return The number of chars parsed in the current message.
* @return The number of chars parsed in the current message.
*/
*/
size_t
GetParsedLen
();
size_t
GetParsedLen
();
/**
/**
* Resets the parser internals. Must be called before parsing a new message
* Resets the parser internals. Must be called before parsing a new message
* (regardless the previous one succeded or not).
* (regardless the previous one succeded or not).
*/
*/
void
Reset
();
void
Reset
();
/**
/**
* Prints current status of the parser.
* Prints current status of the parser.
*/
*/
void
Dump
();
void
Dump
();
protected
:
protected
:
size_t
parsedLen
;
size_t
parsedLen
;
private
:
private
:
// Allocated by this:
// Allocated by this:
ControlProtocol
::
Message
*
msg
=
nullptr
;
ControlProtocol
::
Message
*
msg
=
nullptr
;
// Others:
// Others:
size_t
cs
=
0
;
// Needed for Ragel.
size_t
cs
=
0
;
// Needed for Ragel.
size_t
mark
=
0
;
size_t
mark
=
0
;
};
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/Request.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_H
#ifndef MS_CONTROL_PROTOCOL_REQUEST_H
#define MS_CONTROL_PROTOCOL_REQUEST_H
#define MS_CONTROL_PROTOCOL_REQUEST_H
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
namespace
ControlProtocol
{
{
class
Request
:
public
ControlProtocol
::
Message
{
class
Request
:
public
ControlProtocol
::
Message
{
public
:
public
:
enum
class
Type
enum
class
Type
{
{
Hello
=
1
,
Hello
=
1
,
Authenticate
,
Authenticate
,
CreateConference
CreateConference
};
public
:
Request
(
Type
);
virtual
~
Request
();
virtual
void
Dump
()
=
0
;
public
:
// Allow fast access to type.
Type
type
;
};
};
public
:
Request
(
Type
);
virtual
~
Request
();
virtual
void
Dump
()
=
0
;
public
:
// Allow fast access to type.
Type
type
;
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#ifndef MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#define MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#define MS_CONTROL_PROTOCOL_TCP_CONNECTION_H
#include "common.h"
#include "common.h"
#include "handles/TCPConnection.h"
#include "handles/TCPConnection.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
TCPConnection
:
public
::
TCPConnection
{
public
:
class
Reader
{
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
TCPConnection
*
connection
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
};
namespace
ControlProtocol
{
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
class
TCPConnection
:
public
::
TCPConnection
{
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
class
Reader
{
public
:
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
TCPConnection
*
connection
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
};
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_TCP_SERVER_H
#ifndef MS_CONTROL_PROTOCOL_TCP_SERVER_H
#define MS_CONTROL_PROTOCOL_TCP_SERVER_H
#define MS_CONTROL_PROTOCOL_TCP_SERVER_H
#include "common.h"
#include "common.h"
#include "handles/TCPServer.h"
#include "handles/TCPServer.h"
#include "handles/TCPConnection.h"
#include "handles/TCPConnection.h"
...
@@ -9,36 +8,33 @@
...
@@ -9,36 +8,33 @@
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
#include <string>
#include <string>
namespace
ControlProtocol
{
class
TCPServer
:
public
::
TCPServer
{
public
:
class
Listener
{
public
:
virtual
void
onControlProtocolNewTCPConnection
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
)
=
0
;
virtual
void
onControlProtocolTCPConnectionClosed
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
namespace
ControlProtocol
{
public
:
TCPServer
(
Listener
*
listener
,
ControlProtocol
::
TCPConnection
::
Reader
*
reader
,
const
std
::
string
&
ip
,
MS_PORT
port
);
class
TCPServer
:
public
::
TCPServer
{
/* Pure virtual methods inherited from ::TCPServer. */
public
:
class
Listener
{
public
:
public
:
virtual
void
onControlProtocolNewTCPConnection
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
)
=
0
;
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
onControlProtocolTCPConnectionClosed
(
ControlProtocol
::
TCPServer
*
tcpServer
,
ControlProtocol
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
ControlProtocol
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
};
public
:
TCPServer
(
Listener
*
listener
,
ControlProtocol
::
TCPConnection
::
Reader
*
reader
,
const
std
::
string
&
ip
,
MS_PORT
port
);
/* Pure virtual methods inherited from ::TCPServer. */
public
:
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
ControlProtocol
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/UnixStreamSocket.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#ifndef MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#define MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#define MS_CONTROL_PROTOCOL_UNIX_STREAM_SOCKET_H
#include "common.h"
#include "common.h"
#include "handles/UnixStreamSocket.h"
#include "handles/UnixStreamSocket.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Parser.h"
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
namespace
ControlProtocol
{
class
UnixStreamSocket
:
public
::
UnixStreamSocket
{
public
:
class
Listener
{
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
onControlProtocolUnixStreamSocketClosed
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
bool
is_closed_by_peer
)
=
0
;
};
namespace
ControlProtocol
{
public
:
UnixStreamSocket
(
Listener
*
listener
,
int
fd
);
virtual
~
UnixStreamSocket
();
class
UnixStreamSocket
:
public
::
UnixStreamSocket
{
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public
:
class
Listener
{
public
:
public
:
virtual
void
onControlProtocolMessage
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
ControlProtocol
::
Message
*
msg
,
const
MS_BYTE
*
raw
,
size_t
len
)
=
0
;
virtual
void
userOnUnixStreamRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onControlProtocolUnixStreamSocketClosed
(
ControlProtocol
::
UnixStreamSocket
*
unixSocket
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
};
public
:
UnixStreamSocket
(
Listener
*
listener
,
int
fd
);
virtual
~
UnixStreamSocket
();
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public
:
virtual
void
userOnUnixStreamRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
userOnUnixStreamSocketClosed
(
bool
is_closed_by_peer
)
override
;
private
:
// Allocated by this:
ControlProtocol
::
Parser
*
parser
=
nullptr
;
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Others:
size_t
msgStart
=
0
;
// Where the latest message starts.
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/messages.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_MESSAGES_H
#ifndef MS_CONTROL_PROTOCOL_MESSAGES_H
#define MS_CONTROL_PROTOCOL_MESSAGES_H
#define MS_CONTROL_PROTOCOL_MESSAGES_H
#include "messages/RequestHello.h"
#include "messages/RequestHello.h"
#include "messages/RequestAuthenticate.h"
#include "messages/RequestAuthenticate.h"
#include "messages/RequestCreateConference.h"
#include "messages/RequestCreateConference.h"
#endif
#endif
include/ControlProtocol/messages/RequestAuthenticate.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#ifndef MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#define MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#define MS_CONTROL_PROTOCOL_REQUEST_AUTHENTICATE_H
#include "ControlProtocol/Request.h"
#include "ControlProtocol/Request.h"
#include <string>
#include <string>
namespace
ControlProtocol
{
class
RequestAuthenticate
:
public
ControlProtocol
::
Request
{
public
:
RequestAuthenticate
();
virtual
~
RequestAuthenticate
();
namespace
ControlProtocol
{
void
SetUser
(
const
char
*
str
,
size_t
len
);
void
SetPasswd
(
const
char
*
str
,
size_t
len
);
class
RequestAuthenticate
:
public
ControlProtocol
::
Request
{
public
:
RequestAuthenticate
();
virtual
~
RequestAuthenticate
();
void
SetUser
(
const
char
*
str
,
size_t
len
);
void
SetPasswd
(
const
char
*
str
,
size_t
len
);
virtual
void
Dump
()
override
;
private
:
std
::
string
user
;
std
::
string
passwd
;
};
virtual
void
Dump
()
override
;
private
:
std
::
string
user
;
std
::
string
passwd
;
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/messages/RequestCreateConference.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#ifndef MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#define MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#define MS_CONTROL_PROTOCOL_REQUEST_CREATE_CONFERENCE_H
#include "ControlProtocol/Request.h"
#include "ControlProtocol/Request.h"
namespace
ControlProtocol
{
class
RequestCreateConference
:
public
ControlProtocol
::
Request
{
public
:
RequestCreateConference
();
virtual
~
RequestCreateConference
();
namespace
ControlProtocol
{
virtual
void
Dump
()
override
;
};
class
RequestCreateConference
:
public
ControlProtocol
::
Request
{
public
:
RequestCreateConference
();
virtual
~
RequestCreateConference
();
virtual
void
Dump
()
override
;
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/ControlProtocol/messages/RequestHello.h
浏览文件 @
6262224c
#ifndef MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#ifndef MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#define MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#define MS_CONTROL_PROTOCOL_REQUEST_HELLO_H
#include "ControlProtocol/Request.h"
#include "ControlProtocol/Request.h"
namespace
ControlProtocol
{
class
RequestHello
:
public
ControlProtocol
::
Request
{
public
:
RequestHello
();
virtual
~
RequestHello
();
namespace
ControlProtocol
{
virtual
void
Dump
()
override
;
};
class
RequestHello
:
public
ControlProtocol
::
Request
{
public
:
RequestHello
();
virtual
~
RequestHello
();
virtual
void
Dump
()
override
;
};
}
// namespace ControlProtocol
}
// namespace ControlProtocol
#endif
#endif
include/Daemon.h
浏览文件 @
6262224c
#ifndef MS_DAEMON_H
#ifndef MS_DAEMON_H
#define MS_DAEMON_H
#define MS_DAEMON_H
class
Daemon
class
Daemon
{
{
public
:
public
:
static
void
Daemonize
();
static
void
Daemonize
();
static
void
SendOKStatusToAncestor
();
static
void
SendOKStatusToAncestor
();
...
@@ -22,5 +22,4 @@ private:
...
@@ -22,5 +22,4 @@ private:
static
bool
hasWrittenPIDFile
;
static
bool
hasWrittenPIDFile
;
};
};
#endif
#endif
include/Dispatcher.h
浏览文件 @
6262224c
#ifndef MS_DISPATCHER_H
#ifndef MS_DISPATCHER_H
#define MS_DISPATCHER_H
#define MS_DISPATCHER_H
#include "common.h"
#include "common.h"
#include "handles/SignalsHandler.h"
#include "handles/SignalsHandler.h"
#include "ControlProtocol/TCPServer.h"
#include "ControlProtocol/TCPServer.h"
...
@@ -10,7 +9,6 @@
...
@@ -10,7 +9,6 @@
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
#include <vector>
#include <vector>
class
Dispatcher
:
class
Dispatcher
:
public
SignalsHandler
::
Listener
,
public
SignalsHandler
::
Listener
,
public
ControlProtocol
::
TCPServer
::
Listener
,
public
ControlProtocol
::
TCPServer
::
Listener
,
...
@@ -52,5 +50,4 @@ private:
...
@@ -52,5 +50,4 @@ private:
bool
closed
=
false
;
bool
closed
=
false
;
};
};
#endif
#endif
include/LibSRTP.h
浏览文件 @
6262224c
#ifndef MS_LIBSRTP_H
#ifndef MS_LIBSRTP_H
#define MS_LIBSRTP_H
#define MS_LIBSRTP_H
#include <vector>
#include <vector>
#include <srtp/srtp.h>
#include <srtp/srtp.h>
class
LibSRTP
class
LibSRTP
{
{
public
:
public
:
static
void
ClassInit
();
static
void
ClassInit
();
static
void
ClassDestroy
();
static
void
ClassDestroy
();
...
@@ -17,20 +16,19 @@ private:
...
@@ -17,20 +16,19 @@ private:
static
std
::
vector
<
const
char
*>
errors
;
static
std
::
vector
<
const
char
*>
errors
;
};
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
bool
LibSRTP
::
IsError
(
err_status_t
code
)
{
bool
LibSRTP
::
IsError
(
err_status_t
code
)
{
return
(
code
!=
err_status_ok
);
return
(
code
!=
err_status_ok
);
}
}
inline
inline
const
char
*
LibSRTP
::
GetErrorString
(
err_status_t
code
)
{
const
char
*
LibSRTP
::
GetErrorString
(
err_status_t
code
)
{
// This throws out_of_range if the given index is not in the vector.
// This throws out_of_range if the given index is not in the vector.
return
LibSRTP
::
errors
.
at
(
code
);
return
LibSRTP
::
errors
.
at
(
code
);
}
}
#endif
#endif
include/LibUV.h
浏览文件 @
6262224c
#ifndef MS_LIBUV_H
#ifndef MS_LIBUV_H
#define MS_LIBUV_H
#define MS_LIBUV_H
#include "common.h"
#include "common.h"
#include <uv.h>
#include <uv.h>
class
LibUV
class
LibUV
{
{
public
:
public
:
static
void
ClassInit
();
static
void
ClassInit
();
static
void
ThreadInit
();
static
void
ThreadInit
();
...
@@ -18,13 +17,12 @@ private:
...
@@ -18,13 +17,12 @@ private:
static
__thread
uv_loop_t
*
loop
;
static
__thread
uv_loop_t
*
loop
;
};
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
uv_loop_t
*
LibUV
::
GetLoop
()
{
uv_loop_t
*
LibUV
::
GetLoop
()
{
return
LibUV
::
loop
;
return
LibUV
::
loop
;
}
}
#endif
#endif
include/Logger.h
浏览文件 @
6262224c
#ifndef MS_LOGGER_H
#ifndef MS_LOGGER_H
#define MS_LOGGER_H
#define MS_LOGGER_H
#include "common.h"
#include "common.h"
#include "Settings.h"
#include "Settings.h"
#include <string>
#include <string>
...
@@ -9,11 +8,11 @@
...
@@ -9,11 +8,11 @@
#include <cstring>
#include <cstring>
#include <cstdlib> // std::_Exit(), std::abort()
#include <cstdlib> // std::_Exit(), std::abort()
#include <uv.h>
#include <uv.h>
extern
"C"
{
extern
"C"
{
#include <syslog.h>
#include <syslog.h>
}
}
/*
/*
* Logger facility for MediaSoup.
* Logger facility for MediaSoup.
*
*
...
@@ -55,8 +54,8 @@ extern "C" {
...
@@ -55,8 +54,8 @@ extern "C" {
*/
*/
#define MS_GET_LOG_LEVEL Settings::configuration.logLevel
#define MS_GET_LOG_LEVEL Settings::configuration.logLevel
class
Logger
class
Logger
{
{
public
:
public
:
static
void
ThreadInit
(
const
std
::
string
name
);
static
void
ThreadInit
(
const
std
::
string
name
);
static
const
char
*
GetThreadName
();
static
const
char
*
GetThreadName
();
...
@@ -73,27 +72,26 @@ private:
...
@@ -73,27 +72,26 @@ private:
static
bool
isSyslogEnabled
;
static
bool
isSyslogEnabled
;
};
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
const
char
*
Logger
::
GetThreadName
()
{
const
char
*
Logger
::
GetThreadName
()
{
return
Logger
::
threadNamePtr
;
return
Logger
::
threadNamePtr
;
}
}
inline
inline
bool
Logger
::
IsSyslogEnabled
()
{
bool
Logger
::
IsSyslogEnabled
()
{
return
Logger
::
isSyslogEnabled
;
return
Logger
::
isSyslogEnabled
;
}
}
inline
inline
bool
Logger
::
HasDebugLevel
()
{
bool
Logger
::
HasDebugLevel
()
{
return
(
LOG_DEBUG
==
MS_GET_LOG_LEVEL
);
return
(
LOG_DEBUG
==
MS_GET_LOG_LEVEL
);
}
}
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
#ifdef MS_DEVEL
#ifdef MS_DEVEL
...
@@ -108,19 +106,22 @@ bool Logger::HasDebugLevel() {
...
@@ -108,19 +106,22 @@ bool Logger::HasDebugLevel() {
#endif
#endif
#define _MS_TO_STDOUT(prefix) \
#define _MS_TO_STDOUT(prefix) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stdout, prefix _MS_LOG_STR "\n", _MS_LOG_ARG); \
std::fprintf(stdout, prefix _MS_LOG_STR "\n", _MS_LOG_ARG); \
fflush(stdout); \
fflush(stdout); \
}
}
#define _MS_TO_STDOUT_DESC(prefix, desc, ...) \
#define _MS_TO_STDOUT_DESC(prefix, desc, ...) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stdout, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
std::fprintf(stdout, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stdout); \
fflush(stdout); \
}
}
#define _MS_TO_STDERR_DESC(prefix, desc, ...) \
#define _MS_TO_STDERR_DESC(prefix, desc, ...) \
if (! Logger::IsSyslogEnabled()) { \
if (!Logger::IsSyslogEnabled()) \
{ \
std::fprintf(stderr, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
std::fprintf(stderr, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stderr); \
fflush(stderr); \
}
}
...
@@ -133,7 +134,6 @@ bool Logger::HasDebugLevel() {
...
@@ -133,7 +134,6 @@ bool Logger::HasDebugLevel() {
if (Logger::IsSyslogEnabled()) \
if (Logger::IsSyslogEnabled()) \
syslog(severity, prefix _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__);
syslog(severity, prefix _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__);
/*
/*
* Log levels in syslog.h:
* Log levels in syslog.h:
*
*
...
@@ -150,80 +150,104 @@ bool Logger::HasDebugLevel() {
...
@@ -150,80 +150,104 @@ bool Logger::HasDebugLevel() {
#ifdef MS_DEVEL
#ifdef MS_DEVEL
#define MS_TRACE() \
#define MS_TRACE() \
do { \
do \
{ \
_MS_TO_STDOUT("TRACE: "); \
_MS_TO_STDOUT("TRACE: "); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE: "); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE: "); \
} while(0)
} \
while (0)
#else
#else
#define MS_TRACE()
#define MS_TRACE()
#endif
#endif
#define MS_DEBUG(desc, ...) \
#define MS_DEBUG(desc, ...) \
do { \
do \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) { \
{ \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC("DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG: ", desc, ##__VA_ARGS__); \
} \
} \
} while(0)
} \
while (0)
#define MS_INFO(desc, ...) \
#define MS_INFO(desc, ...) \
do { \
do \
if (LOG_INFO <= MS_GET_LOG_LEVEL) { \
{ \
if (LOG_INFO <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC("INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO: ", desc, ##__VA_ARGS__); \
} \
} \
} while(0)
} \
while (0)
#define MS_NOTICE(desc, ...) \
#define MS_NOTICE(desc, ...) \
do { \
do \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) { \
{ \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC("NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE: ", desc, ##__VA_ARGS__); \
} \
} \
} while(0)
} \
while (0)
#define MS_WARN(desc, ...) \
#define MS_WARN(desc, ...) \
do { \
do \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) { \
{ \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDERR_DESC("WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC("WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN: ", desc, ##__VA_ARGS__); \
} \
} \
} while(0)
} \
while (0)
#define MS_ERROR(desc, ...) \
#define MS_ERROR(desc, ...) \
do { \
do \
{ \
_MS_TO_STDERR_DESC("ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC("ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR: ", desc, ##__VA_ARGS__); \
} while(0)
} \
while (0)
#define MS_CRIT(desc, ...) \
#define MS_CRIT(desc, ...) \
do { \
do \
{ \
_MS_TO_STDERR_DESC("CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC("CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT: ", desc, ##__VA_ARGS__); \
} while(0)
} \
while (0)
#define MS_EXIT_SUCCESS(desc, ...) \
#define MS_EXIT_SUCCESS(desc, ...) \
do { \
do \
{ \
MS_NOTICE("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
MS_NOTICE("SUCCESS EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_SUCCESS); \
std::_Exit(EXIT_SUCCESS); \
} while(0)
} \
while (0)
#define MS_EXIT_FAILURE(desc, ...) \
#define MS_EXIT_FAILURE(desc, ...) \
do { \
do \
{ \
MS_CRIT("FAILURE EXIT | " desc, ##__VA_ARGS__); \
MS_CRIT("FAILURE EXIT | " desc, ##__VA_ARGS__); \
std::_Exit(EXIT_FAILURE); \
std::_Exit(EXIT_FAILURE); \
} while(0)
} \
while (0)
#define MS_ABORT(desc, ...) \
#define MS_ABORT(desc, ...) \
do { \
do \
{ \
MS_CRIT("ABORT | " desc, ##__VA_ARGS__); \
MS_CRIT("ABORT | " desc, ##__VA_ARGS__); \
std::abort(); \
std::abort(); \
} while(0)
} \
while (0)
#define MS_ASSERT(condition, desc, ...) \
#define MS_ASSERT(condition, desc, ...) \
if (! (condition)) { \
if (!(condition)) \
{ \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
}
}
#endif
#endif
include/MediaSoup.h
浏览文件 @
6262224c
#ifndef MS_MEDIASOUP_H
#ifndef MS_MEDIASOUP_H
#define MS_MEDIASOUP_H
#define MS_MEDIASOUP_H
/*
/*
* MediaSoup top class.
* MediaSoup top class.
*
*
* Entry point of the application.
* Entry point of the application.
*/
*/
class
MediaSoup
{
class
MediaSoup
{
public
:
public
:
// Set the process.
// Set the process.
static
void
SetProcess
();
static
void
SetProcess
();
...
@@ -27,5 +27,4 @@ private:
...
@@ -27,5 +27,4 @@ private:
static
void
RunWorkerThread
(
void
*
data
);
static
void
RunWorkerThread
(
void
*
data
);
};
};
#endif
#endif
include/MediaSoupError.h
浏览文件 @
6262224c
#ifndef MS_MEDIASOUP_ERROR_H
#ifndef MS_MEDIASOUP_ERROR_H
#define MS_MEDIASOUP_ERROR_H
#define MS_MEDIASOUP_ERROR_H
#include "Logger.h"
#include "Logger.h"
#include <stdexcept>
#include <stdexcept>
#include <string>
#include <string>
#include <cstdio> // std::snprintf
#include <cstdio> // std::snprintf
class
MediaSoupError
:
public
std
::
runtime_error
class
MediaSoupError
:
public
std
::
runtime_error
{
{
public
:
public
:
MediaSoupError
(
const
char
*
description
);
MediaSoupError
(
const
char
*
description
);
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
MediaSoupError
::
MediaSoupError
(
const
char
*
description
)
:
MediaSoupError
::
MediaSoupError
(
const
char
*
description
)
:
std
::
runtime_error
(
description
)
std
::
runtime_error
(
description
)
{}
{}
#define MS_THROW_ERROR(desc, ...) \
#define MS_THROW_ERROR(desc, ...) \
do { \
do \
{ \
MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \
MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \
char buffer[1000]; \
char buffer[1000]; \
std::snprintf(buffer, 1000, desc, ##__VA_ARGS__); \
std::snprintf(buffer, 1000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \
throw MediaSoupError(buffer); \
}
while(0)
}
\
while (0)
#endif
#endif
include/OpenSSL.h
浏览文件 @
6262224c
#ifndef MS_OPENSSL_H
#ifndef MS_OPENSSL_H
#define MS_OPENSSL_H
#define MS_OPENSSL_H
#include "common.h"
#include "common.h"
#include <openssl/ssl.h>
#include <openssl/ssl.h>
#include <openssl/crypto.h>
#include <openssl/crypto.h>
/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
struct
CRYPTO_dynlock_value
{
struct
CRYPTO_dynlock_value
{
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
};
};
class
OpenSSL
class
OpenSSL
{
{
public
:
public
:
static
void
ClassInit
();
static
void
ClassInit
();
static
void
ClassDestroy
();
static
void
ClassDestroy
();
...
@@ -30,5 +29,4 @@ private:
...
@@ -30,5 +29,4 @@ private:
static
int
numMutexes
;
static
int
numMutexes
;
};
};
#endif
#endif
include/RTC/DTLSHandler.h
浏览文件 @
6262224c
#ifndef MS_RTC_DTLS_HANDLER_H
#ifndef MS_RTC_DTLS_HANDLER_H
#define MS_RTC_DTLS_HANDLER_H
#define MS_RTC_DTLS_HANDLER_H
#include "common.h"
#include "common.h"
#include "handles/Timer.h"
#include "handles/Timer.h"
#include "RTC/DTLSRole.h"
#include "RTC/DTLSRole.h"
...
@@ -14,137 +13,133 @@
...
@@ -14,137 +13,133 @@
#include <openssl/bio.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <openssl/x509.h>
namespace
RTC
{
class
DTLSHandler
:
public
Timer
::
Listener
{
private
:
struct
SrtpProfileMapEntry
{
SRTPProfile
profile
;
const
char
*
name
;
};
namespace
RTC
{
public
:
class
Listener
{
public
:
// NOTE: The caller MUST NOT call Reset() or Close() during the
// onOutgoingDTLSData() callback.
virtual
void
onOutgoingDTLSData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// onDTLSDisconnected or onDTLSFailed callbacks.
virtual
void
onDTLSConnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSDisconnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onDTLSFailed
(
DTLSHandler
*
dtlsHandler
)
=
0
;
virtual
void
onSRTPKeyMaterial
(
DTLSHandler
*
dtlsHandler
,
RTC
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
public
:
static
void
ClassInit
();
static
void
ClassDestroy
();
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
static
const
std
::
string
&
GetFingerprint
(
RTC
::
FingerprintHash
hash
);
private
:
static
void
GenerateCertificateAndPrivateKey
();
static
void
ReadCertificateAndPrivateKeyFromFiles
();
static
void
CreateSSL_CTX
();
static
void
GenerateFingerprints
();
private
:
static
X509
*
certificate
;
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
typedef
std
::
map
<
RTC
::
FingerprintHash
,
std
::
string
>
Fingerprints
;
static
Fingerprints
fingerprints
;
typedef
std
::
vector
<
SrtpProfileMapEntry
>
SRTPProfiles
;
static
SRTPProfiles
srtpProfiles
;
static
__thread
MS_BYTE
sslReadBuffer
[];
class
DTLSHandler
:
public
:
public
Timer
::
Listener
DTLSHandler
(
Listener
*
listener
);
{
virtual
~
DTLSHandler
();
private
:
struct
SrtpProfileMapEntry
{
void
Run
(
RTC
::
DTLSRole
role
);
SRTPProfile
profile
;
void
SetRemoteFingerprint
(
RTC
::
FingerprintHash
hash
,
std
::
string
&
fingerprint
);
const
char
*
name
;
void
Reset
();
};
void
Close
();
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
IsRunning
();
bool
IsConnected
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Dump
();
private
:
bool
CheckStatus
(
int
return_code
);
void
SendPendingOutgoingDTLSData
();
void
SetTimeout
();
void
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
RTC
::
SRTPProfile
GetNegotiatedSRTPProfile
();
void
ExtractSRTPKeys
(
RTC
::
SRTPProfile
srtp_profile
);
/* Callbacks fired by OpenSSL events. */
public
:
void
onSSLInfo
(
int
where
,
int
ret
);
public
:
/* Pure virtual methods inherited from Timer::Listener. */
class
Listener
{
public
:
public
:
// NOTE: The caller MUST NOT call Reset() or Close() during the
virtual
void
onTimer
(
Timer
*
timer
)
override
;
// onOutgoingDTLSData() callback.
virtual
void
onOutgoingDTLSData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
private
:
// NOTE: The caller MUST NOT call any method during the onDTLSConnected,
// Passed by argument:
// onDTLSDisconnected or onDTLSFailed callbacks.
Listener
*
listener
=
nullptr
;
virtual
void
onDTLSConnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
// Allocated by this:
virtual
void
onDTLSDisconnected
(
DTLSHandler
*
dtlsHandler
)
=
0
;
SSL
*
ssl
=
nullptr
;
virtual
void
onDTLSFailed
(
DTLSHandler
*
dtlsHandler
)
=
0
;
BIO
*
sslBioFromNetwork
=
nullptr
;
// The BIO from which ssl reads.
virtual
void
onSRTPKeyMaterial
(
DTLSHandler
*
dtlsHandler
,
RTC
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
virtual
void
onDTLSApplicationData
(
DTLSHandler
*
dtlsHandler
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
Timer
*
timer
=
nullptr
;
// Others:
RTC
::
DTLSRole
role
;
RTC
::
FingerprintHash
remoteFingerprintHash
=
RTC
::
FingerprintHash
::
NONE
;
std
::
string
remoteFingerprint
;
bool
isRunning
=
false
;
bool
isHandshakeDone
=
false
;
bool
isHandshakeDoneNow
=
false
;
bool
isConnected
=
false
;
bool
isCheckingStatus
=
false
;
bool
doReset
=
false
;
bool
doClose
=
false
;
};
};
public
:
/* Inline static methods. */
static
void
ClassInit
();
static
void
ClassDestroy
();
inline
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
DTLSHandler
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
static
const
std
::
string
&
GetFingerprint
(
RTC
::
FingerprintHash
hash
);
{
return
(
private
:
// Minimum DTLS record length is 13 bytes.
static
void
GenerateCertificateAndPrivateKey
();
(
len
>=
13
)
&&
static
void
ReadCertificateAndPrivateKeyFromFiles
();
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
static
void
CreateSSL_CTX
();
(
data
[
0
]
>
19
&&
data
[
0
]
<
64
)
static
void
GenerateFingerprints
();
);
}
private
:
static
X509
*
certificate
;
/* Inline instance methods. */
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
inline
typedef
std
::
map
<
RTC
::
FingerprintHash
,
std
::
string
>
Fingerprints
;
bool
DTLSHandler
::
IsConnected
()
static
Fingerprints
fingerprints
;
{
typedef
std
::
vector
<
SrtpProfileMapEntry
>
SRTPProfiles
;
return
this
->
isConnected
;
static
SRTPProfiles
srtpProfiles
;
}
static
__thread
MS_BYTE
sslReadBuffer
[];
inline
public
:
bool
DTLSHandler
::
IsRunning
()
DTLSHandler
(
Listener
*
listener
);
{
virtual
~
DTLSHandler
();
return
this
->
isRunning
;
}
void
Run
(
RTC
::
DTLSRole
role
);
void
SetRemoteFingerprint
(
RTC
::
FingerprintHash
hash
,
std
::
string
&
fingerprint
);
void
Reset
();
void
Close
();
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
bool
IsRunning
();
bool
IsConnected
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Dump
();
private
:
bool
CheckStatus
(
int
return_code
);
void
SendPendingOutgoingDTLSData
();
void
SetTimeout
();
void
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
RTC
::
SRTPProfile
GetNegotiatedSRTPProfile
();
void
ExtractSRTPKeys
(
RTC
::
SRTPProfile
srtp_profile
);
/* Callbacks fired by OpenSSL events. */
public
:
void
onSSLInfo
(
int
where
,
int
ret
);
/* Pure virtual methods inherited from Timer::Listener. */
public
:
virtual
void
onTimer
(
Timer
*
timer
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
// Allocated by this:
SSL
*
ssl
=
nullptr
;
BIO
*
sslBioFromNetwork
=
nullptr
;
// The BIO from which ssl reads.
BIO
*
sslBioToNetwork
=
nullptr
;
// The BIO in which ssl writes.
Timer
*
timer
=
nullptr
;
// Others:
RTC
::
DTLSRole
role
;
RTC
::
FingerprintHash
remoteFingerprintHash
=
RTC
::
FingerprintHash
::
NONE
;
std
::
string
remoteFingerprint
;
bool
isRunning
=
false
;
bool
isHandshakeDone
=
false
;
bool
isHandshakeDoneNow
=
false
;
bool
isConnected
=
false
;
bool
isCheckingStatus
=
false
;
bool
doReset
=
false
;
bool
doClose
=
false
;
};
/* Inline static methods. */
inline
bool
DTLSHandler
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
{
return
(
// Minimum DTLS record length is 13 bytes.
(
len
>=
13
)
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
19
&&
data
[
0
]
<
64
)
);
}
/* Inline instance methods. */
inline
bool
DTLSHandler
::
IsConnected
()
{
return
this
->
isConnected
;
}
inline
bool
DTLSHandler
::
IsRunning
()
{
return
this
->
isRunning
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/DTLSRole.h
浏览文件 @
6262224c
#ifndef MS_RTC_DTLS_ROLE_H
#ifndef MS_RTC_DTLS_ROLE_H
#define MS_RTC_DTLS_ROLE_H
#define MS_RTC_DTLS_ROLE_H
namespace
RTC
{
namespace
RTC
{
enum
class
DTLSRole
{
enum
class
DTLSRole
{
NONE
=
0
,
NONE
=
0
,
SERVER
=
1
,
SERVER
=
1
,
CLIENT
CLIENT
};
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/FingerprintHash.h
浏览文件 @
6262224c
#ifndef MS_RTC_FINGERPRINT_HASH_H
#ifndef MS_RTC_FINGERPRINT_HASH_H
#define MS_RTC_FINGERPRINT_HASH_H
#define MS_RTC_FINGERPRINT_HASH_H
namespace
RTC
namespace
RTC
{
{
enum
class
FingerprintHash
{
enum
class
FingerprintHash
{
NONE
=
0
,
NONE
=
0
,
SHA1
=
1
,
SHA1
=
1
,
SHA224
,
SHA224
,
SHA256
,
SHA256
,
SHA384
,
SHA384
,
SHA512
SHA512
};
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/ICEServer.h
浏览文件 @
6262224c
#ifndef MS_RTC_ICE_SERVER_H
#ifndef MS_RTC_ICE_SERVER_H
#define MS_RTC_ICE_SERVER_H
#define MS_RTC_ICE_SERVER_H
#include "common.h"
#include "common.h"
#include "RTC/TransportSource.h"
#include "RTC/TransportSource.h"
#include "RTC/STUNMessage.h"
#include "RTC/STUNMessage.h"
...
@@ -9,69 +8,66 @@
...
@@ -9,69 +8,66 @@
#include "RTC/TCPConnection.h"
#include "RTC/TCPConnection.h"
#include <string>
#include <string>
namespace
RTC
{
class
ICEServer
{
public
:
class
Listener
{
public
:
/**
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* returns, so the given pointers are still usable.
*/
virtual
void
onOutgoingSTUNMessage
(
ICEServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
=
0
;
virtual
void
onICEValidPair
(
ICEServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
=
0
;
};
namespace
RTC
{
class
ICEServer
{
public
:
class
Listener
{
public
:
public
:
/**
ICEServer
(
Listener
*
listener
);
* These callbacks are guaranteed to be called before ProcessSTUNMessage()
* returns, so the given pointers are still usable.
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
);
*/
std
::
string
&
GetLocalUsername
();
virtual
void
onOutgoingSTUNMessage
(
ICEServer
*
iceServer
,
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
)
=
0
;
std
::
string
&
GetLocalPassword
();
virtual
void
onICEValidPair
(
ICEServer
*
iceServer
,
RTC
::
TransportSource
*
source
,
bool
has_use_candidate
)
=
0
;
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
std
::
string
localUsername
;
std
::
string
localPassword
;
};
};
public
:
/* Inline methods. */
ICEServer
(
Listener
*
listener
);
inline
void
ProcessSTUNMessage
(
RTC
::
STUNMessage
*
msg
,
RTC
::
TransportSource
*
source
);
std
::
string
&
ICEServer
::
GetLocalUsername
()
std
::
string
&
GetLocalUsername
();
{
std
::
string
&
GetLocalPassword
();
return
this
->
localUsername
;
void
SetUserData
(
void
*
userData
);
}
void
*
GetUserData
();
void
Close
();
inline
std
::
string
&
ICEServer
::
GetLocalPassword
()
private
:
{
// Passed by argument:
return
this
->
localPassword
;
Listener
*
listener
=
nullptr
;
}
void
*
userData
=
nullptr
;
// Others:
inline
std
::
string
localUsername
;
void
ICEServer
::
SetUserData
(
void
*
userData
)
std
::
string
localPassword
;
{
};
this
->
userData
=
userData
;
}
/* Inline methods. */
inline
void
*
ICEServer
::
GetUserData
()
inline
{
std
::
string
&
ICEServer
::
GetLocalUsername
()
{
return
this
->
userData
;
return
this
->
localUsername
;
}
}
inline
std
::
string
&
ICEServer
::
GetLocalPassword
()
{
return
this
->
localPassword
;
}
inline
void
ICEServer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
ICEServer
::
GetUserData
()
{
return
this
->
userData
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/Peer.h
浏览文件 @
6262224c
#ifndef MS_RTC_PEER_H
#ifndef MS_RTC_PEER_H
#define MS_RTC_PEER_H
#define MS_RTC_PEER_H
#include "RTC/Transport.h"
#include "RTC/Transport.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include <vector>
#include <vector>
namespace
RTC
namespace
RTC
{
class
Peer
:
RTC
::
Transport
::
Listener
{
{
public
:
class
Peer
:
RTC
::
Transport
::
Listener
class
Listener
{
{
public
:
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
=
0
;
class
Listener
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
=
0
;
{
};
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
=
0
;
public
:
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
=
0
;
Peer
(
Listener
*
listener
);
};
virtual
~
Peer
();
void
SendRTPPacket
(
RTC
::
RTPPacket
*
packet
);
void
SendRTCPPacket
(
RTC
::
RTCPPacket
*
packet
);
void
SetUserData
(
void
*
userData
);
void
*
GetUserData
();
void
Close
();
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
RTC
::
Transport
*
transport
=
nullptr
;
};
/* Inline methods. */
inline
void
Peer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
public
:
Peer
(
Listener
*
listener
);
virtual
~
Peer
();
inline
void
SendRTPPacket
(
RTC
::
RTPPacket
*
packet
);
void
*
Peer
::
GetUserData
()
{
void
SendRTCPPacket
(
RTC
::
RTCPPacket
*
packet
);
return
this
->
userData
;
void
SetUserData
(
void
*
userData
);
}
void
*
GetUserData
();
void
Close
();
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public
:
virtual
void
onRTPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTPPacket
*
packet
)
override
;
virtual
void
onRTCPPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCPPacket
*
packet
)
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
void
*
userData
=
nullptr
;
// Others:
RTC
::
Transport
*
transport
=
nullptr
;
};
/* Inline methods. */
inline
void
Peer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
}
inline
void
*
Peer
::
GetUserData
()
{
return
this
->
userData
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/RTCPPacket.h
浏览文件 @
6262224c
#ifndef MS_RTC_RTCP_PACKET_H
#ifndef MS_RTC_RTCP_PACKET_H
#define MS_RTC_RTCP_PACKET_H
#define MS_RTC_RTCP_PACKET_H
#include "common.h"
#include "common.h"
namespace
RTC
namespace
RTC
{
{
class
RTCPPacket
{
class
RTCPPacket
{
public
:
public
:
/* Struct for RTCP common header. */
/* Struct for RTCP common header. */
typedef
struct
CommonHeader
typedef
struct
CommonHeader
{
{
#if defined(MS_LITTLE_ENDIAN)
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
count
:
5
;
MS_BYTE
count
:
5
;
MS_BYTE
padding
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
MS_BYTE
version
:
2
;
#elif defined(MS_BIG_ENDIAN)
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
count
:
5
;
MS_BYTE
count
:
5
;
#endif
#endif
MS_BYTE
packet_type
:
8
;
MS_BYTE
packet_type
:
8
;
MS_2BYTES
length
:
16
;
MS_2BYTES
length
:
16
;
}
CommonHeader
;
}
CommonHeader
;
public
:
public
:
static
bool
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
public
:
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
);
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTCPPacket
();
~
RTCPPacket
();
const
MS_BYTE
*
GetRaw
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
size_t
GetLength
();
private
:
private
:
// Passed by argument:
// Passed by argument:
CommonHeader
*
header
=
nullptr
;
CommonHeader
*
header
=
nullptr
;
MS_BYTE
*
raw
=
nullptr
;
MS_BYTE
*
raw
=
nullptr
;
size_t
length
=
0
;
size_t
length
=
0
;
};
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
bool
RTCPPacket
::
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
)
bool
RTCPPacket
::
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
{
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
return
(
return
(
(
len
>=
sizeof
(
CommonHeader
))
&&
(
len
>=
sizeof
(
CommonHeader
))
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// RTP Version must be 2.
// RTP Version must be 2.
(
header
->
version
==
2
)
&&
(
header
->
version
==
2
)
&&
// RTCP packet types defined by IANA:
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(
header
->
packet_type
>=
192
&&
header
->
packet_type
<=
223
)
(
header
->
packet_type
>=
192
&&
header
->
packet_type
<=
223
)
);
);
}
}
/* Inline instance methods. */
/* Inline instance methods. */
inline
inline
const
MS_BYTE
*
RTCPPacket
::
GetRaw
()
const
MS_BYTE
*
RTCPPacket
::
GetRaw
()
{
{
return
this
->
raw
;
return
this
->
raw
;
}
}
inline
inline
size_t
RTCPPacket
::
GetLength
()
size_t
RTCPPacket
::
GetLength
()
{
{
return
this
->
length
;
return
this
->
length
;
}
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/RTPPacket.h
浏览文件 @
6262224c
#ifndef MS_RTC_RTP_PACKET_H
#ifndef MS_RTC_RTP_PACKET_H
#define MS_RTC_RTP_PACKET_H
#define MS_RTC_RTP_PACKET_H
#include "common.h"
#include "common.h"
namespace
RTC
namespace
RTC
{
{
class
RTPPacket
{
class
RTPPacket
{
public
:
public
:
/* Struct for RTP header. */
/* Struct for RTP header. */
typedef
struct
Header
typedef
struct
Header
{
{
#if defined(MS_LITTLE_ENDIAN)
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
csrc_count
:
4
;
MS_BYTE
csrc_count
:
4
;
MS_BYTE
extension
:
1
;
MS_BYTE
extension
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
version
:
2
;
MS_BYTE
version
:
2
;
MS_BYTE
payload_type
:
7
;
MS_BYTE
payload_type
:
7
;
MS_BYTE
marker
:
1
;
MS_BYTE
marker
:
1
;
#elif defined(MS_BIG_ENDIAN)
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
MS_BYTE
version
:
2
;
MS_BYTE
padding
:
1
;
MS_BYTE
padding
:
1
;
MS_BYTE
extension
:
1
;
MS_BYTE
extension
:
1
;
MS_BYTE
csrc_count
:
4
;
MS_BYTE
csrc_count
:
4
;
MS_BYTE
marker
:
1
;
MS_BYTE
marker
:
1
;
MS_BYTE
payload_type
:
7
;
MS_BYTE
payload_type
:
7
;
#endif
#endif
MS_2BYTES
sequence_number
;
MS_2BYTES
sequence_number
;
MS_4BYTES
timestamp
;
MS_4BYTES
timestamp
;
MS_4BYTES
ssrc
;
MS_4BYTES
ssrc
;
}
Header
;
}
Header
;
/* Struct for RTP header extension. */
/* Struct for RTP header extension. */
typedef
struct
ExtensionHeader
{
typedef
struct
ExtensionHeader
MS_2BYTES
id
;
{
MS_2BYTES
length
;
// Size of value in multiples of 4 bytes.
MS_2BYTES
id
;
MS_BYTE
*
value
;
MS_2BYTES
length
;
// Size of value in multiples of 4 bytes.
}
ExtensionHeader
;
MS_BYTE
*
value
;
}
ExtensionHeader
;
public
:
static
bool
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
static
RTPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLen
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
);
public
:
~
RTPPacket
();
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLen
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
);
~
RTPPacket
();
const
MS_BYTE
*
GetRaw
();
size_t
GetLength
();
const
MS_BYTE
*
GetRaw
();
MS_BYTE
GetPayloadType
();
size_t
GetLength
();
void
SetPayloadType
(
MS_BYTE
payload_type
);
MS_BYTE
GetPayloadType
();
bool
HasMarker
();
void
SetPayloadType
(
MS_BYTE
payload_type
);
void
SetMarker
(
bool
marker
);
bool
HasMarker
();
MS_2BYTES
GetSequenceNumber
();
void
SetMarker
(
bool
marker
);
MS_4BYTES
GetTimestamp
();
MS_2BYTES
GetSequenceNumber
();
MS_4BYTES
GetSSRC
();
MS_4BYTES
GetTimestamp
();
void
SetSSRC
(
MS_4BYTES
ssrc
);
MS_4BYTES
GetSSRC
();
bool
HasExtensionHeader
();
void
SetSSRC
(
MS_4BYTES
ssrc
);
MS_2BYTES
GetExtensionHeaderId
();
bool
HasExtensionHeader
();
size_t
GetExtensionHeaderLength
();
MS_2BYTES
GetExtensionHeaderId
();
MS_BYTE
*
GetPayload
();
size_t
GetExtensionHeaderLength
();
size_t
GetPayloadLength
();
MS_BYTE
*
GetPayload
();
void
Serialize
();
size_t
GetPayloadLength
();
void
Dump
();
void
Serialize
();
void
Dump
();
private
:
// Passed by argument:
private
:
Header
*
header
=
nullptr
;
// Passed by argument:
MS_BYTE
*
csrcList
=
nullptr
;
Header
*
header
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
MS_BYTE
*
csrcList
=
nullptr
;
MS_BYTE
*
payload
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
size_t
payloadLength
=
0
;
MS_BYTE
*
payload
=
nullptr
;
MS_BYTE
payloadPadding
=
0
;
size_t
payloadLength
=
0
;
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
MS_BYTE
payloadPadding
=
0
;
size_t
length
=
0
;
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
// Others:
size_t
length
=
0
;
bool
isSerialized
=
false
;
// Others:
};
bool
isSerialized
=
false
;
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
bool
RTPPacket
::
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
)
{
bool
RTPPacket
::
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
)
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
{
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
Header
*
header
=
(
Header
*
)
data
;
Header
*
header
=
(
Header
*
)
data
;
return
(
(
len
>=
sizeof
(
Header
))
&&
return
(
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(
len
>=
sizeof
(
Header
))
&&
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
// RTP Version must be 2.
(
data
[
0
]
>
127
&&
data
[
0
]
<
192
)
&&
(
header
->
version
==
2
)
// RTP Version must be 2.
);
(
header
->
version
==
2
)
}
);
}
/* Inline instance methods. */
/* Inline instance methods. */
inline
inline
const
MS_BYTE
*
RTPPacket
::
GetRaw
()
{
const
MS_BYTE
*
RTPPacket
::
GetRaw
()
return
this
->
raw
;
{
}
return
this
->
raw
;
}
inline
inline
size_t
RTPPacket
::
GetLength
()
{
size_t
RTPPacket
::
GetLength
()
return
this
->
length
;
{
}
return
this
->
length
;
}
inline
inline
MS_BYTE
RTPPacket
::
GetPayloadType
()
{
MS_BYTE
RTPPacket
::
GetPayloadType
()
return
this
->
header
->
payload_type
;
{
}
return
this
->
header
->
payload_type
;
}
inline
inline
void
RTPPacket
::
SetPayloadType
(
MS_BYTE
payload_type
)
{
void
RTPPacket
::
SetPayloadType
(
MS_BYTE
payload_type
)
this
->
header
->
payload_type
=
payload_type
;
{
}
this
->
header
->
payload_type
=
payload_type
;
}
inline
inline
bool
RTPPacket
::
HasMarker
()
{
bool
RTPPacket
::
HasMarker
()
return
this
->
header
->
marker
;
{
}
return
this
->
header
->
marker
;
}
inline
inline
void
RTPPacket
::
SetMarker
(
bool
marker
)
{
void
RTPPacket
::
SetMarker
(
bool
marker
)
this
->
header
->
marker
=
marker
;
{
}
this
->
header
->
marker
=
marker
;
}
inline
inline
MS_2BYTES
RTPPacket
::
GetSequenceNumber
()
{
MS_2BYTES
RTPPacket
::
GetSequenceNumber
()
return
ntohs
(
this
->
header
->
sequence_number
);
{
}
return
ntohs
(
this
->
header
->
sequence_number
);
}
inline
inline
MS_4BYTES
RTPPacket
::
GetTimestamp
()
{
MS_4BYTES
RTPPacket
::
GetTimestamp
()
return
ntohl
(
this
->
header
->
timestamp
);
{
}
return
ntohl
(
this
->
header
->
timestamp
);
}
inline
inline
MS_4BYTES
RTPPacket
::
GetSSRC
()
{
MS_4BYTES
RTPPacket
::
GetSSRC
()
return
ntohl
(
this
->
header
->
ssrc
);
{
}
return
ntohl
(
this
->
header
->
ssrc
);
}
// TODO temp
// TODO temp
inline
inline
void
RTPPacket
::
SetSSRC
(
MS_4BYTES
ssrc
)
{
void
RTPPacket
::
SetSSRC
(
MS_4BYTES
ssrc
)
this
->
header
->
ssrc
=
htonl
(
ssrc
);
{
}
this
->
header
->
ssrc
=
htonl
(
ssrc
);
}
inline
inline
bool
RTPPacket
::
HasExtensionHeader
()
{
bool
RTPPacket
::
HasExtensionHeader
()
return
(
this
->
extensionHeader
?
true
:
false
);
{
}
return
(
this
->
extensionHeader
?
true
:
false
);
}
inline
inline
MS_2BYTES
RTPPacket
::
GetExtensionHeaderId
()
{
MS_2BYTES
RTPPacket
::
GetExtensionHeaderId
()
if
(
this
->
extensionHeader
)
{
return
MS_2BYTES
(
ntohs
(
this
->
extensionHeader
->
id
));
if
(
this
->
extensionHeader
)
else
return
MS_2BYTES
(
ntohs
(
this
->
extensionHeader
->
id
));
return
0
;
else
}
return
0
;
}
inline
inline
size_t
RTPPacket
::
GetExtensionHeaderLength
()
{
size_t
RTPPacket
::
GetExtensionHeaderLength
()
if
(
this
->
extensionHeader
)
{
return
size_t
(
ntohs
(
this
->
extensionHeader
->
length
)
*
4
);
if
(
this
->
extensionHeader
)
else
return
size_t
(
ntohs
(
this
->
extensionHeader
->
length
)
*
4
);
return
0
;
else
}
return
0
;
}
inline
inline
MS_BYTE
*
RTPPacket
::
GetPayload
()
{
MS_BYTE
*
RTPPacket
::
GetPayload
()
return
this
->
payload
;
{
}
return
this
->
payload
;
}
inline
inline
size_t
RTPPacket
::
GetPayloadLength
()
{
size_t
RTPPacket
::
GetPayloadLength
()
return
this
->
payloadLength
;
{
}
return
this
->
payloadLength
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/Room.h
浏览文件 @
6262224c
#ifndef MS_RTC_ROOM_H
#ifndef MS_RTC_ROOM_H
#define MS_RTC_ROOM_H
#define MS_RTC_ROOM_H
#include "RTC/Peer.h"
#include "RTC/Peer.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include <vector>
#include <vector>
namespace
RTC
namespace
RTC
{
class
Room
:
RTC
::
Peer
::
Listener
{
{
public
:
class
Room
:
RTC
::
Peer
::
Listener
Room
();
{
virtual
~
Room
();
public
:
Room
();
void
Close
();
virtual
~
Room
();
/* Pure virtual methods inherited from RTC::Peer::Listener. */
void
Close
();
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
override
;
/* Pure virtual methods inherited from RTC::Peer::Listener. */
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
override
;
public
:
virtual
void
onRTPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTPPacket
*
packet
)
override
;
private
:
virtual
void
onRTCPPacket
(
RTC
::
Peer
*
peer
,
RTC
::
RTCPPacket
*
packet
)
override
;
// Others:
typedef
std
::
vector
<
RTC
::
Peer
*>
Peers
;
private
:
Peers
peers
;
// Others:
}
;
typedef
std
::
vector
<
RTC
::
Peer
*>
Peers
;
Peers
peers
;
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/SRTPProfile.h
浏览文件 @
6262224c
#ifndef MS_RTC_SRTP_PROFILE_H
#ifndef MS_RTC_SRTP_PROFILE_H
#define MS_RTC_SRTP_PROFILE_H
#define MS_RTC_SRTP_PROFILE_H
namespace
RTC
namespace
RTC
{
{
enum
class
SRTPProfile
{
enum
class
SRTPProfile
{
NONE
=
0
,
NONE
=
0
,
AES_CM_128_HMAC_SHA1_80
=
1
,
AES_CM_128_HMAC_SHA1_80
=
1
,
AES_CM_128_HMAC_SHA1_32
AES_CM_128_HMAC_SHA1_32
};
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/SRTPSession.h
浏览文件 @
6262224c
#ifndef MS_RTC_SRTP_SESSION_H
#ifndef MS_RTC_SRTP_SESSION_H
#define MS_RTC_SRTP_SESSION_H
#define MS_RTC_SRTP_SESSION_H
#include "common.h"
#include "common.h"
#include "LibSRTP.h"
#include "LibSRTP.h"
#include "RTC/SRTPProfile.h"
#include "RTC/SRTPProfile.h"
#include <srtp/srtp.h>
#include <srtp/srtp.h>
namespace
RTC
namespace
RTC
{
{
class
SRTPSession
{
class
SRTPSession
{
public
:
public
:
enum
class
Type
enum
class
Type
{
{
INBOUND
=
1
,
INBOUND
=
1
,
OUTBOUND
OUTBOUND
};
public
:
static
void
ClassInit
();
private
:
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
private
:
static
__thread
MS_BYTE
encryptBuffer
[];
public
:
SRTPSession
(
Type
type
,
RTC
::
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
);
~
SRTPSession
();
bool
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
bool
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
const
char
*
GetLastErrorDesc
();
void
Close
();
private
:
// Allocated by this:
srtp_t
session
=
nullptr
;
// Others:
err_status_t
lastError
=
(
err_status_t
)
0
;
};
};
public
:
/* Inline instance methods. */
static
void
ClassInit
();
private
:
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
private
:
static
__thread
MS_BYTE
encryptBuffer
[];
public
:
SRTPSession
(
Type
type
,
RTC
::
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
);
~
SRTPSession
();
bool
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
inline
bool
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
const
char
*
SRTPSession
::
GetLastErrorDesc
()
bool
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
{
bool
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
const
char
*
error_string
;
const
char
*
GetLastErrorDesc
();
void
Close
();
private
:
// Allocated by this:
srtp_t
session
=
nullptr
;
// Others:
err_status_t
lastError
=
(
err_status_t
)
0
;
};
/* Inline instance methods. */
inline
const
char
*
SRTPSession
::
GetLastErrorDesc
()
{
const
char
*
error_string
;
error_string
=
LibSRTP
::
GetErrorString
(
this
->
lastError
);
this
->
lastError
=
(
err_status_t
)
0
;
// Reset it.
return
error_string
;
}
error_string
=
LibSRTP
::
GetErrorString
(
this
->
lastError
);
this
->
lastError
=
(
err_status_t
)
0
;
// Reset it.
return
error_string
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/STUNMessage.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/RTC/Stream.h
浏览文件 @
6262224c
#ifndef MS_RTC_STREAM_H
#ifndef MS_RTC_STREAM_H
#define MS_RTC_STREAM_H
#define MS_RTC_STREAM_H
#include "common.h"
#include "common.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTPPacket.h"
#include "RTC/RTCPPacket.h"
#include "RTC/RTCPPacket.h"
#include <unordered_set>
#include <unordered_set>
namespace
RTC
{
class
Stream
{
public
:
Stream
();
~
Stream
();
namespace
RTC
{
void
Close
();
class
Stream
{
public
:
Stream
();
~
Stream
();
void
Close
();
private
:
MS_4BYTES
ssrc
=
0
;
std
::
unordered_set
<
MS_BYTE
>
payloads
;
};
private
:
MS_4BYTES
ssrc
=
0
;
std
::
unordered_set
<
MS_BYTE
>
payloads
;
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_RTC_TCP_CONNECTION_H
#ifndef MS_RTC_TCP_CONNECTION_H
#define MS_RTC_TCP_CONNECTION_H
#define MS_RTC_TCP_CONNECTION_H
#include "common.h"
#include "common.h"
#include "handles/TCPConnection.h"
#include "handles/TCPConnection.h"
namespace
RTC
namespace
RTC
{
{
class
TCPConnection
:
public
::
TCPConnection
{
class
TCPConnection
:
public
::
TCPConnection
{
public
:
class
Reader
{
public
:
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
class
Reader
virtual
void
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
{
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
public
:
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onSTUNDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
};
virtual
void
onDTLSDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
public
:
virtual
void
onRTCPDataRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
};
virtual
~
TCPConnection
();
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
public
:
TCPConnection
(
Reader
*
reader
,
size_t
bufferSize
);
/* Pure virtual methods inherited from ::TCPConnection. */
virtual
~
TCPConnection
();
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
frameStart
=
0
;
// Where the latest frame starts.
};
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
virtual
void
userOnTCPConnectionRead
(
const
MS_BYTE
*
data
,
size_t
len
)
override
;
private
:
// Passed by argument:
Reader
*
reader
=
nullptr
;
// Others:
size_t
frameStart
=
0
;
// Where the latest frame starts.
};
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_RTC_TCP_SERVER_H
#ifndef MS_RTC_TCP_SERVER_H
#define MS_RTC_TCP_SERVER_H
#define MS_RTC_TCP_SERVER_H
#include "common.h"
#include "common.h"
#include "handles/TCPServer.h"
#include "handles/TCPServer.h"
#include "handles/TCPConnection.h"
#include "handles/TCPConnection.h"
...
@@ -9,63 +8,60 @@
...
@@ -9,63 +8,60 @@
#include <unordered_map>
#include <unordered_map>
#include <uv.h>
#include <uv.h>
namespace
RTC
namespace
RTC
{
{
class
TCPServer
:
public
::
TCPServer
{
class
TCPServer
:
public
::
TCPServer
{
public
:
class
Listener
{
public
:
public
:
virtual
void
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
class
Listener
};
{
public
:
public
:
virtual
void
onRTCTCPConnectionClosed
(
RTC
::
TCPServer
*
tcpServer
,
RTC
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
static
void
ClassInit
();
};
static
RTC
::
TCPServer
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
TCPServer
*
servers
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_tcp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
public
:
public
:
TCPServer
(
uv_tcp_t
*
uvHandle
);
static
void
ClassInit
();
static
RTC
::
TCPServer
*
New
(
int
address_family
);
void
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
);
static
void
NewPair
(
int
address_family
,
RTC
::
TCPServer
*
servers
[]);
/* Pure virtual methods inherited from ::TCPServer. */
private
:
public
:
static
void
RandomizePort
(
int
address_family
,
uv_tcp_t
*
uvHandles
[],
bool
pair
);
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
private
:
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
virtual
void
userOnTCPServerClosed
()
override
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
private
:
static
MS_PORT
maxPort
;
// Passed by argument:
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
Listener
*
listener
=
nullptr
;
static
AvailablePorts
availableIPv4Ports
;
RTC
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
static
AvailablePorts
availableIPv6Ports
;
};
public
:
TCPServer
(
uv_tcp_t
*
uvHandle
);
/* Inline methods. */
void
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
);
inline
/* Pure virtual methods inherited from ::TCPServer. */
void
TCPServer
::
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
)
{
public
:
this
->
listener
=
listener
;
virtual
void
userOnTCPConnectionAlloc
(
::
TCPConnection
**
connection
)
override
;
this
->
reader
=
reader
;
virtual
void
userOnNewTCPConnection
(
::
TCPConnection
*
connection
)
override
;
}
virtual
void
userOnTCPConnectionClosed
(
::
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
override
;
virtual
void
userOnTCPServerClosed
()
override
;
private
:
// Passed by argument:
Listener
*
listener
=
nullptr
;
RTC
::
TCPConnection
::
Reader
*
reader
=
nullptr
;
};
/* Inline methods. */
inline
void
TCPServer
::
SetListeners
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Reader
*
reader
)
{
this
->
listener
=
listener
;
this
->
reader
=
reader
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/Transport.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/RTC/TransportSource.h
浏览文件 @
6262224c
#ifndef MS_RTC_TRANSPORT_SOURCE_H
#ifndef MS_RTC_TRANSPORT_SOURCE_H
#define MS_RTC_TRANSPORT_SOURCE_H
#define MS_RTC_TRANSPORT_SOURCE_H
#include "common.h"
#include "common.h"
#include "RTC/UDPSocket.h"
#include "RTC/UDPSocket.h"
#include "RTC/TCPConnection.h"
#include "RTC/TCPConnection.h"
#include "Utils.h"
#include "Utils.h"
#include <string>
#include <string>
namespace
RTC
namespace
RTC
{
{
class
TransportSource
{
class
TransportSource
{
public
:
public
:
enum
class
Type
enum
class
Type
{
{
UDP
=
1
,
UDP
=
1
,
TCP
TCP
};
public
:
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
);
void
StoreUdpRemoteAddress
();
bool
IsUDP
();
bool
IsTCP
();
bool
Compare
(
TransportSource
*
source
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
const
struct
sockaddr
*
GetRemoteAddress
();
void
Close
();
void
Dump
();
private
:
// Passed by argument:
RTC
::
UDPSocket
*
udpSocket
=
nullptr
;
struct
sockaddr
*
udpRemoteAddr
=
nullptr
;
sockaddr_storage
udpRemoteAddrStorage
;
RTC
::
TCPConnection
*
tcpConnection
=
nullptr
;
// Others:
Type
type
;
};
};
public
:
/* Inline methods. */
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
);
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
);
inline
TransportSource
::
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
void
StoreUdpRemoteAddress
();
udpSocket
(
udpSocket
),
bool
IsUDP
();
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
bool
IsTCP
();
type
(
Type
::
UDP
)
bool
Compare
(
TransportSource
*
source
);
{}
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
const
struct
sockaddr
*
GetRemoteAddress
();
inline
void
Close
();
TransportSource
::
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
)
:
void
Dump
();
tcpConnection
(
tcpConnection
),
type
(
Type
::
TCP
)
private
:
{}
// Passed by argument:
RTC
::
UDPSocket
*
udpSocket
=
nullptr
;
inline
struct
sockaddr
*
udpRemoteAddr
=
nullptr
;
void
TransportSource
::
StoreUdpRemoteAddress
()
sockaddr_storage
udpRemoteAddrStorage
;
{
RTC
::
TCPConnection
*
tcpConnection
=
nullptr
;
// Clone the given address into our address storage and make the sockaddr
// Others:
// pointer point to it.
Type
type
;
this
->
udpRemoteAddrStorage
=
Utils
::
IP
::
CopyAddress
(
udpRemoteAddr
);
};
this
->
udpRemoteAddr
=
(
struct
sockaddr
*
)
&
this
->
udpRemoteAddrStorage
;
/* Inline methods. */
inline
TransportSource
::
TransportSource
(
RTC
::
UDPSocket
*
udpSocket
,
const
struct
sockaddr
*
udpRemoteAddr
)
:
udpSocket
(
udpSocket
),
udpRemoteAddr
((
struct
sockaddr
*
)
udpRemoteAddr
),
type
(
Type
::
UDP
)
{}
inline
TransportSource
::
TransportSource
(
RTC
::
TCPConnection
*
tcpConnection
)
:
tcpConnection
(
tcpConnection
),
type
(
Type
::
TCP
)
{}
inline
void
TransportSource
::
StoreUdpRemoteAddress
()
{
// Clone the given address into our address storage and make the sockaddr
// pointer point to it.
this
->
udpRemoteAddrStorage
=
Utils
::
IP
::
CopyAddress
(
udpRemoteAddr
);
this
->
udpRemoteAddr
=
(
struct
sockaddr
*
)
&
this
->
udpRemoteAddrStorage
;
}
inline
bool
TransportSource
::
IsUDP
()
{
return
(
this
->
type
==
Type
::
UDP
);
}
inline
bool
TransportSource
::
IsTCP
()
{
return
(
this
->
type
==
Type
::
TCP
);
}
inline
bool
TransportSource
::
Compare
(
TransportSource
*
source
)
{
if
(
this
->
type
==
Type
::
UDP
&&
source
->
IsUDP
())
{
return
(
this
->
udpSocket
==
source
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
source
->
GetRemoteAddress
()));
}
}
else
if
(
this
->
type
==
Type
::
TCP
&&
source
->
IsTCP
())
{
return
(
this
->
tcpConnection
==
source
->
tcpConnection
);
}
else
{
return
false
;
}
}
inline
void
TransportSource
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
{
if
(
this
->
type
==
Type
::
UDP
)
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
else
this
->
tcpConnection
->
Send
(
data
,
len
);
}
inline
bool
TransportSource
::
IsUDP
()
{
return
(
this
->
type
==
Type
::
UDP
);
}
inline
inline
const
struct
sockaddr
*
TransportSource
::
GetRemoteAddress
()
{
bool
TransportSource
::
IsTCP
()
if
(
this
->
type
==
Type
::
UDP
)
{
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
return
(
this
->
type
==
Type
::
TCP
);
else
}
return
this
->
tcpConnection
->
GetPeerAddress
();
}
inline
bool
TransportSource
::
Compare
(
TransportSource
*
source
)
{
if
(
this
->
type
==
Type
::
UDP
&&
source
->
IsUDP
())
{
return
(
this
->
udpSocket
==
source
->
udpSocket
&&
Utils
::
IP
::
CompareAddresses
(
this
->
udpRemoteAddr
,
source
->
GetRemoteAddress
()));
}
else
if
(
this
->
type
==
Type
::
TCP
&&
source
->
IsTCP
())
{
return
(
this
->
tcpConnection
==
source
->
tcpConnection
);
}
else
{
return
false
;
}
}
inline
inline
void
TransportSource
::
Close
()
{
void
TransportSource
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
if
(
this
->
type
==
Type
::
TCP
)
{
this
->
tcpConnection
->
Close
();
if
(
this
->
type
==
Type
::
UDP
)
}
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
else
this
->
tcpConnection
->
Send
(
data
,
len
);
}
inline
const
struct
sockaddr
*
TransportSource
::
GetRemoteAddress
()
{
if
(
this
->
type
==
Type
::
UDP
)
return
(
const
struct
sockaddr
*
)
this
->
udpRemoteAddr
;
else
return
this
->
tcpConnection
->
GetPeerAddress
();
}
inline
void
TransportSource
::
Close
()
{
if
(
this
->
type
==
Type
::
TCP
)
this
->
tcpConnection
->
Close
();
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/RTC/UDPSocket.h
浏览文件 @
6262224c
#ifndef MS_RTC_UDP_SOCKET_H
#ifndef MS_RTC_UDP_SOCKET_H
#define MS_RTC_UDP_SOCKET_H
#define MS_RTC_UDP_SOCKET_H
#include "common.h"
#include "common.h"
#include "handles/UDPSocket.h"
#include "handles/UDPSocket.h"
#include <unordered_map>
#include <unordered_map>
#include <uv.h>
#include <uv.h>
namespace
RTC
namespace
RTC
{
{
class
UDPSocket
:
public
::
UDPSocket
{
class
UDPSocket
:
public
::
UDPSocket
{
public
:
class
Listener
{
public
:
public
:
virtual
void
onSTUNDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
class
Listener
virtual
void
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
{
virtual
void
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
public
:
virtual
void
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onSTUNDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
};
virtual
void
onDTLSDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onRTPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
public
:
virtual
void
onRTCPDataRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
static
void
ClassInit
();
};
static
RTC
::
UDPSocket
*
New
(
int
address_family
);
static
void
NewPair
(
int
address_family
,
RTC
::
UDPSocket
*
sockets
[]);
private
:
static
void
RandomizePort
(
int
address_family
,
uv_udp_t
*
uvHandles
[],
bool
pair
);
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
public
:
public
:
UDPSocket
(
uv_udp_t
*
uvHandle
);
static
void
ClassInit
();
static
RTC
::
UDPSocket
*
New
(
int
address_family
);
void
SetListener
(
Listener
*
listener
);
static
void
NewPair
(
int
address_family
,
RTC
::
UDPSocket
*
sockets
[]);
/* Pure virtual methods inherited from ::UDPSocket. */
private
:
public
:
static
void
RandomizePort
(
int
address_family
,
uv_udp_t
*
uvHandles
[],
bool
pair
);
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
MS_PORT
maxPort
;
typedef
std
::
unordered_map
<
MS_PORT
,
bool
>
AvailablePorts
;
static
AvailablePorts
availableIPv4Ports
;
static
AvailablePorts
availableIPv6Ports
;
private
:
public
:
// Passed by argument:
UDPSocket
(
uv_udp_t
*
uvHandle
);
Listener
*
listener
=
nullptr
;
};
void
SetListener
(
Listener
*
listener
);
/* Inline methods. */
/* Pure virtual methods inherited from ::UDPSocket. */
public
:
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
inline
private
:
void
UDPSocket
::
SetListener
(
Listener
*
listener
)
{
// Passed by argument:
this
->
listener
=
listene
r
;
Listener
*
listener
=
nullpt
r
;
}
};
/* Inline methods. */
inline
void
UDPSocket
::
SetListener
(
Listener
*
listener
)
{
this
->
listener
=
listener
;
}
}
// namespace RTC
}
// namespace RTC
#endif
#endif
include/Settings.h
浏览文件 @
6262224c
#ifndef MS_SETTINGS_H
#ifndef MS_SETTINGS_H
#define MS_SETTINGS_H
#define MS_SETTINGS_H
#include "common.h"
#include "common.h"
#include <map>
#include <map>
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <libconfig.h++>
#include <libconfig.h++>
extern
"C"
{
extern
"C"
{
#include <syslog.h>
#include <syslog.h>
}
}
class
Settings
class
Settings
{
{
public
:
public
:
// Struct holding command line arguments.
// Struct holding command line arguments.
struct
Arguments
{
struct
Arguments
{
std
::
string
configFile
;
std
::
string
configFile
;
bool
daemonize
{
false
};
bool
daemonize
{
false
};
std
::
string
pidFile
;
std
::
string
pidFile
;
...
@@ -24,17 +25,20 @@ public:
...
@@ -24,17 +25,20 @@ public:
};
};
// Struct holding the configuration (can be overriden by a config file).
// Struct holding the configuration (can be overriden by a config file).
struct
Configuration
{
struct
Configuration
{
unsigned
int
logLevel
{
LOG_DEBUG
};
unsigned
int
logLevel
{
LOG_DEBUG
};
unsigned
int
syslogFacility
{
LOG_USER
};
unsigned
int
syslogFacility
{
LOG_USER
};
int
numWorkers
{
0
};
int
numWorkers
{
0
};
struct
{
struct
{
std
::
string
listenIP
{
"127.0.0.1"
};
std
::
string
listenIP
{
"127.0.0.1"
};
MS_PORT
listenPort
{
4080
};
MS_PORT
listenPort
{
4080
};
}
ControlProtocol
;
}
ControlProtocol
;
struct
{
struct
{
std
::
string
listenIPv4
;
std
::
string
listenIPv4
;
std
::
string
listenIPv6
;
std
::
string
listenIPv6
;
MS_PORT
minPort
{
10000
};
MS_PORT
minPort
{
10000
};
...
@@ -83,5 +87,4 @@ private:
...
@@ -83,5 +87,4 @@ private:
static
std
::
map
<
unsigned
int
,
std
::
string
>
syslogFacility2String
;
static
std
::
map
<
unsigned
int
,
std
::
string
>
syslogFacility2String
;
};
};
#endif
#endif
include/Utils.h
浏览文件 @
6262224c
差异被折叠。
点击展开。
include/Version.h
浏览文件 @
6262224c
#ifndef MS_VERSION_H
#ifndef MS_VERSION_H
#define MS_VERSION_H
#define MS_VERSION_H
#include <string>
#include <string>
class
Version
class
Version
{
{
public
:
public
:
static
const
std
::
string
GetVersion
();
static
const
std
::
string
GetVersion
();
static
const
std
::
string
GetNameAndVersion
();
static
const
std
::
string
GetNameAndVersion
();
...
@@ -19,5 +18,4 @@ public:
...
@@ -19,5 +18,4 @@ public:
static
const
std
::
string
copyright
;
static
const
std
::
string
copyright
;
};
};
#endif
#endif
include/Worker.h
浏览文件 @
6262224c
#ifndef MS_WORKER_H
#ifndef MS_WORKER_H
#define MS_WORKER_H
#define MS_WORKER_H
#include "common.h"
#include "common.h"
#include "ControlProtocol/UnixStreamSocket.h"
#include "ControlProtocol/UnixStreamSocket.h"
#include "ControlProtocol/Message.h"
#include "ControlProtocol/Message.h"
...
@@ -10,7 +9,6 @@
...
@@ -10,7 +9,6 @@
// TMP
// TMP
#include "RTC/Room.h"
#include "RTC/Room.h"
class
Worker
:
class
Worker
:
public
ControlProtocol
::
UnixStreamSocket
::
Listener
public
ControlProtocol
::
UnixStreamSocket
::
Listener
{
{
...
@@ -53,5 +51,4 @@ private:
...
@@ -53,5 +51,4 @@ private:
RTC
::
Room
*
room
=
nullptr
;
RTC
::
Room
*
room
=
nullptr
;
};
};
#endif
#endif
include/common.h
浏览文件 @
6262224c
#ifndef MS_COMMON_H
#ifndef MS_COMMON_H
#define MS_COMMON_H
#define MS_COMMON_H
#include <cstddef> // size_t
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <cstdint> // uint8_t, 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
...
@@ -9,14 +8,12 @@
...
@@ -9,14 +8,12 @@
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <pthread.h> // __thread
#include <pthread.h> // __thread
#define MS_BYTE uint8_t
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
#define MS_2BYTES uint16_t
#define MS_4BYTES uint32_t
#define MS_4BYTES uint32_t
#define MS_8BYTES uint64_t
#define MS_8BYTES uint64_t
#define MS_PORT uint16_t
#define MS_PORT uint16_t
// Detect Little-Endian or Big-Endian CPU.
// Detect Little-Endian or Big-Endian CPU.
// NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined
// NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined
// then don't autodetect it.
// then don't autodetect it.
...
...
include/handles/SignalsHandler.h
浏览文件 @
6262224c
#ifndef MS_SIGNALS_HANDLER_H
#ifndef MS_SIGNALS_HANDLER_H
#define MS_SIGNALS_HANDLER_H
#define MS_SIGNALS_HANDLER_H
#include <vector>
#include <vector>
#include <string>
#include <string>
#include <uv.h>
#include <uv.h>
class
SignalsHandler
class
SignalsHandler
{
{
public
:
public
:
class
Listener
{
class
Listener
{
public
:
public
:
virtual
void
onSignal
(
SignalsHandler
*
signalsHandler
,
int
signum
)
=
0
;
virtual
void
onSignal
(
SignalsHandler
*
signalsHandler
,
int
signum
)
=
0
;
virtual
void
onSignalsHandlerClosed
(
SignalsHandler
*
signalsHandler
)
=
0
;
virtual
void
onSignalsHandlerClosed
(
SignalsHandler
*
signalsHandler
)
=
0
;
...
@@ -33,5 +33,4 @@ private:
...
@@ -33,5 +33,4 @@ private:
Listener
*
listener
=
nullptr
;
Listener
*
listener
=
nullptr
;
};
};
#endif
#endif
include/handles/TCPConnection.h
浏览文件 @
6262224c
#ifndef MS_TCP_CONNECTION_H
#ifndef MS_TCP_CONNECTION_H
#define MS_TCP_CONNECTION_H
#define MS_TCP_CONNECTION_H
#include "common.h"
#include "common.h"
#include <string>
#include <string>
#include <uv.h>
#include <uv.h>
class
TCPConnection
class
TCPConnection
{
{
public
:
public
:
class
Listener
{
class
Listener
{
public
:
public
:
virtual
void
onTCPConnectionClosed
(
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
virtual
void
onTCPConnectionClosed
(
TCPConnection
*
connection
,
bool
is_closed_by_peer
)
=
0
;
};
};
public
:
public
:
/* Struct for the data field of uv_req_t when writing into the connection. */
/* Struct for the data field of uv_req_t when writing into the connection. */
typedef
struct
UvWriteData
{
typedef
struct
UvWriteData
{
TCPConnection
*
connection
;
TCPConnection
*
connection
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
...
@@ -82,61 +83,60 @@ protected:
...
@@ -82,61 +83,60 @@ protected:
MS_PORT
peerPort
=
0
;
MS_PORT
peerPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
uv_tcp_t
*
TCPConnection
::
GetUvHandle
()
{
uv_tcp_t
*
TCPConnection
::
GetUvHandle
()
{
return
this
->
uvHandle
;
return
this
->
uvHandle
;
}
}
inline
inline
void
TCPConnection
::
Write
(
const
std
::
string
&
data
)
{
void
TCPConnection
::
Write
(
const
std
::
string
&
data
)
{
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
}
}
inline
inline
const
std
::
string
&
TCPConnection
::
GetLocalIP
()
{
const
std
::
string
&
TCPConnection
::
GetLocalIP
()
{
return
this
->
localIP
;
return
this
->
localIP
;
}
}
inline
inline
MS_PORT
TCPConnection
::
GetLocalPort
()
{
MS_PORT
TCPConnection
::
GetLocalPort
()
{
return
this
->
localPort
;
return
this
->
localPort
;
}
}
inline
inline
const
struct
sockaddr
*
TCPConnection
::
GetPeerAddress
()
{
const
struct
sockaddr
*
TCPConnection
::
GetPeerAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
peerAddr
;
return
(
const
struct
sockaddr
*
)
&
this
->
peerAddr
;
}
}
inline
inline
const
std
::
string
&
TCPConnection
::
GetPeerIP
()
{
const
std
::
string
&
TCPConnection
::
GetPeerIP
()
{
return
this
->
peerIP
;
return
this
->
peerIP
;
}
}
inline
inline
MS_PORT
TCPConnection
::
GetPeerPort
()
{
MS_PORT
TCPConnection
::
GetPeerPort
()
{
return
this
->
peerPort
;
return
this
->
peerPort
;
}
}
inline
inline
void
TCPConnection
::
SetUserData
(
void
*
userData
)
{
void
TCPConnection
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
this
->
userData
=
userData
;
}
}
inline
inline
void
*
TCPConnection
::
GetUserData
()
{
void
*
TCPConnection
::
GetUserData
()
{
return
this
->
userData
;
return
this
->
userData
;
}
}
#endif
#endif
include/handles/TCPServer.h
浏览文件 @
6262224c
#ifndef MS_TCP_SERVER_H
#ifndef MS_TCP_SERVER_H
#define MS_TCP_SERVER_H
#define MS_TCP_SERVER_H
#include "common.h"
#include "common.h"
#include "handles/TCPConnection.h"
#include "handles/TCPConnection.h"
#include <string>
#include <string>
#include <unordered_set>
#include <unordered_set>
#include <uv.h>
#include <uv.h>
class
TCPServer
:
public
TCPConnection
::
Listener
class
TCPServer
:
public
TCPConnection
::
Listener
{
{
public
:
public
:
TCPServer
(
const
std
::
string
&
ip
,
MS_PORT
port
,
int
backlog
);
TCPServer
(
const
std
::
string
&
ip
,
MS_PORT
port
,
int
backlog
);
/**
/**
...
@@ -63,31 +62,30 @@ protected:
...
@@ -63,31 +62,30 @@ protected:
MS_PORT
localPort
=
0
;
MS_PORT
localPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
void
TCPServer
::
SetUserData
(
void
*
userData
)
{
void
TCPServer
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
this
->
userData
=
userData
;
}
}
inline
inline
void
*
TCPServer
::
GetUserData
()
{
void
*
TCPServer
::
GetUserData
()
{
return
this
->
userData
;
return
this
->
userData
;
}
}
inline
inline
size_t
TCPServer
::
GetNumConnections
()
{
size_t
TCPServer
::
GetNumConnections
()
{
return
this
->
connections
.
size
();
return
this
->
connections
.
size
();
}
}
inline
inline
bool
TCPServer
::
IsClosing
()
{
bool
TCPServer
::
IsClosing
()
{
return
this
->
isClosing
;
return
this
->
isClosing
;
}
}
#endif
#endif
include/handles/Timer.h
浏览文件 @
6262224c
#ifndef MS_TIMER_H
#ifndef MS_TIMER_H
#define MS_TIMER_H
#define MS_TIMER_H
#include "common.h"
#include "common.h"
#include <uv.h>
#include <uv.h>
class
Timer
class
Timer
{
{
public
:
public
:
class
Listener
{
class
Listener
{
public
:
public
:
virtual
void
onTimer
(
Timer
*
timer
)
=
0
;
virtual
void
onTimer
(
Timer
*
timer
)
=
0
;
};
};
...
@@ -31,5 +31,4 @@ private:
...
@@ -31,5 +31,4 @@ private:
Listener
*
listener
=
nullptr
;
Listener
*
listener
=
nullptr
;
};
};
#endif
#endif
include/handles/UDPSocket.h
浏览文件 @
6262224c
#ifndef MS_UDP_SOCKET_H
#ifndef MS_UDP_SOCKET_H
#define MS_UDP_SOCKET_H
#define MS_UDP_SOCKET_H
#include "common.h"
#include "common.h"
#include <string>
#include <string>
#include <uv.h>
#include <uv.h>
class
UDPSocket
class
UDPSocket
{
{
public
:
public
:
/* Struct for the data field of uv_req_t when sending a datagram. */
/* Struct for the data field of uv_req_t when sending a datagram. */
typedef
struct
UvSendData
{
typedef
struct
UvSendData
{
UDPSocket
*
socket
;
UDPSocket
*
socket
;
uv_udp_send_t
req
;
uv_udp_send_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
...
@@ -68,49 +68,48 @@ protected:
...
@@ -68,49 +68,48 @@ protected:
MS_PORT
localPort
=
0
;
MS_PORT
localPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
{
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
)
{
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
addr
);
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
addr
);
}
}
inline
inline
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
MS_PORT
port
)
{
void
UDPSocket
::
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
MS_PORT
port
)
{
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
}
}
inline
inline
const
struct
sockaddr
*
UDPSocket
::
GetLocalAddress
()
{
const
struct
sockaddr
*
UDPSocket
::
GetLocalAddress
()
{
return
(
const
struct
sockaddr
*
)
&
this
->
localAddr
;
return
(
const
struct
sockaddr
*
)
&
this
->
localAddr
;
}
}
inline
inline
const
std
::
string
&
UDPSocket
::
GetLocalIP
()
{
const
std
::
string
&
UDPSocket
::
GetLocalIP
()
{
return
this
->
localIP
;
return
this
->
localIP
;
}
}
inline
inline
MS_PORT
UDPSocket
::
GetLocalPort
()
{
MS_PORT
UDPSocket
::
GetLocalPort
()
{
return
this
->
localPort
;
return
this
->
localPort
;
}
}
inline
inline
void
UDPSocket
::
SetUserData
(
void
*
userData
)
{
void
UDPSocket
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
this
->
userData
=
userData
;
}
}
inline
inline
void
*
UDPSocket
::
GetUserData
()
{
void
*
UDPSocket
::
GetUserData
()
{
return
this
->
userData
;
return
this
->
userData
;
}
}
#endif
#endif
include/handles/UnixStreamSocket.h
浏览文件 @
6262224c
#ifndef MS_UNIX_STREAM_SOCKET_H
#ifndef MS_UNIX_STREAM_SOCKET_H
#define MS_UNIX_STREAM_SOCKET_H
#define MS_UNIX_STREAM_SOCKET_H
#include "common.h"
#include "common.h"
#include <string>
#include <string>
#include <uv.h>
#include <uv.h>
class
UnixStreamSocket
class
UnixStreamSocket
{
{
public
:
public
:
/* Struct for the data field of uv_req_t when writing data. */
/* Struct for the data field of uv_req_t when writing data. */
typedef
struct
UvWriteData
{
typedef
struct
UvWriteData
{
UnixStreamSocket
*
socket
;
UnixStreamSocket
*
socket
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
MS_BYTE
store
[
1
];
...
@@ -59,25 +59,24 @@ protected:
...
@@ -59,25 +59,24 @@ protected:
size_t
bufferDataLen
=
0
;
size_t
bufferDataLen
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
void
UnixStreamSocket
::
Write
(
const
std
::
string
&
data
)
{
void
UnixStreamSocket
::
Write
(
const
std
::
string
&
data
)
{
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
Write
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
());
}
}
inline
inline
void
UnixStreamSocket
::
SetUserData
(
void
*
userData
)
{
void
UnixStreamSocket
::
SetUserData
(
void
*
userData
)
{
this
->
userData
=
userData
;
this
->
userData
=
userData
;
}
}
inline
inline
void
*
UnixStreamSocket
::
GetUserData
()
{
void
*
UnixStreamSocket
::
GetUserData
()
{
return
this
->
userData
;
return
this
->
userData
;
}
}
#endif
#endif
src/ControlProtocol/Message.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Parser.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Parser.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/Request.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/UnixStreamSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/grammar/RequestAuthenticate.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/grammar/RequestCreateConference.rl
浏览文件 @
6262224c
%%{
%%{
machine RequestCreateConference;
machine RequestCreateConference;
action on_request_type_CreateConference {
action on_request_type_CreateConference
{
this->msg = new ControlProtocol::RequestCreateConference();
this->msg = new ControlProtocol::RequestCreateConference();
}
}
...
...
src/ControlProtocol/grammar/RequestHello.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestAuthenticate.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestCreateConference.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/ControlProtocol/messages/RequestHello.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Daemon.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Dispatcher.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/LibSRTP.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/LibUV.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Logger.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/MediaSoup.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/OpenSSL.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/DTLSHandler.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/ICEServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Peer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/RTCPPacket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/RTPPacket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Room.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/SRTPSession.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/STUNMessage.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Stream.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/Transport.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/TransportSource.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/RTC/UDPSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Settings.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/Crypto.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/File.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/IP.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/IP.rl
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Utils/Socket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Version.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/Worker.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/SignalsHandler.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/TCPConnection.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/TCPServer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/Timer.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/UDPSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/handles/UnixStreamSocket.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
src/main.cpp
浏览文件 @
6262224c
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论