Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
a675da25
提交
a675da25
authored
1月 17, 2016
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace stupid MSX_BYTES macros with uintX_t.
上级
5c3b2180
全部展开
显示空白字符变更
内嵌
并排
正在显示
41 个修改的文件
包含
331 行增加
和
329 行删除
+331
-329
UnixStreamSocket.h
worker/include/Channel/UnixStreamSocket.h
+1
-1
DTLSTransport.h
worker/include/RTC/DTLSTransport.h
+8
-8
IceCandidate.h
worker/include/RTC/IceCandidate.h
+1
-1
RTCPPacket.h
worker/include/RTC/RTCPPacket.h
+15
-15
RTPPacket.h
worker/include/RTC/RTPPacket.h
+45
-45
RtpReceiver.h
worker/include/RTC/RtpReceiver.h
+8
-0
SRTPSession.h
worker/include/RTC/SRTPSession.h
+6
-6
STUNMessage.h
worker/include/RTC/STUNMessage.h
+36
-36
TCPConnection.h
worker/include/RTC/TCPConnection.h
+2
-2
TCPServer.h
worker/include/RTC/TCPServer.h
+4
-4
Transport.h
worker/include/RTC/Transport.h
+11
-11
TransportTuple.h
worker/include/RTC/TransportTuple.h
+2
-2
UDPSocket.h
worker/include/RTC/UDPSocket.h
+6
-6
Settings.h
worker/include/Settings.h
+2
-2
Utils.h
worker/include/Utils.h
+53
-53
common.h
worker/include/common.h
+0
-6
TCPConnection.h
worker/include/handles/TCPConnection.h
+12
-12
TCPServer.h
worker/include/handles/TCPServer.h
+3
-3
Timer.h
worker/include/handles/Timer.h
+1
-1
UDPSocket.h
worker/include/handles/UDPSocket.h
+13
-13
UnixStreamSocket.h
worker/include/handles/UnixStreamSocket.h
+4
-4
UnixStreamSocket.cpp
worker/src/Channel/UnixStreamSocket.cpp
+2
-2
DTLSTransport.cpp
worker/src/RTC/DTLSTransport.cpp
+14
-14
RTCPPacket.cpp
worker/src/RTC/RTCPPacket.cpp
+3
-3
RTPPacket.cpp
worker/src/RTC/RTPPacket.cpp
+8
-8
SRTPSession.cpp
worker/src/RTC/SRTPSession.cpp
+8
-8
STUNMessage.cpp
worker/src/RTC/STUNMessage.cpp
+0
-0
TCPConnection.cpp
worker/src/RTC/TCPConnection.cpp
+3
-3
TCPServer.cpp
worker/src/RTC/TCPServer.cpp
+10
-10
Transport.cpp
worker/src/RTC/Transport.cpp
+10
-10
TransportTuple.cpp
worker/src/RTC/TransportTuple.cpp
+2
-2
UDPSocket.cpp
worker/src/RTC/UDPSocket.cpp
+12
-12
Settings.cpp
worker/src/Settings.cpp
+3
-3
Crypto.cpp
worker/src/Utils/Crypto.cpp
+3
-3
IP.cpp
worker/src/Utils/IP.cpp
+3
-3
IP.rl
worker/src/Utils/IP.rl
+3
-3
TCPConnection.cpp
worker/src/handles/TCPConnection.cpp
+4
-4
TCPServer.cpp
worker/src/handles/TCPServer.cpp
+2
-2
Timer.cpp
worker/src/handles/Timer.cpp
+1
-1
UDPSocket.cpp
worker/src/handles/UDPSocket.cpp
+5
-5
UnixStreamSocket.cpp
worker/src/handles/UnixStreamSocket.cpp
+2
-2
没有找到文件。
worker/include/Channel/UnixStreamSocket.h
浏览文件 @
a675da25
...
@@ -23,7 +23,7 @@ namespace Channel
...
@@ -23,7 +23,7 @@ namespace Channel
};
};
private
:
private
:
static
MS_BYTE
writeBuffer
[];
static
uint8_t
writeBuffer
[];
public
:
public
:
UnixStreamSocket
(
int
fd
);
UnixStreamSocket
(
int
fd
);
...
...
worker/include/RTC/DTLSTransport.h
浏览文件 @
a675da25
...
@@ -73,7 +73,7 @@ namespace RTC
...
@@ -73,7 +73,7 @@ namespace RTC
// DTLS has completed negotiation of a secure connection (including DTLS-SRTP
// DTLS has completed negotiation of a secure connection (including DTLS-SRTP
// and remote fingerprint verification). Outgoing media can now flow through.
// and remote fingerprint verification). Outgoing media can now flow through.
// NOTE: The caller MUST NOT call any method during this callback.
// NOTE: The caller MUST NOT call any method during this callback.
virtual
void
onDTLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
virtual
void
onDTLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
=
0
;
// The DTLS connection has been closed as the result of an error (such as a
// The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint).
// DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Close() during this callback.
// NOTE: The caller MUST NOT call Close() during this callback.
...
@@ -83,10 +83,10 @@ namespace RTC
...
@@ -83,10 +83,10 @@ namespace RTC
virtual
void
onDTLSClosed
(
DTLSTransport
*
dtlsTransport
)
=
0
;
virtual
void
onDTLSClosed
(
DTLSTransport
*
dtlsTransport
)
=
0
;
// Need to send DTLS data to the peer.
// Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Close() during this callback.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onOutgoingDTLSData
(
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onOutgoingDTLSData
(
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
// DTLS application data received.
// DTLS application data received.
// NOTE: The caller MUST NOT call Close() during this callback.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual
void
onDTLSApplicationData
(
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onDTLSApplicationData
(
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
};
};
public
:
public
:
...
@@ -95,7 +95,7 @@ namespace RTC
...
@@ -95,7 +95,7 @@ namespace RTC
static
Json
::
Value
&
GetLocalFingerprints
();
static
Json
::
Value
&
GetLocalFingerprints
();
static
Role
StringToRole
(
std
::
string
role
);
static
Role
StringToRole
(
std
::
string
role
);
static
FingerprintAlgorithm
GetFingerprintAlgorithm
(
std
::
string
fingerprint
);
static
FingerprintAlgorithm
GetFingerprintAlgorithm
(
std
::
string
fingerprint
);
static
bool
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsDTLS
(
const
uint8_t
*
data
,
size_t
len
);
private
:
private
:
static
void
GenerateCertificateAndPrivateKey
();
static
void
GenerateCertificateAndPrivateKey
();
...
@@ -107,7 +107,7 @@ namespace RTC
...
@@ -107,7 +107,7 @@ namespace RTC
static
X509
*
certificate
;
static
X509
*
certificate
;
static
EVP_PKEY
*
privateKey
;
static
EVP_PKEY
*
privateKey
;
static
SSL_CTX
*
sslCtx
;
static
SSL_CTX
*
sslCtx
;
static
MS_BYTE
sslReadBuffer
[];
static
uint8_t
sslReadBuffer
[];
static
std
::
map
<
std
::
string
,
Role
>
string2Role
;
static
std
::
map
<
std
::
string
,
Role
>
string2Role
;
static
std
::
map
<
std
::
string
,
FingerprintAlgorithm
>
string2FingerprintAlgorithm
;
static
std
::
map
<
std
::
string
,
FingerprintAlgorithm
>
string2FingerprintAlgorithm
;
static
Json
::
Value
localFingerprints
;
static
Json
::
Value
localFingerprints
;
...
@@ -121,10 +121,10 @@ namespace RTC
...
@@ -121,10 +121,10 @@ namespace RTC
void
Dump
();
void
Dump
();
void
Run
(
Role
localRole
);
void
Run
(
Role
localRole
);
void
SetRemoteFingerprint
(
Fingerprint
fingerprint
);
void
SetRemoteFingerprint
(
Fingerprint
fingerprint
);
void
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
ProcessDTLSData
(
const
uint8_t
*
data
,
size_t
len
);
DtlsState
GetState
();
DtlsState
GetState
();
Role
GetLocalRole
();
Role
GetLocalRole
();
void
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
);
void
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
);
private
:
private
:
bool
IsRunning
();
bool
IsRunning
();
...
@@ -192,7 +192,7 @@ namespace RTC
...
@@ -192,7 +192,7 @@ namespace RTC
}
}
inline
inline
bool
DTLSTransport
::
IsDTLS
(
const
MS_BYTE
*
data
,
size_t
len
)
bool
DTLSTransport
::
IsDTLS
(
const
uint8_t
*
data
,
size_t
len
)
{
{
return
(
return
(
// Minimum DTLS record length is 13 bytes.
// Minimum DTLS record length is 13 bytes.
...
...
worker/include/RTC/IceCandidate.h
浏览文件 @
a675da25
...
@@ -42,7 +42,7 @@ namespace RTC
...
@@ -42,7 +42,7 @@ namespace RTC
uint32_t
priority
;
uint32_t
priority
;
std
::
string
ip
;
std
::
string
ip
;
Protocol
protocol
;
Protocol
protocol
;
MS_PORT
port
;
uint16_t
port
;
CandidateType
type
;
CandidateType
type
;
TcpCandidateType
tcpType
;
TcpCandidateType
tcpType
;
};
};
...
...
worker/include/RTC/RTCPPacket.h
浏览文件 @
a675da25
...
@@ -12,40 +12,40 @@ namespace RTC
...
@@ -12,40 +12,40 @@ namespace RTC
struct
CommonHeader
struct
CommonHeader
{
{
#if defined(MS_LITTLE_ENDIAN)
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
count
:
5
;
uint8_t
count
:
5
;
MS_BYTE
padding
:
1
;
uint8_t
padding
:
1
;
MS_BYTE
version
:
2
;
uint8_t
version
:
2
;
#elif defined(MS_BIG_ENDIAN)
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
uint8_t
version
:
2
;
MS_BYTE
padding
:
1
;
uint8_t
padding
:
1
;
MS_BYTE
count
:
5
;
uint8_t
count
:
5
;
#endif
#endif
MS_BYTE
packet_type
:
8
;
uint8_t
packet_type
:
8
;
MS_2BYTES
length
:
16
;
uint16_t
length
:
16
;
};
};
public
:
public
:
static
bool
IsRTCP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsRTCP
(
const
uint8_t
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTCPPacket
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
public
:
public
:
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
);
RTCPPacket
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
);
~
RTCPPacket
();
~
RTCPPacket
();
const
MS_BYTE
*
GetRaw
();
const
uint8_t
*
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
;
uint8_t
*
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
uint8_t
*
data
,
size_t
len
)
{
{
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
CommonHeader
*
header
=
(
CommonHeader
*
)
data
;
...
@@ -65,7 +65,7 @@ namespace RTC
...
@@ -65,7 +65,7 @@ namespace RTC
/* Inline instance methods. */
/* Inline instance methods. */
inline
inline
const
MS_BYTE
*
RTCPPacket
::
GetRaw
()
const
uint8_t
*
RTCPPacket
::
GetRaw
()
{
{
return
this
->
raw
;
return
this
->
raw
;
}
}
...
...
worker/include/RTC/RTPPacket.h
浏览文件 @
a675da25
...
@@ -12,68 +12,68 @@ namespace RTC
...
@@ -12,68 +12,68 @@ namespace RTC
struct
Header
struct
Header
{
{
#if defined(MS_LITTLE_ENDIAN)
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE
csrc_count
:
4
;
uint8_t
csrc_count
:
4
;
MS_BYTE
extension
:
1
;
uint8_t
extension
:
1
;
MS_BYTE
padding
:
1
;
uint8_t
padding
:
1
;
MS_BYTE
version
:
2
;
uint8_t
version
:
2
;
MS_BYTE
payload_type
:
7
;
uint8_t
payload_type
:
7
;
MS_BYTE
marker
:
1
;
uint8_t
marker
:
1
;
#elif defined(MS_BIG_ENDIAN)
#elif defined(MS_BIG_ENDIAN)
MS_BYTE
version
:
2
;
uint8_t
version
:
2
;
MS_BYTE
padding
:
1
;
uint8_t
padding
:
1
;
MS_BYTE
extension
:
1
;
uint8_t
extension
:
1
;
MS_BYTE
csrc_count
:
4
;
uint8_t
csrc_count
:
4
;
MS_BYTE
marker
:
1
;
uint8_t
marker
:
1
;
MS_BYTE
payload_type
:
7
;
uint8_t
payload_type
:
7
;
#endif
#endif
MS_2BYTES
sequence_number
;
uint16_t
sequence_number
;
MS_4BYTES
timestamp
;
uint32_t
timestamp
;
MS_4BYTES
ssrc
;
uint32_t
ssrc
;
};
};
/* Struct for RTP header extension. */
/* Struct for RTP header extension. */
struct
ExtensionHeader
struct
ExtensionHeader
{
{
MS_2BYTES
id
;
uint16_t
id
;
MS_2BYTES
length
;
// Size of value in multiples of 4 bytes.
uint16_t
length
;
// Size of value in multiples of 4 bytes.
MS_BYTE
*
value
;
uint8_t
*
value
;
};
};
public
:
public
:
static
bool
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsRTP
(
const
uint8_t
*
data
,
size_t
len
);
static
RTPPacket
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
static
RTPPacket
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
public
:
public
:
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLen
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
);
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLen
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
);
~
RTPPacket
();
~
RTPPacket
();
void
Dump
();
void
Dump
();
const
MS_BYTE
*
GetRaw
();
const
uint8_t
*
GetRaw
();
size_t
GetLength
();
size_t
GetLength
();
MS_BYTE
GetPayloadType
();
uint8_t
GetPayloadType
();
void
SetPayloadType
(
MS_BYTE
payload_type
);
void
SetPayloadType
(
uint8_t
payload_type
);
bool
HasMarker
();
bool
HasMarker
();
void
SetMarker
(
bool
marker
);
void
SetMarker
(
bool
marker
);
MS_2BYTES
GetSequenceNumber
();
uint16_t
GetSequenceNumber
();
MS_4BYTES
GetTimestamp
();
uint32_t
GetTimestamp
();
MS_4BYTES
GetSSRC
();
uint32_t
GetSSRC
();
void
SetSSRC
(
MS_4BYTES
ssrc
);
void
SetSSRC
(
uint32_t
ssrc
);
bool
HasExtensionHeader
();
bool
HasExtensionHeader
();
MS_2BYTES
GetExtensionHeaderId
();
uint16_t
GetExtensionHeaderId
();
size_t
GetExtensionHeaderLength
();
size_t
GetExtensionHeaderLength
();
MS_BYTE
*
GetPayload
();
uint8_t
*
GetPayload
();
size_t
GetPayloadLength
();
size_t
GetPayloadLength
();
void
Serialize
();
void
Serialize
();
private
:
private
:
// Passed by argument.
// Passed by argument.
Header
*
header
=
nullptr
;
Header
*
header
=
nullptr
;
MS_BYTE
*
csrcList
=
nullptr
;
uint8_t
*
csrcList
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
ExtensionHeader
*
extensionHeader
=
nullptr
;
MS_BYTE
*
payload
=
nullptr
;
uint8_t
*
payload
=
nullptr
;
size_t
payloadLength
=
0
;
size_t
payloadLength
=
0
;
MS_BYTE
payloadPadding
=
0
;
uint8_t
payloadPadding
=
0
;
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
uint8_t
*
raw
=
nullptr
;
// Allocated when Serialize().
size_t
length
=
0
;
size_t
length
=
0
;
// Others.
// Others.
bool
isSerialized
=
false
;
bool
isSerialized
=
false
;
...
@@ -82,7 +82,7 @@ namespace RTC
...
@@ -82,7 +82,7 @@ namespace RTC
/* Inline static methods. */
/* Inline static methods. */
inline
inline
bool
RTPPacket
::
IsRTP
(
const
MS_BYTE
*
data
,
size_t
len
)
bool
RTPPacket
::
IsRTP
(
const
uint8_t
*
data
,
size_t
len
)
{
{
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
...
@@ -100,7 +100,7 @@ namespace RTC
...
@@ -100,7 +100,7 @@ namespace RTC
/* Inline instance methods. */
/* Inline instance methods. */
inline
inline
const
MS_BYTE
*
RTPPacket
::
GetRaw
()
const
uint8_t
*
RTPPacket
::
GetRaw
()
{
{
return
this
->
raw
;
return
this
->
raw
;
}
}
...
@@ -112,13 +112,13 @@ namespace RTC
...
@@ -112,13 +112,13 @@ namespace RTC
}
}
inline
inline
MS_BYTE
RTPPacket
::
GetPayloadType
()
uint8_t
RTPPacket
::
GetPayloadType
()
{
{
return
this
->
header
->
payload_type
;
return
this
->
header
->
payload_type
;
}
}
inline
inline
void
RTPPacket
::
SetPayloadType
(
MS_BYTE
payload_type
)
void
RTPPacket
::
SetPayloadType
(
uint8_t
payload_type
)
{
{
this
->
header
->
payload_type
=
payload_type
;
this
->
header
->
payload_type
=
payload_type
;
}
}
...
@@ -136,26 +136,26 @@ namespace RTC
...
@@ -136,26 +136,26 @@ namespace RTC
}
}
inline
inline
MS_2BYTES
RTPPacket
::
GetSequenceNumber
()
uint16_t
RTPPacket
::
GetSequenceNumber
()
{
{
return
ntohs
(
this
->
header
->
sequence_number
);
return
ntohs
(
this
->
header
->
sequence_number
);
}
}
inline
inline
MS_4BYTES
RTPPacket
::
GetTimestamp
()
uint32_t
RTPPacket
::
GetTimestamp
()
{
{
return
ntohl
(
this
->
header
->
timestamp
);
return
ntohl
(
this
->
header
->
timestamp
);
}
}
inline
inline
MS_4BYTES
RTPPacket
::
GetSSRC
()
uint32_t
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
(
uint32_t
ssrc
)
{
{
this
->
header
->
ssrc
=
htonl
(
ssrc
);
this
->
header
->
ssrc
=
htonl
(
ssrc
);
}
}
...
@@ -167,10 +167,10 @@ namespace RTC
...
@@ -167,10 +167,10 @@ namespace RTC
}
}
inline
inline
MS_2BYTES
RTPPacket
::
GetExtensionHeaderId
()
uint16_t
RTPPacket
::
GetExtensionHeaderId
()
{
{
if
(
this
->
extensionHeader
)
if
(
this
->
extensionHeader
)
return
MS_2BYTES
(
ntohs
(
this
->
extensionHeader
->
id
));
return
uint16_t
(
ntohs
(
this
->
extensionHeader
->
id
));
else
else
return
0
;
return
0
;
}
}
...
@@ -185,7 +185,7 @@ namespace RTC
...
@@ -185,7 +185,7 @@ namespace RTC
}
}
inline
inline
MS_BYTE
*
RTPPacket
::
GetPayload
()
uint8_t
*
RTPPacket
::
GetPayload
()
{
{
return
this
->
payload
;
return
this
->
payload
;
}
}
...
...
worker/include/RTC/RtpReceiver.h
浏览文件 @
a675da25
...
@@ -63,12 +63,20 @@ namespace RTC
...
@@ -63,12 +63,20 @@ namespace RTC
void
RtpReceiver
::
SetRtpListener
(
RtpListener
*
rtpListener
)
void
RtpReceiver
::
SetRtpListener
(
RtpListener
*
rtpListener
)
{
{
this
->
rtpListener
=
rtpListener
;
this
->
rtpListener
=
rtpListener
;
// If we already had rtpParameters then provide the new listener with them.
if
(
this
->
rtpParameters
)
this
->
rtpListener
->
onRtpListenerParameters
(
this
,
this
->
rtpParameters
);
}
}
inline
inline
void
RtpReceiver
::
SetRtpListenerForRtcp
(
RtpListener
*
rtcpListener
)
void
RtpReceiver
::
SetRtpListenerForRtcp
(
RtpListener
*
rtcpListener
)
{
{
this
->
rtcpListener
=
rtcpListener
;
this
->
rtcpListener
=
rtcpListener
;
// If we already had rtpParameters then provide the new listener with them.
if
(
this
->
rtpParameters
)
this
->
rtcpListener
->
onRtpListenerParameters
(
this
,
this
->
rtpParameters
);
}
}
inline
inline
...
...
worker/include/RTC/SRTPSession.h
浏览文件 @
a675da25
...
@@ -31,16 +31,16 @@ namespace RTC
...
@@ -31,16 +31,16 @@ namespace RTC
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
static
void
onSRTPEvent
(
srtp_event_data_t
*
data
);
private
:
private
:
static
MS_BYTE
encryptBuffer
[];
static
uint8_t
encryptBuffer
[];
public
:
public
:
SRTPSession
(
Type
type
,
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
);
SRTPSession
(
Type
type
,
SRTPProfile
profile
,
uint8_t
*
key
,
size_t
key_len
);
~
SRTPSession
();
~
SRTPSession
();
bool
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
EncryptRTP
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
bool
DecryptSRTP
(
const
uint8_t
*
data
,
size_t
*
len
);
bool
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
);
bool
EncryptRTCP
(
const
uint8_t
**
data
,
size_t
*
len
);
bool
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
);
bool
DecryptSRTCP
(
const
uint8_t
*
data
,
size_t
*
len
);
const
char
*
GetLastErrorDesc
();
const
char
*
GetLastErrorDesc
();
void
Close
();
void
Close
();
...
...
worker/include/RTC/STUNMessage.h
浏览文件 @
a675da25
...
@@ -10,7 +10,7 @@ namespace RTC
...
@@ -10,7 +10,7 @@ namespace RTC
{
{
public
:
public
:
// STUN message class.
// STUN message class.
enum
class
Class
:
MS_2BYTES
enum
class
Class
:
uint16_t
{
{
Request
=
0
,
Request
=
0
,
Indication
=
1
,
Indication
=
1
,
...
@@ -19,13 +19,13 @@ namespace RTC
...
@@ -19,13 +19,13 @@ namespace RTC
};
};
// STUN message method.
// STUN message method.
enum
class
Method
:
MS_2BYTES
enum
class
Method
:
uint16_t
{
{
Binding
=
1
Binding
=
1
};
};
// Attribute type.
// Attribute type.
enum
class
Attribute
:
MS_2BYTES
enum
class
Attribute
:
uint16_t
{
{
MappedAddress
=
0x0001
,
MappedAddress
=
0x0001
,
Username
=
0x0006
,
Username
=
0x0006
,
...
@@ -53,42 +53,42 @@ namespace RTC
...
@@ -53,42 +53,42 @@ namespace RTC
};
};
public
:
public
:
static
bool
IsSTUN
(
const
MS_BYTE
*
data
,
size_t
len
);
static
bool
IsSTUN
(
const
uint8_t
*
data
,
size_t
len
);
static
STUNMessage
*
Parse
(
const
MS_BYTE
*
data
,
size_t
len
);
static
STUNMessage
*
Parse
(
const
uint8_t
*
data
,
size_t
len
);
private
:
private
:
static
const
MS_BYTE
magicCookie
[];
static
const
uint8_t
magicCookie
[];
public
:
public
:
STUNMessage
(
Class
klass
,
Method
method
,
const
MS_BYTE
*
transactionId
,
const
MS_BYTE
*
raw
,
size_t
length
);
STUNMessage
(
Class
klass
,
Method
method
,
const
uint8_t
*
transactionId
,
const
uint8_t
*
raw
,
size_t
length
);
~
STUNMessage
();
~
STUNMessage
();
void
Dump
();
void
Dump
();
Class
GetClass
();
Class
GetClass
();
Method
GetMethod
();
Method
GetMethod
();
const
MS_BYTE
*
GetRaw
();
const
uint8_t
*
GetRaw
();
void
SetLength
(
size_t
length
);
void
SetLength
(
size_t
length
);
size_t
GetLength
();
size_t
GetLength
();
void
SetUsername
(
const
char
*
username
,
size_t
len
);
void
SetUsername
(
const
char
*
username
,
size_t
len
);
void
SetPriority
(
const
MS_4BYTES
priority
);
void
SetPriority
(
const
uint32_t
priority
);
void
SetIceControlling
(
const
MS_8BYTES
iceControlling
);
void
SetIceControlling
(
const
uint64_t
iceControlling
);
void
SetIceControlled
(
const
MS_8BYTES
iceControlled
);
void
SetIceControlled
(
const
uint64_t
iceControlled
);
void
SetUseCandidate
();
void
SetUseCandidate
();
void
SetXorMappedAddress
(
const
struct
sockaddr
*
xorMappedAddress
);
void
SetXorMappedAddress
(
const
struct
sockaddr
*
xorMappedAddress
);
void
SetErrorCode
(
MS_2BYTES
errorCode
);
void
SetErrorCode
(
uint16_t
errorCode
);
void
SetMessageIntegrity
(
const
MS_BYTE
*
messageIntegrity
);
void
SetMessageIntegrity
(
const
uint8_t
*
messageIntegrity
);
void
SetFingerprint
();
void
SetFingerprint
();
const
std
::
string
&
GetUsername
();
const
std
::
string
&
GetUsername
();
const
MS_4BYTES
GetPriority
();
const
uint32_t
GetPriority
();
const
MS_8BYTES
GetIceControlling
();
const
uint64_t
GetIceControlling
();
const
MS_8BYTES
GetIceControlled
();
const
uint64_t
GetIceControlled
();
bool
HasUseCandidate
();
bool
HasUseCandidate
();
MS_2BYTES
GetErrorCode
();
uint16_t
GetErrorCode
();
bool
HasMessageIntegrity
();
bool
HasMessageIntegrity
();
bool
HasFingerprint
();
bool
HasFingerprint
();
Authentication
CheckAuthentication
(
const
std
::
string
&
local_username
,
const
std
::
string
&
local_password
);
Authentication
CheckAuthentication
(
const
std
::
string
&
local_username
,
const
std
::
string
&
local_password
);
STUNMessage
*
CreateSuccessResponse
();
STUNMessage
*
CreateSuccessResponse
();
STUNMessage
*
CreateErrorResponse
(
MS_2BYTES
errorCode
);
STUNMessage
*
CreateErrorResponse
(
uint16_t
errorCode
);
void
Authenticate
(
const
std
::
string
&
password
);
void
Authenticate
(
const
std
::
string
&
password
);
void
Serialize
();
void
Serialize
();
...
@@ -96,28 +96,28 @@ namespace RTC
...
@@ -96,28 +96,28 @@ namespace RTC
// Passed by argument.
// Passed by argument.
Class
klass
;
// 2 bytes.
Class
klass
;
// 2 bytes.
Method
method
;
// 2 bytes.
Method
method
;
// 2 bytes.
const
MS_BYTE
*
transactionId
=
nullptr
;
// 12 bytes.
const
uint8_t
*
transactionId
=
nullptr
;
// 12 bytes.
MS_BYTE
*
raw
=
nullptr
;
// Allocated when Serialize().
uint8_t
*
raw
=
nullptr
;
// Allocated when Serialize().
size_t
length
=
0
;
// The full message size (including header).
size_t
length
=
0
;
// The full message size (including header).
// Others.
// Others.
bool
isSerialized
=
false
;
bool
isSerialized
=
false
;
// STUN attributes.
// STUN attributes.
std
::
string
username
;
// Less than 513 bytes.
std
::
string
username
;
// Less than 513 bytes.
MS_4BYTES
priority
=
0
;
// 4 bytes unsigned integer.
uint32_t
priority
=
0
;
// 4 bytes unsigned integer.
MS_8BYTES
iceControlling
=
0
;
// 8 bytes unsigned integer.
uint64_t
iceControlling
=
0
;
// 8 bytes unsigned integer.
MS_8BYTES
iceControlled
=
0
;
// 8 bytes unsigned integer.
uint64_t
iceControlled
=
0
;
// 8 bytes unsigned integer.
bool
hasUseCandidate
=
false
;
// 0 bytes.
bool
hasUseCandidate
=
false
;
// 0 bytes.
const
MS_BYTE
*
messageIntegrity
=
nullptr
;
// 20 bytes.
const
uint8_t
*
messageIntegrity
=
nullptr
;
// 20 bytes.
bool
hasFingerprint
=
false
;
// 4 bytes.
bool
hasFingerprint
=
false
;
// 4 bytes.
const
struct
sockaddr
*
xorMappedAddress
=
nullptr
;
// 8 or 20 bytes.
const
struct
sockaddr
*
xorMappedAddress
=
nullptr
;
// 8 or 20 bytes.
MS_2BYTES
errorCode
=
0
;
// 4 bytes (no reason phrase).
uint16_t
errorCode
=
0
;
// 4 bytes (no reason phrase).
std
::
string
password
;
std
::
string
password
;
};
};
/* Inline methods. */
/* Inline methods. */
inline
inline
bool
STUNMessage
::
IsSTUN
(
const
MS_BYTE
*
data
,
size_t
len
)
bool
STUNMessage
::
IsSTUN
(
const
uint8_t
*
data
,
size_t
len
)
{
{
return
(
return
(
// STUN headers are 20 bytes.
// STUN headers are 20 bytes.
...
@@ -145,7 +145,7 @@ namespace RTC
...
@@ -145,7 +145,7 @@ namespace RTC
}
}
inline
inline
const
MS_BYTE
*
STUNMessage
::
GetRaw
()
const
uint8_t
*
STUNMessage
::
GetRaw
()
{
{
return
this
->
raw
;
return
this
->
raw
;
}
}
...
@@ -170,21 +170,21 @@ namespace RTC
...
@@ -170,21 +170,21 @@ namespace RTC
}
}
inline
inline
void
STUNMessage
::
SetPriority
(
const
MS_4BYTES
priority
)
void
STUNMessage
::
SetPriority
(
const
uint32_t
priority
)
{
{
if
(
!
this
->
priority
)
if
(
!
this
->
priority
)
this
->
priority
=
priority
;
this
->
priority
=
priority
;
}
}
inline
inline
void
STUNMessage
::
SetIceControlling
(
const
MS_8BYTES
iceControlling
)
void
STUNMessage
::
SetIceControlling
(
const
uint64_t
iceControlling
)
{
{
if
(
!
this
->
iceControlling
)
if
(
!
this
->
iceControlling
)
this
->
iceControlling
=
iceControlling
;
this
->
iceControlling
=
iceControlling
;
}
}
inline
inline
void
STUNMessage
::
SetIceControlled
(
const
MS_8BYTES
iceControlled
)
void
STUNMessage
::
SetIceControlled
(
const
uint64_t
iceControlled
)
{
{
if
(
!
this
->
iceControlled
)
if
(
!
this
->
iceControlled
)
this
->
iceControlled
=
iceControlled
;
this
->
iceControlled
=
iceControlled
;
...
@@ -204,13 +204,13 @@ namespace RTC
...
@@ -204,13 +204,13 @@ namespace RTC
}
}
inline
inline
void
STUNMessage
::
SetErrorCode
(
MS_2BYTES
errorCode
)
void
STUNMessage
::
SetErrorCode
(
uint16_t
errorCode
)
{
{
this
->
errorCode
=
errorCode
;
this
->
errorCode
=
errorCode
;
}
}
inline
inline
void
STUNMessage
::
SetMessageIntegrity
(
const
MS_BYTE
*
messageIntegrity
)
void
STUNMessage
::
SetMessageIntegrity
(
const
uint8_t
*
messageIntegrity
)
{
{
if
(
!
this
->
messageIntegrity
)
if
(
!
this
->
messageIntegrity
)
this
->
messageIntegrity
=
messageIntegrity
;
this
->
messageIntegrity
=
messageIntegrity
;
...
@@ -229,19 +229,19 @@ namespace RTC
...
@@ -229,19 +229,19 @@ namespace RTC
}
}
inline
inline
const
MS_4BYTES
STUNMessage
::
GetPriority
()
const
uint32_t
STUNMessage
::
GetPriority
()
{
{
return
this
->
priority
;
return
this
->
priority
;
}
}
inline
inline
const
MS_8BYTES
STUNMessage
::
GetIceControlling
()
const
uint64_t
STUNMessage
::
GetIceControlling
()
{
{
return
this
->
iceControlling
;
return
this
->
iceControlling
;
}
}
inline
inline
const
MS_8BYTES
STUNMessage
::
GetIceControlled
()
const
uint64_t
STUNMessage
::
GetIceControlled
()
{
{
return
this
->
iceControlled
;
return
this
->
iceControlled
;
}
}
...
@@ -253,7 +253,7 @@ namespace RTC
...
@@ -253,7 +253,7 @@ namespace RTC
}
}
inline
inline
MS_2BYTES
STUNMessage
::
GetErrorCode
()
uint16_t
STUNMessage
::
GetErrorCode
()
{
{
return
this
->
errorCode
;
return
this
->
errorCode
;
}
}
...
...
worker/include/RTC/TCPConnection.h
浏览文件 @
a675da25
...
@@ -13,14 +13,14 @@ namespace RTC
...
@@ -13,14 +13,14 @@ namespace RTC
class
Listener
class
Listener
{
{
public
:
public
:
virtual
void
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
=
0
;
virtual
void
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
};
};
public
:
public
:
TCPConnection
(
Listener
*
listener
,
size_t
bufferSize
);
TCPConnection
(
Listener
*
listener
,
size_t
bufferSize
);
virtual
~
TCPConnection
();
virtual
~
TCPConnection
();
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
/* Pure virtual methods inherited from ::TCPConnection. */
/* Pure virtual methods inherited from ::TCPConnection. */
public
:
public
:
...
...
worker/include/RTC/TCPServer.h
浏览文件 @
a675da25
...
@@ -31,10 +31,10 @@ namespace RTC
...
@@ -31,10 +31,10 @@ namespace RTC
private
:
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
uint16_t
minPort
;
static
MS_PORT
maxPort
;
static
uint16_t
maxPort
;
static
std
::
unordered_map
<
MS_PORT
,
bool
>
availableIPv4Ports
;
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv4Ports
;
static
std
::
unordered_map
<
MS_PORT
,
bool
>
availableIPv6Ports
;
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv6Ports
;
public
:
public
:
TCPServer
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Listener
*
connListener
,
uv_tcp_t
*
uvHandle
);
TCPServer
(
Listener
*
listener
,
RTC
::
TCPConnection
::
Listener
*
connListener
,
uv_tcp_t
*
uvHandle
);
...
...
worker/include/RTC/Transport.h
浏览文件 @
a675da25
...
@@ -43,7 +43,7 @@ namespace RTC
...
@@ -43,7 +43,7 @@ namespace RTC
// - Table of SSRC / RtpReceiver pairs.
// - Table of SSRC / RtpReceiver pairs.
std
::
unordered_map
<
uint32_t
,
RTC
::
RtpReceiver
*>
ssrcTable
;
std
::
unordered_map
<
uint32_t
,
RTC
::
RtpReceiver
*>
ssrcTable
;
// - Table of MID RTP header extension / RtpReceiver pairs.
// - Table of MID RTP header extension / RtpReceiver pairs.
// std::unordered_map<
MS_2BYTES
, RTC::RtpReceiver*> midTable;
// std::unordered_map<
uint16_t
, RTC::RtpReceiver*> midTable;
// - Table of RTP payload type / RtpReceiver pairs.
// - Table of RTP payload type / RtpReceiver pairs.
std
::
unordered_map
<
uint8_t
,
RTC
::
RtpReceiver
*>
ptTable
;
std
::
unordered_map
<
uint8_t
,
RTC
::
RtpReceiver
*>
ptTable
;
};
};
...
@@ -65,15 +65,15 @@ namespace RTC
...
@@ -65,15 +65,15 @@ namespace RTC
/* Private methods to unify UDP and TCP behavior. */
/* Private methods to unify UDP and TCP behavior. */
private
:
private
:
void
onPacketRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onPacketRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onSTUNDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onSTUNDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onDTLSDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onDTLSDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onRTPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
void
onRTCPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
);
void
onRTCPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
);
/* Pure virtual methods inherited from RTC::UDPSocket::Listener. */
/* Pure virtual methods inherited from RTC::UDPSocket::Listener. */
public
:
public
:
virtual
void
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
override
;
virtual
void
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
override
;
/* Pure virtual methods inherited from RTC::TCPServer::Listener. */
/* Pure virtual methods inherited from RTC::TCPServer::Listener. */
public
:
public
:
...
@@ -81,7 +81,7 @@ namespace RTC
...
@@ -81,7 +81,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::TCPConnection::Listener. */
/* Pure virtual methods inherited from RTC::TCPConnection::Listener. */
public
:
public
:
virtual
void
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
override
;
/* Pure virtual methods inherited from RTC::ICEServer::Listener. */
/* Pure virtual methods inherited from RTC::ICEServer::Listener. */
public
:
public
:
...
@@ -94,11 +94,11 @@ namespace RTC
...
@@ -94,11 +94,11 @@ namespace RTC
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public
:
public
:
virtual
void
onDTLSConnecting
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSConnecting
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
override
;
virtual
void
onDTLSConnected
(
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
override
;
virtual
void
onDTLSFailed
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSFailed
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSClosed
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onDTLSClosed
(
DTLSTransport
*
dtlsTransport
)
override
;
virtual
void
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
virtual
void
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
override
;
virtual
void
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
/* Pure virtual methods inherited from RTC::RtpReceiver::RtpListener. */
/* Pure virtual methods inherited from RTC::RtpReceiver::RtpListener. */
virtual
void
onRtpListenerParameters
(
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RtpParameters
*
rtpParameters
)
override
;
virtual
void
onRtpListenerParameters
(
RTC
::
RtpReceiver
*
rtpReceiver
,
RTC
::
RtpParameters
*
rtpParameters
)
override
;
...
...
worker/include/RTC/TransportTuple.h
浏览文件 @
a675da25
...
@@ -27,7 +27,7 @@ namespace RTC
...
@@ -27,7 +27,7 @@ namespace RTC
void
Dump
();
void
Dump
();
void
StoreUdpRemoteAddress
();
void
StoreUdpRemoteAddress
();
bool
Compare
(
TransportTuple
*
tuple
);
bool
Compare
(
TransportTuple
*
tuple
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Send
(
const
uint8_t
*
data
,
size_t
len
);
Protocol
GetProtocol
();
Protocol
GetProtocol
();
const
struct
sockaddr
*
GetLocalAddress
();
const
struct
sockaddr
*
GetLocalAddress
();
const
struct
sockaddr
*
GetRemoteAddress
();
const
struct
sockaddr
*
GetRemoteAddress
();
...
@@ -97,7 +97,7 @@ namespace RTC
...
@@ -97,7 +97,7 @@ namespace RTC
}
}
inline
inline
void
TransportTuple
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
void
TransportTuple
::
Send
(
const
uint8_t
*
data
,
size_t
len
)
{
{
if
(
this
->
protocol
==
Protocol
::
UDP
)
if
(
this
->
protocol
==
Protocol
::
UDP
)
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
this
->
udpSocket
->
Send
(
data
,
len
,
this
->
udpRemoteAddr
);
...
...
worker/include/RTC/UDPSocket.h
浏览文件 @
a675da25
...
@@ -15,7 +15,7 @@ namespace RTC
...
@@ -15,7 +15,7 @@ namespace RTC
class
Listener
class
Listener
{
{
public
:
public
:
virtual
void
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
virtual
void
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
=
0
;
};
};
public
:
public
:
...
@@ -29,17 +29,17 @@ namespace RTC
...
@@ -29,17 +29,17 @@ namespace RTC
private
:
private
:
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv4
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
struct
sockaddr_storage
sockaddrStorageIPv6
;
static
MS_PORT
minPort
;
static
uint16_t
minPort
;
static
MS_PORT
maxPort
;
static
uint16_t
maxPort
;
static
std
::
unordered_map
<
MS_PORT
,
bool
>
availableIPv4Ports
;
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv4Ports
;
static
std
::
unordered_map
<
MS_PORT
,
bool
>
availableIPv6Ports
;
static
std
::
unordered_map
<
uint16_t
,
bool
>
availableIPv6Ports
;
public
:
public
:
UDPSocket
(
Listener
*
listener
,
uv_udp_t
*
uvHandle
);
UDPSocket
(
Listener
*
listener
,
uv_udp_t
*
uvHandle
);
/* Pure virtual methods inherited from ::UDPSocket. */
/* Pure virtual methods inherited from ::UDPSocket. */
public
:
public
:
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPDatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
virtual
void
userOnUDPSocketClosed
()
override
;
private
:
private
:
...
...
worker/include/Settings.h
浏览文件 @
a675da25
...
@@ -16,8 +16,8 @@ public:
...
@@ -16,8 +16,8 @@ public:
uint8_t
logLevel
{
MS_LOG_LEVEL_DEBUG
};
uint8_t
logLevel
{
MS_LOG_LEVEL_DEBUG
};
std
::
string
rtcListenIPv4
;
std
::
string
rtcListenIPv4
;
std
::
string
rtcListenIPv6
;
std
::
string
rtcListenIPv6
;
MS_PORT
rtcMinPort
{
10000
};
uint16_t
rtcMinPort
{
10000
};
MS_PORT
rtcMaxPort
{
59999
};
uint16_t
rtcMaxPort
{
59999
};
std
::
string
dtlsCertificateFile
;
std
::
string
dtlsCertificateFile
;
std
::
string
dtlsPrivateKeyFile
;
std
::
string
dtlsPrivateKeyFile
;
// Private fields.
// Private fields.
...
...
worker/include/Utils.h
浏览文件 @
a675da25
...
@@ -13,7 +13,7 @@ namespace Utils
...
@@ -13,7 +13,7 @@ namespace Utils
public
:
public
:
static
int
GetFamily
(
const
char
*
ip
,
size_t
ip_len
);
static
int
GetFamily
(
const
char
*
ip
,
size_t
ip_len
);
static
int
GetFamily
(
const
std
::
string
&
ip
);
static
int
GetFamily
(
const
std
::
string
&
ip
);
static
void
GetAddressInfo
(
const
struct
sockaddr
*
addr
,
int
*
family
,
std
::
string
&
ip
,
MS_PORT
*
port
);
static
void
GetAddressInfo
(
const
struct
sockaddr
*
addr
,
int
*
family
,
std
::
string
&
ip
,
uint16_t
*
port
);
static
bool
CompareAddresses
(
const
struct
sockaddr
*
addr1
,
const
struct
sockaddr
*
addr2
);
static
bool
CompareAddresses
(
const
struct
sockaddr
*
addr1
,
const
struct
sockaddr
*
addr2
);
static
struct
sockaddr_storage
CopyAddress
(
const
struct
sockaddr
*
addr
);
static
struct
sockaddr_storage
CopyAddress
(
const
struct
sockaddr
*
addr
);
};
};
...
@@ -85,97 +85,97 @@ namespace Utils
...
@@ -85,97 +85,97 @@ namespace Utils
/**
/**
* All these functions get and set bytes in Network Byte Order (Big Endian).
* All these functions get and set bytes in Network Byte Order (Big Endian).
*/
*/
static
MS_BYTE
Get1Byte
(
const
MS_BYTE
*
data
,
size_t
i
);
static
uint8_t
Get1Byte
(
const
uint8_t
*
data
,
size_t
i
);
static
MS_2BYTES
Get2Bytes
(
const
MS_BYTE
*
data
,
size_t
i
);
static
uint16_t
Get2Bytes
(
const
uint8_t
*
data
,
size_t
i
);
static
MS_4BYTES
Get3Bytes
(
const
MS_BYTE
*
data
,
size_t
i
);
static
uint32_t
Get3Bytes
(
const
uint8_t
*
data
,
size_t
i
);
static
MS_4BYTES
Get4Bytes
(
const
MS_BYTE
*
data
,
size_t
i
);
static
uint32_t
Get4Bytes
(
const
uint8_t
*
data
,
size_t
i
);
static
MS_8BYTES
Get8Bytes
(
const
MS_BYTE
*
data
,
size_t
i
);
static
uint64_t
Get8Bytes
(
const
uint8_t
*
data
,
size_t
i
);
static
void
Set1Byte
(
MS_BYTE
*
data
,
size_t
i
,
MS_BYTE
value
);
static
void
Set1Byte
(
uint8_t
*
data
,
size_t
i
,
uint8_t
value
);
static
void
Set2Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_2BYTES
value
);
static
void
Set2Bytes
(
uint8_t
*
data
,
size_t
i
,
uint16_t
value
);
static
void
Set3Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_4BYTES
value
);
static
void
Set3Bytes
(
uint8_t
*
data
,
size_t
i
,
uint32_t
value
);
static
void
Set4Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_4BYTES
value
);
static
void
Set4Bytes
(
uint8_t
*
data
,
size_t
i
,
uint32_t
value
);
static
void
Set8Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_8BYTES
value
);
static
void
Set8Bytes
(
uint8_t
*
data
,
size_t
i
,
uint64_t
value
);
static
MS_2BYTES
PadTo4Bytes
(
MS_2BYTES
size
);
static
uint16_t
PadTo4Bytes
(
uint16_t
size
);
static
MS_4BYTES
PadTo4Bytes
(
MS_4BYTES
size
);
static
uint32_t
PadTo4Bytes
(
uint32_t
size
);
};
};
/* Inline static methods. */
/* Inline static methods. */
inline
inline
MS_BYTE
Byte
::
Get1Byte
(
const
MS_BYTE
*
data
,
size_t
i
)
uint8_t
Byte
::
Get1Byte
(
const
uint8_t
*
data
,
size_t
i
)
{
{
return
data
[
i
];
return
data
[
i
];
}
}
inline
inline
MS_2BYTES
Byte
::
Get2Bytes
(
const
MS_BYTE
*
data
,
size_t
i
)
uint16_t
Byte
::
Get2Bytes
(
const
uint8_t
*
data
,
size_t
i
)
{
{
return
(
MS_2BYTES
)(
data
[
i
+
1
])
|
((
MS_2BYTES
)(
data
[
i
]))
<<
8
;
return
(
uint16_t
)(
data
[
i
+
1
])
|
((
uint16_t
)(
data
[
i
]))
<<
8
;
}
}
inline
inline
MS_4BYTES
Byte
::
Get3Bytes
(
const
MS_BYTE
*
data
,
size_t
i
)
uint32_t
Byte
::
Get3Bytes
(
const
uint8_t
*
data
,
size_t
i
)
{
{
return
(
MS_4BYTES
)(
data
[
i
+
2
])
|
((
MS_4BYTES
)(
data
[
i
+
1
]))
<<
8
|
((
MS_4BYTES
)(
data
[
i
]))
<<
16
;
return
(
uint32_t
)(
data
[
i
+
2
])
|
((
uint32_t
)(
data
[
i
+
1
]))
<<
8
|
((
uint32_t
)(
data
[
i
]))
<<
16
;
}
}
inline
inline
MS_4BYTES
Byte
::
Get4Bytes
(
const
MS_BYTE
*
data
,
size_t
i
)
uint32_t
Byte
::
Get4Bytes
(
const
uint8_t
*
data
,
size_t
i
)
{
{
return
(
MS_4BYTES
)(
data
[
i
+
3
])
|
((
MS_4BYTES
)(
data
[
i
+
2
]))
<<
8
|
((
MS_4BYTES
)(
data
[
i
+
1
]))
<<
16
|
((
MS_4BYTES
)(
data
[
i
]))
<<
24
;
return
(
uint32_t
)(
data
[
i
+
3
])
|
((
uint32_t
)(
data
[
i
+
2
]))
<<
8
|
((
uint32_t
)(
data
[
i
+
1
]))
<<
16
|
((
uint32_t
)(
data
[
i
]))
<<
24
;
}
}
inline
inline
MS_8BYTES
Byte
::
Get8Bytes
(
const
MS_BYTE
*
data
,
size_t
i
)
uint64_t
Byte
::
Get8Bytes
(
const
uint8_t
*
data
,
size_t
i
)
{
{
return
((
MS_8BYTES
)
Byte
::
Get4Bytes
(
data
,
i
))
<<
32
|
Byte
::
Get4Bytes
(
data
,
i
+
4
);
return
((
uint64_t
)
Byte
::
Get4Bytes
(
data
,
i
))
<<
32
|
Byte
::
Get4Bytes
(
data
,
i
+
4
);
}
}
inline
inline
void
Byte
::
Set1Byte
(
MS_BYTE
*
data
,
size_t
i
,
MS_BYTE
value
)
void
Byte
::
Set1Byte
(
uint8_t
*
data
,
size_t
i
,
uint8_t
value
)
{
{
data
[
i
]
=
value
;
data
[
i
]
=
value
;
}
}
inline
inline
void
Byte
::
Set2Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_2BYTES
value
)
void
Byte
::
Set2Bytes
(
uint8_t
*
data
,
size_t
i
,
uint16_t
value
)
{
{
data
[
i
+
1
]
=
(
MS_BYTE
)(
value
);
data
[
i
+
1
]
=
(
uint8_t
)(
value
);
data
[
i
]
=
(
MS_BYTE
)(
value
>>
8
);
data
[
i
]
=
(
uint8_t
)(
value
>>
8
);
}
}
inline
inline
void
Byte
::
Set3Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_4BYTES
value
)
void
Byte
::
Set3Bytes
(
uint8_t
*
data
,
size_t
i
,
uint32_t
value
)
{
{
data
[
i
+
2
]
=
(
MS_BYTE
)(
value
);
data
[
i
+
2
]
=
(
uint8_t
)(
value
);
data
[
i
+
1
]
=
(
MS_BYTE
)(
value
>>
8
);
data
[
i
+
1
]
=
(
uint8_t
)(
value
>>
8
);
data
[
i
]
=
(
MS_BYTE
)(
value
>>
16
);
data
[
i
]
=
(
uint8_t
)(
value
>>
16
);
}
}
inline
inline
void
Byte
::
Set4Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_4BYTES
value
)
void
Byte
::
Set4Bytes
(
uint8_t
*
data
,
size_t
i
,
uint32_t
value
)
{
{
data
[
i
+
3
]
=
(
MS_BYTE
)(
value
);
data
[
i
+
3
]
=
(
uint8_t
)(
value
);
data
[
i
+
2
]
=
(
MS_BYTE
)(
value
>>
8
);
data
[
i
+
2
]
=
(
uint8_t
)(
value
>>
8
);
data
[
i
+
1
]
=
(
MS_BYTE
)(
value
>>
16
);
data
[
i
+
1
]
=
(
uint8_t
)(
value
>>
16
);
data
[
i
]
=
(
MS_BYTE
)(
value
>>
24
);
data
[
i
]
=
(
uint8_t
)(
value
>>
24
);
}
}
inline
inline
void
Byte
::
Set8Bytes
(
MS_BYTE
*
data
,
size_t
i
,
MS_8BYTES
value
)
void
Byte
::
Set8Bytes
(
uint8_t
*
data
,
size_t
i
,
uint64_t
value
)
{
{
data
[
i
+
7
]
=
(
MS_BYTE
)(
value
);
data
[
i
+
7
]
=
(
uint8_t
)(
value
);
data
[
i
+
6
]
=
(
MS_BYTE
)(
value
>>
8
);
data
[
i
+
6
]
=
(
uint8_t
)(
value
>>
8
);
data
[
i
+
5
]
=
(
MS_BYTE
)(
value
>>
16
);
data
[
i
+
5
]
=
(
uint8_t
)(
value
>>
16
);
data
[
i
+
4
]
=
(
MS_BYTE
)(
value
>>
24
);
data
[
i
+
4
]
=
(
uint8_t
)(
value
>>
24
);
data
[
i
+
3
]
=
(
MS_BYTE
)(
value
>>
32
);
data
[
i
+
3
]
=
(
uint8_t
)(
value
>>
32
);
data
[
i
+
2
]
=
(
MS_BYTE
)(
value
>>
40
);
data
[
i
+
2
]
=
(
uint8_t
)(
value
>>
40
);
data
[
i
+
1
]
=
(
MS_BYTE
)(
value
>>
48
);
data
[
i
+
1
]
=
(
uint8_t
)(
value
>>
48
);
data
[
i
]
=
(
MS_BYTE
)(
value
>>
56
);
data
[
i
]
=
(
uint8_t
)(
value
>>
56
);
}
}
inline
inline
MS_2BYTES
Byte
::
PadTo4Bytes
(
MS_2BYTES
size
)
uint16_t
Byte
::
PadTo4Bytes
(
uint16_t
size
)
{
{
// If size is not multiple of 32 bits then pad it.
// If size is not multiple of 32 bits then pad it.
if
(
size
&
0x03
)
if
(
size
&
0x03
)
...
@@ -185,7 +185,7 @@ namespace Utils
...
@@ -185,7 +185,7 @@ namespace Utils
}
}
inline
inline
MS_4BYTES
Byte
::
PadTo4Bytes
(
MS_4BYTES
size
)
uint32_t
Byte
::
PadTo4Bytes
(
uint32_t
size
)
{
{
// If size is not multiple of 32 bits then pad it.
// If size is not multiple of 32 bits then pad it.
if
(
size
&
0x03
)
if
(
size
&
0x03
)
...
@@ -201,14 +201,14 @@ namespace Utils
...
@@ -201,14 +201,14 @@ namespace Utils
static
void
ClassDestroy
();
static
void
ClassDestroy
();
static
uint32_t
GetRandomUInt
(
uint32_t
min
,
uint32_t
max
);
static
uint32_t
GetRandomUInt
(
uint32_t
min
,
uint32_t
max
);
static
const
std
::
string
GetRandomString
(
size_t
len
);
static
const
std
::
string
GetRandomString
(
size_t
len
);
static
MS_4BYTES
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
);
static
uint32_t
GetCRC32
(
const
uint8_t
*
data
,
size_t
size
);
static
const
MS_BYTE
*
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
MS_BYTE
*
data
,
size_t
len
);
static
const
uint8_t
*
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
uint8_t
*
data
,
size_t
len
);
private
:
private
:
static
uint32_t
seed
;
static
uint32_t
seed
;
static
HMAC_CTX
hmacSha1Ctx
;
static
HMAC_CTX
hmacSha1Ctx
;
static
MS_BYTE
hmacSha1Buffer
[];
static
uint8_t
hmacSha1Buffer
[];
static
const
MS_4BYTES
crc32Table
[
256
];
static
const
uint32_t
crc32Table
[
256
];
};
};
/* Inline static methods. */
/* Inline static methods. */
...
@@ -247,10 +247,10 @@ namespace Utils
...
@@ -247,10 +247,10 @@ namespace Utils
}
}
inline
inline
MS_4BYTES
Crypto
::
GetCRC32
(
const
MS_BYTE
*
data
,
size_t
size
)
uint32_t
Crypto
::
GetCRC32
(
const
uint8_t
*
data
,
size_t
size
)
{
{
MS_4BYTES
crc
=
0xFFFFFFFF
;
uint32_t
crc
=
0xFFFFFFFF
;
const
MS_BYTE
*
p
=
data
;
const
uint8_t
*
p
=
data
;
while
(
size
--
)
while
(
size
--
)
crc
=
Crypto
::
crc32Table
[(
crc
^
*
p
++
)
&
0xFF
]
^
(
crc
>>
8
);
crc
=
Crypto
::
crc32Table
[(
crc
^
*
p
++
)
&
0xFF
]
^
(
crc
>>
8
);
...
...
worker/include/common.h
浏览文件 @
a675da25
...
@@ -15,12 +15,6 @@
...
@@ -15,12 +15,6 @@
#define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_ERROR 0
#define MS_LOG_LEVEL_ERROR 0
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
#define MS_4BYTES uint32_t
#define MS_8BYTES uint64_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.
...
...
worker/include/handles/TCPConnection.h
浏览文件 @
a675da25
...
@@ -20,7 +20,7 @@ public:
...
@@ -20,7 +20,7 @@ public:
{
{
TCPConnection
*
connection
;
TCPConnection
*
connection
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
uint8_t
store
[
1
];
};
};
public
:
public
:
...
@@ -29,19 +29,19 @@ public:
...
@@ -29,19 +29,19 @@ public:
void
Close
();
void
Close
();
virtual
void
Dump
();
virtual
void
Dump
();
void
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
MS_PORT
localPort
);
void
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
uint16_t
localPort
);
bool
IsClosing
();
bool
IsClosing
();
uv_tcp_t
*
GetUvHandle
();
uv_tcp_t
*
GetUvHandle
();
void
Start
();
void
Start
();
void
Write
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Write
(
const
uint8_t
*
data
,
size_t
len
);
void
Write
(
const
MS_BYTE
*
data1
,
size_t
len1
,
const
MS_BYTE
*
data2
,
size_t
len2
);
void
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
);
void
Write
(
const
std
::
string
&
data
);
void
Write
(
const
std
::
string
&
data
);
const
struct
sockaddr
*
GetLocalAddress
();
const
struct
sockaddr
*
GetLocalAddress
();
const
std
::
string
&
GetLocalIP
();
const
std
::
string
&
GetLocalIP
();
MS_PORT
GetLocalPort
();
uint16_t
GetLocalPort
();
const
struct
sockaddr
*
GetPeerAddress
();
const
struct
sockaddr
*
GetPeerAddress
();
const
std
::
string
&
GetPeerIP
();
const
std
::
string
&
GetPeerIP
();
MS_PORT
GetPeerPort
();
uint16_t
GetPeerPort
();
private
:
private
:
bool
SetPeerAddress
();
bool
SetPeerAddress
();
...
@@ -73,14 +73,14 @@ protected:
...
@@ -73,14 +73,14 @@ protected:
// Passed by argument.
// Passed by argument.
size_t
bufferSize
=
0
;
size_t
bufferSize
=
0
;
// Allocated by this.
// Allocated by this.
MS_BYTE
*
buffer
=
nullptr
;
uint8_t
*
buffer
=
nullptr
;
// Others.
// Others.
size_t
bufferDataLen
=
0
;
size_t
bufferDataLen
=
0
;
std
::
string
localIP
;
std
::
string
localIP
;
MS_PORT
localPort
=
0
;
uint16_t
localPort
=
0
;
struct
sockaddr_storage
peerAddr
;
struct
sockaddr_storage
peerAddr
;
std
::
string
peerIP
;
std
::
string
peerIP
;
MS_PORT
peerPort
=
0
;
uint16_t
peerPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
...
@@ -100,7 +100,7 @@ uv_tcp_t* TCPConnection::GetUvHandle()
...
@@ -100,7 +100,7 @@ uv_tcp_t* TCPConnection::GetUvHandle()
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
uint8_t
*
)
data
.
c_str
(),
data
.
size
());
}
}
inline
inline
...
@@ -116,7 +116,7 @@ const std::string& TCPConnection::GetLocalIP()
...
@@ -116,7 +116,7 @@ const std::string& TCPConnection::GetLocalIP()
}
}
inline
inline
MS_PORT
TCPConnection
::
GetLocalPort
()
uint16_t
TCPConnection
::
GetLocalPort
()
{
{
return
this
->
localPort
;
return
this
->
localPort
;
}
}
...
@@ -134,7 +134,7 @@ const std::string& TCPConnection::GetPeerIP()
...
@@ -134,7 +134,7 @@ const std::string& TCPConnection::GetPeerIP()
}
}
inline
inline
MS_PORT
TCPConnection
::
GetPeerPort
()
uint16_t
TCPConnection
::
GetPeerPort
()
{
{
return
this
->
peerPort
;
return
this
->
peerPort
;
}
}
...
...
worker/include/handles/TCPServer.h
浏览文件 @
a675da25
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
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
,
uint16_t
port
,
int
backlog
);
/**
/**
* uvHandle must be an already initialized and binded uv_tcp_t pointer.
* uvHandle must be an already initialized and binded uv_tcp_t pointer.
*/
*/
...
@@ -22,7 +22,7 @@ public:
...
@@ -22,7 +22,7 @@ public:
bool
IsClosing
();
bool
IsClosing
();
const
struct
sockaddr
*
GetLocalAddress
();
const
struct
sockaddr
*
GetLocalAddress
();
const
std
::
string
&
GetLocalIP
();
const
std
::
string
&
GetLocalIP
();
MS_PORT
GetLocalPort
();
uint16_t
GetLocalPort
();
size_t
GetNumConnections
();
size_t
GetNumConnections
();
private
:
private
:
...
@@ -54,7 +54,7 @@ private:
...
@@ -54,7 +54,7 @@ private:
protected
:
protected
:
struct
sockaddr_storage
localAddr
;
struct
sockaddr_storage
localAddr
;
std
::
string
localIP
;
std
::
string
localIP
;
MS_PORT
localPort
=
0
;
uint16_t
localPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
...
...
worker/include/handles/Timer.h
浏览文件 @
a675da25
...
@@ -17,7 +17,7 @@ public:
...
@@ -17,7 +17,7 @@ public:
Timer
(
Listener
*
listener
);
Timer
(
Listener
*
listener
);
void
Close
();
void
Close
();
void
Start
(
MS_8BYTES
timeout
);
void
Start
(
uint64_t
timeout
);
void
Stop
();
void
Stop
();
/* Callbacks fired by UV events. */
/* Callbacks fired by UV events. */
...
...
worker/include/handles/UDPSocket.h
浏览文件 @
a675da25
...
@@ -13,14 +13,14 @@ public:
...
@@ -13,14 +13,14 @@ public:
{
{
UDPSocket
*
socket
;
UDPSocket
*
socket
;
uv_udp_send_t
req
;
uv_udp_send_t
req
;
MS_BYTE
store
[
1
];
uint8_t
store
[
1
];
};
};
private
:
private
:
static
MS_BYTE
readBuffer
[];
static
uint8_t
readBuffer
[];
public
:
public
:
UDPSocket
(
const
std
::
string
&
ip
,
MS_PORT
port
);
UDPSocket
(
const
std
::
string
&
ip
,
uint16_t
port
);
/**
/**
* uvHandle must be an already initialized and binded uv_udp_t pointer.
* uvHandle must be an already initialized and binded uv_udp_t pointer.
*/
*/
...
@@ -29,13 +29,13 @@ public:
...
@@ -29,13 +29,13 @@ public:
void
Close
();
void
Close
();
virtual
void
Dump
();
virtual
void
Dump
();
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
);
void
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
);
void
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
);
void
Send
(
const
std
::
string
&
data
,
const
struct
sockaddr
*
addr
);
void
Send
(
const
MS_BYTE
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
MS_PORT
port
);
void
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
uint16_t
port
);
void
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
MS_PORT
port
);
void
Send
(
const
std
::
string
&
data
,
const
std
::
string
&
ip
,
uint16_t
port
);
const
struct
sockaddr
*
GetLocalAddress
();
const
struct
sockaddr
*
GetLocalAddress
();
const
std
::
string
&
GetLocalIP
();
const
std
::
string
&
GetLocalIP
();
MS_PORT
GetLocalPort
();
uint16_t
GetLocalPort
();
private
:
private
:
bool
SetLocalAddress
();
bool
SetLocalAddress
();
...
@@ -49,7 +49,7 @@ public:
...
@@ -49,7 +49,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
/* Pure virtual methods that must be implemented by the subclass. */
protected
:
protected
:
virtual
void
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
=
0
;
virtual
void
userOnUDPDatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
=
0
;
virtual
void
userOnUDPSocketClosed
()
=
0
;
virtual
void
userOnUDPSocketClosed
()
=
0
;
private
:
private
:
...
@@ -61,7 +61,7 @@ private:
...
@@ -61,7 +61,7 @@ private:
protected
:
protected
:
struct
sockaddr_storage
localAddr
;
struct
sockaddr_storage
localAddr
;
std
::
string
localIP
;
std
::
string
localIP
;
MS_PORT
localPort
=
0
;
uint16_t
localPort
=
0
;
};
};
/* Inline methods. */
/* Inline methods. */
...
@@ -69,13 +69,13 @@ protected:
...
@@ -69,13 +69,13 @@ protected:
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
uint8_t
*
)
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
,
uint16_t
port
)
{
{
Send
((
const
MS_BYTE
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
Send
((
const
uint8_t
*
)
data
.
c_str
(),
data
.
size
(),
ip
,
port
);
}
}
inline
inline
...
@@ -91,7 +91,7 @@ const std::string& UDPSocket::GetLocalIP()
...
@@ -91,7 +91,7 @@ const std::string& UDPSocket::GetLocalIP()
}
}
inline
inline
MS_PORT
UDPSocket
::
GetLocalPort
()
uint16_t
UDPSocket
::
GetLocalPort
()
{
{
return
this
->
localPort
;
return
this
->
localPort
;
}
}
...
...
worker/include/handles/UnixStreamSocket.h
浏览文件 @
a675da25
...
@@ -13,7 +13,7 @@ public:
...
@@ -13,7 +13,7 @@ public:
{
{
UnixStreamSocket
*
socket
;
UnixStreamSocket
*
socket
;
uv_write_t
req
;
uv_write_t
req
;
MS_BYTE
store
[
1
];
uint8_t
store
[
1
];
};
};
public
:
public
:
...
@@ -22,7 +22,7 @@ public:
...
@@ -22,7 +22,7 @@ public:
void
Close
();
void
Close
();
bool
IsClosing
();
bool
IsClosing
();
void
Write
(
const
MS_BYTE
*
data
,
size_t
len
);
void
Write
(
const
uint8_t
*
data
,
size_t
len
);
void
Write
(
const
std
::
string
&
data
);
void
Write
(
const
std
::
string
&
data
);
/* Callbacks fired by UV events. */
/* Callbacks fired by UV events. */
...
@@ -50,7 +50,7 @@ protected:
...
@@ -50,7 +50,7 @@ protected:
// Passed by argument.
// Passed by argument.
size_t
bufferSize
=
0
;
size_t
bufferSize
=
0
;
// Allocated by this.
// Allocated by this.
MS_BYTE
*
buffer
=
nullptr
;
uint8_t
*
buffer
=
nullptr
;
// Others.
// Others.
size_t
bufferDataLen
=
0
;
size_t
bufferDataLen
=
0
;
};
};
...
@@ -66,7 +66,7 @@ bool UnixStreamSocket::IsClosing()
...
@@ -66,7 +66,7 @@ bool UnixStreamSocket::IsClosing()
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
uint8_t
*
)
data
.
c_str
(),
data
.
size
());
}
}
#endif
#endif
worker/src/Channel/UnixStreamSocket.cpp
浏览文件 @
a675da25
...
@@ -17,7 +17,7 @@ namespace Channel
...
@@ -17,7 +17,7 @@ namespace Channel
{
{
/* Class variables. */
/* Class variables. */
MS_BYTE
UnixStreamSocket
::
writeBuffer
[
NS_MAX_SIZE
];
uint8_t
UnixStreamSocket
::
writeBuffer
[
NS_MAX_SIZE
];
/* Instance methods. */
/* Instance methods. */
...
@@ -232,7 +232,7 @@ namespace Channel
...
@@ -232,7 +232,7 @@ namespace Channel
// If here it means that json_start points to the beginning of a JSON string
// If here it means that json_start points to the beginning of a JSON string
// with json_len bytes length, so recalculate read_len.
// with json_len bytes length, so recalculate read_len.
read_len
=
(
const
MS_BYTE
*
)
json_start
-
(
this
->
buffer
+
this
->
msgStart
)
+
json_len
+
1
;
read_len
=
(
const
uint8_t
*
)
json_start
-
(
this
->
buffer
+
this
->
msgStart
)
+
json_len
+
1
;
Json
::
Value
json
;
Json
::
Value
json
;
std
::
string
json_parse_error
;
std
::
string
json_parse_error
;
...
...
worker/src/RTC/DTLSTransport.cpp
浏览文件 @
a675da25
...
@@ -62,7 +62,7 @@ namespace RTC
...
@@ -62,7 +62,7 @@ namespace RTC
X509
*
DTLSTransport
::
certificate
=
nullptr
;
X509
*
DTLSTransport
::
certificate
=
nullptr
;
EVP_PKEY
*
DTLSTransport
::
privateKey
=
nullptr
;
EVP_PKEY
*
DTLSTransport
::
privateKey
=
nullptr
;
SSL_CTX
*
DTLSTransport
::
sslCtx
=
nullptr
;
SSL_CTX
*
DTLSTransport
::
sslCtx
=
nullptr
;
MS_BYTE
DTLSTransport
::
sslReadBuffer
[
MS_SSL_READ_BUFFER_SIZE
];
uint8_t
DTLSTransport
::
sslReadBuffer
[
MS_SSL_READ_BUFFER_SIZE
];
std
::
map
<
std
::
string
,
DTLSTransport
::
FingerprintAlgorithm
>
DTLSTransport
::
string2FingerprintAlgorithm
=
std
::
map
<
std
::
string
,
DTLSTransport
::
FingerprintAlgorithm
>
DTLSTransport
::
string2FingerprintAlgorithm
=
{
{
{
"sha-1"
,
DTLSTransport
::
FingerprintAlgorithm
::
SHA1
},
{
"sha-1"
,
DTLSTransport
::
FingerprintAlgorithm
::
SHA1
},
...
@@ -636,7 +636,7 @@ namespace RTC
...
@@ -636,7 +636,7 @@ namespace RTC
}
}
}
}
void
DTLSTransport
::
ProcessDTLSData
(
const
MS_BYTE
*
data
,
size_t
len
)
void
DTLSTransport
::
ProcessDTLSData
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -681,11 +681,11 @@ namespace RTC
...
@@ -681,11 +681,11 @@ namespace RTC
}
}
// Notify the listener.
// Notify the listener.
this
->
listener
->
onDTLSApplicationData
(
this
,
(
MS_BYTE
*
)
DTLSTransport
::
sslReadBuffer
,
(
size_t
)
read
);
this
->
listener
->
onDTLSApplicationData
(
this
,
(
uint8_t
*
)
DTLSTransport
::
sslReadBuffer
,
(
size_t
)
read
);
}
}
}
}
void
DTLSTransport
::
SendApplicationData
(
const
MS_BYTE
*
data
,
size_t
len
)
void
DTLSTransport
::
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -853,7 +853,7 @@ namespace RTC
...
@@ -853,7 +853,7 @@ namespace RTC
MS_DEBUG
(
"%ld bytes of DTLS data ready to sent to the peer"
,
read
);
MS_DEBUG
(
"%ld bytes of DTLS data ready to sent to the peer"
,
read
);
// Notify the listener.
// Notify the listener.
this
->
listener
->
onOutgoingDTLSData
(
this
,
(
MS_BYTE
*
)
data
,
(
size_t
)
read
);
this
->
listener
->
onOutgoingDTLSData
(
this
,
(
uint8_t
*
)
data
,
(
size_t
)
read
);
// Clear the BIO buffer.
// Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning.
// NOTE: the (void) avoids the -Wunused-value warning.
...
@@ -867,7 +867,7 @@ namespace RTC
...
@@ -867,7 +867,7 @@ namespace RTC
long
int
ret
;
long
int
ret
;
struct
timeval
dtls_timeout
;
struct
timeval
dtls_timeout
;
MS_8BYTES
timeout_ms
;
uint64_t
timeout_ms
;
// NOTE: If ret == 0 then ignore the value in dtls_timeout.
// NOTE: If ret == 0 then ignore the value in dtls_timeout.
// NOTE: No DTLSv_1_2_get_timeout() or DTLS_get_timeout() in OpenSSL 1.1.0-dev.
// NOTE: No DTLSv_1_2_get_timeout() or DTLS_get_timeout() in OpenSSL 1.1.0-dev.
...
@@ -875,7 +875,7 @@ namespace RTC
...
@@ -875,7 +875,7 @@ namespace RTC
if
(
ret
==
0
)
if
(
ret
==
0
)
return
true
;
return
true
;
timeout_ms
=
(
dtls_timeout
.
tv_sec
*
(
MS_8BYTES
)
1000
)
+
(
dtls_timeout
.
tv_usec
/
1000
);
timeout_ms
=
(
dtls_timeout
.
tv_sec
*
(
uint64_t
)
1000
)
+
(
dtls_timeout
.
tv_usec
/
1000
);
if
(
timeout_ms
==
0
)
if
(
timeout_ms
==
0
)
{
{
return
true
;
return
true
;
...
@@ -1030,13 +1030,13 @@ namespace RTC
...
@@ -1030,13 +1030,13 @@ namespace RTC
{
{
MS_TRACE
();
MS_TRACE
();
MS_BYTE
srtp_material
[
MS_SRTP_MASTER_LENGTH
*
2
];
uint8_t
srtp_material
[
MS_SRTP_MASTER_LENGTH
*
2
];
MS_BYTE
*
srtp_local_key
;
uint8_t
*
srtp_local_key
;
MS_BYTE
*
srtp_local_salt
;
uint8_t
*
srtp_local_salt
;
MS_BYTE
*
srtp_remote_key
;
uint8_t
*
srtp_remote_key
;
MS_BYTE
*
srtp_remote_salt
;
uint8_t
*
srtp_remote_salt
;
MS_BYTE
srtp_local_master_key
[
MS_SRTP_MASTER_LENGTH
];
uint8_t
srtp_local_master_key
[
MS_SRTP_MASTER_LENGTH
];
MS_BYTE
srtp_remote_master_key
[
MS_SRTP_MASTER_LENGTH
];
uint8_t
srtp_remote_master_key
[
MS_SRTP_MASTER_LENGTH
];
int
ret
;
int
ret
;
ret
=
SSL_export_keying_material
(
this
->
ssl
,
srtp_material
,
MS_SRTP_MASTER_LENGTH
*
2
,
"EXTRACTOR-dtls_srtp"
,
19
,
nullptr
,
0
,
0
);
ret
=
SSL_export_keying_material
(
this
->
ssl
,
srtp_material
,
MS_SRTP_MASTER_LENGTH
*
2
,
"EXTRACTOR-dtls_srtp"
,
19
,
nullptr
,
0
,
0
);
...
...
worker/src/RTC/RTCPPacket.cpp
浏览文件 @
a675da25
...
@@ -7,7 +7,7 @@ namespace RTC
...
@@ -7,7 +7,7 @@ namespace RTC
{
{
/* Class methods. */
/* Class methods. */
RTCPPacket
*
RTCPPacket
::
Parse
(
const
MS_BYTE
*
data
,
size_t
len
)
RTCPPacket
*
RTCPPacket
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -24,9 +24,9 @@ namespace RTC
...
@@ -24,9 +24,9 @@ namespace RTC
/* Instance methods. */
/* Instance methods. */
RTCPPacket
::
RTCPPacket
(
CommonHeader
*
header
,
const
MS_BYTE
*
raw
,
size_t
length
)
:
RTCPPacket
::
RTCPPacket
(
CommonHeader
*
header
,
const
uint8_t
*
raw
,
size_t
length
)
:
header
(
header
),
header
(
header
),
raw
((
MS_BYTE
*
)
raw
),
raw
((
uint8_t
*
)
raw
),
length
(
length
)
length
(
length
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/RTC/RTPPacket.cpp
浏览文件 @
a675da25
...
@@ -9,7 +9,7 @@ namespace RTC
...
@@ -9,7 +9,7 @@ namespace RTC
{
{
/* Class methods. */
/* Class methods. */
RTPPacket
*
RTPPacket
::
Parse
(
const
MS_BYTE
*
data
,
size_t
len
)
RTPPacket
*
RTPPacket
::
Parse
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -70,9 +70,9 @@ namespace RTC
...
@@ -70,9 +70,9 @@ namespace RTC
}
}
// Get payload.
// Get payload.
MS_BYTE
*
payload
=
(
MS_BYTE
*
)
data
+
pos
;
uint8_t
*
payload
=
(
uint8_t
*
)
data
+
pos
;
size_t
payloadLength
=
len
-
pos
;
size_t
payloadLength
=
len
-
pos
;
MS_BYTE
payloadPadding
=
0
;
uint8_t
payloadPadding
=
0
;
MS_ASSERT
(
len
>=
pos
,
"payload has negative size"
);
MS_ASSERT
(
len
>=
pos
,
"payload has negative size"
);
...
@@ -114,19 +114,19 @@ namespace RTC
...
@@ -114,19 +114,19 @@ namespace RTC
/* Instance methods. */
/* Instance methods. */
RTPPacket
::
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
MS_BYTE
*
payload
,
size_t
payloadLength
,
MS_BYTE
payloadPadding
,
const
MS_BYTE
*
raw
,
size_t
length
)
:
RTPPacket
::
RTPPacket
(
Header
*
header
,
ExtensionHeader
*
extensionHeader
,
const
uint8_t
*
payload
,
size_t
payloadLength
,
uint8_t
payloadPadding
,
const
uint8_t
*
raw
,
size_t
length
)
:
header
(
header
),
header
(
header
),
extensionHeader
(
extensionHeader
),
extensionHeader
(
extensionHeader
),
payload
((
MS_BYTE
*
)
payload
),
payload
((
uint8_t
*
)
payload
),
payloadLength
(
payloadLength
),
payloadLength
(
payloadLength
),
payloadPadding
(
payloadPadding
),
payloadPadding
(
payloadPadding
),
raw
((
MS_BYTE
*
)
raw
),
raw
((
uint8_t
*
)
raw
),
length
(
length
)
length
(
length
)
{
{
MS_TRACE
();
MS_TRACE
();
if
(
this
->
header
->
csrc_count
)
if
(
this
->
header
->
csrc_count
)
this
->
csrcList
=
(
MS_BYTE
*
)
raw
+
sizeof
(
Header
);
this
->
csrcList
=
(
uint8_t
*
)
raw
+
sizeof
(
Header
);
}
}
RTPPacket
::~
RTPPacket
()
RTPPacket
::~
RTPPacket
()
...
@@ -192,7 +192,7 @@ namespace RTC
...
@@ -192,7 +192,7 @@ namespace RTC
this
->
length
+=
(
size_t
)
this
->
payloadPadding
;
this
->
length
+=
(
size_t
)
this
->
payloadPadding
;
// Allocate it.
// Allocate it.
this
->
raw
=
new
MS_BYTE
[
this
->
length
];
this
->
raw
=
new
uint8_t
[
this
->
length
];
// Add minimun header.
// Add minimun header.
std
::
memcpy
(
this
->
raw
,
this
->
header
,
sizeof
(
Header
));
std
::
memcpy
(
this
->
raw
,
this
->
header
,
sizeof
(
Header
));
...
...
worker/src/RTC/SRTPSession.cpp
浏览文件 @
a675da25
...
@@ -12,7 +12,7 @@ namespace RTC
...
@@ -12,7 +12,7 @@ namespace RTC
{
{
/* Class variables. */
/* Class variables. */
MS_BYTE
SRTPSession
::
encryptBuffer
[
MS_ENCRYPT_BUFFER_SIZE
];
uint8_t
SRTPSession
::
encryptBuffer
[
MS_ENCRYPT_BUFFER_SIZE
];
/* Class methods. */
/* Class methods. */
...
@@ -57,7 +57,7 @@ namespace RTC
...
@@ -57,7 +57,7 @@ namespace RTC
/* Instance methods. */
/* Instance methods. */
SRTPSession
::
SRTPSession
(
Type
type
,
SRTPProfile
profile
,
MS_BYTE
*
key
,
size_t
key_len
)
SRTPSession
::
SRTPSession
(
Type
type
,
SRTPProfile
profile
,
uint8_t
*
key
,
size_t
key_len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -126,7 +126,7 @@ namespace RTC
...
@@ -126,7 +126,7 @@ namespace RTC
// TODO: It must not memcpy it but instead the provided packet must already be
// TODO: It must not memcpy it but instead the provided packet must already be
// allocated into a buffer.
// allocated into a buffer.
bool
SRTPSession
::
EncryptRTP
(
const
MS_BYTE
**
data
,
size_t
*
len
)
bool
SRTPSession
::
EncryptRTP
(
const
uint8_t
**
data
,
size_t
*
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -148,12 +148,12 @@ namespace RTC
...
@@ -148,12 +148,12 @@ namespace RTC
}
}
// Update the given data pointer.
// Update the given data pointer.
*
data
=
(
const
MS_BYTE
*
)
SRTPSession
::
encryptBuffer
;
*
data
=
(
const
uint8_t
*
)
SRTPSession
::
encryptBuffer
;
return
true
;
return
true
;
}
}
bool
SRTPSession
::
DecryptSRTP
(
const
MS_BYTE
*
data
,
size_t
*
len
)
bool
SRTPSession
::
DecryptSRTP
(
const
uint8_t
*
data
,
size_t
*
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -167,7 +167,7 @@ namespace RTC
...
@@ -167,7 +167,7 @@ namespace RTC
return
true
;
return
true
;
}
}
bool
SRTPSession
::
EncryptRTCP
(
const
MS_BYTE
**
data
,
size_t
*
len
)
bool
SRTPSession
::
EncryptRTCP
(
const
uint8_t
**
data
,
size_t
*
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -189,12 +189,12 @@ namespace RTC
...
@@ -189,12 +189,12 @@ namespace RTC
}
}
// Update the given data pointer.
// Update the given data pointer.
*
data
=
(
const
MS_BYTE
*
)
SRTPSession
::
encryptBuffer
;
*
data
=
(
const
uint8_t
*
)
SRTPSession
::
encryptBuffer
;
return
true
;
return
true
;
}
}
bool
SRTPSession
::
DecryptSRTCP
(
const
MS_BYTE
*
data
,
size_t
*
len
)
bool
SRTPSession
::
DecryptSRTCP
(
const
uint8_t
*
data
,
size_t
*
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/RTC/STUNMessage.cpp
浏览文件 @
a675da25
差异被折叠。
点击展开。
worker/src/RTC/TCPConnection.cpp
浏览文件 @
a675da25
...
@@ -63,7 +63,7 @@ namespace RTC
...
@@ -63,7 +63,7 @@ namespace RTC
// We have packet_len bytes.
// We have packet_len bytes.
if
(
data_len
>=
2
&&
data_len
>=
2
+
packet_len
)
if
(
data_len
>=
2
&&
data_len
>=
2
+
packet_len
)
{
{
const
MS_BYTE
*
packet
=
this
->
buffer
+
this
->
frameStart
+
2
;
const
uint8_t
*
packet
=
this
->
buffer
+
this
->
frameStart
+
2
;
// Notify the listener.
// Notify the listener.
if
(
packet_len
!=
0
)
if
(
packet_len
!=
0
)
...
@@ -139,13 +139,13 @@ namespace RTC
...
@@ -139,13 +139,13 @@ namespace RTC
}
}
}
}
void
TCPConnection
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
)
void
TCPConnection
::
Send
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
// Write according to Framing RFC 4571.
// Write according to Framing RFC 4571.
MS_BYTE
frame_len
[
2
];
uint8_t
frame_len
[
2
];
Utils
::
Byte
::
Set2Bytes
(
frame_len
,
0
,
len
);
Utils
::
Byte
::
Set2Bytes
(
frame_len
,
0
,
len
);
...
...
worker/src/RTC/TCPServer.cpp
浏览文件 @
a675da25
...
@@ -27,10 +27,10 @@ namespace RTC
...
@@ -27,10 +27,10 @@ namespace RTC
struct
sockaddr_storage
TCPServer
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
TCPServer
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
TCPServer
::
sockaddrStorageIPv6
;
struct
sockaddr_storage
TCPServer
::
sockaddrStorageIPv6
;
MS_PORT
TCPServer
::
minPort
;
uint16_t
TCPServer
::
minPort
;
MS_PORT
TCPServer
::
maxPort
;
uint16_t
TCPServer
::
maxPort
;
std
::
unordered_map
<
MS_PORT
,
bool
>
TCPServer
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
TCPServer
::
availableIPv4Ports
;
std
::
unordered_map
<
MS_PORT
,
bool
>
TCPServer
::
availableIPv6Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
TCPServer
::
availableIPv6Ports
;
/* Class methods. */
/* Class methods. */
...
@@ -57,7 +57,7 @@ namespace RTC
...
@@ -57,7 +57,7 @@ namespace RTC
TCPServer
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
TCPServer
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
TCPServer
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
TCPServer
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
MS_PORT
i
=
RTC
::
TCPServer
::
minPort
;
uint16_t
i
=
RTC
::
TCPServer
::
minPort
;
do
do
{
{
RTC
::
TCPServer
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
TCPServer
::
availableIPv4Ports
[
i
]
=
true
;
...
@@ -106,13 +106,13 @@ namespace RTC
...
@@ -106,13 +106,13 @@ namespace RTC
struct
sockaddr_storage
first_bind_addr
;
struct
sockaddr_storage
first_bind_addr
;
struct
sockaddr_storage
second_bind_addr
;
struct
sockaddr_storage
second_bind_addr
;
const
char
*
listenIP
;
const
char
*
listenIP
;
MS_PORT
random_first_port
;
uint16_t
random_first_port
;
MS_PORT
iterate_first_port
;
uint16_t
iterate_first_port
;
MS_PORT
iterate_second_port
;
uint16_t
iterate_second_port
;
uint16_t
attempt
=
0
;
uint16_t
attempt
=
0
;
uint16_t
bindAttempt
=
0
;
uint16_t
bindAttempt
=
0
;
int
flags
=
0
;
int
flags
=
0
;
std
::
unordered_map
<
MS_PORT
,
bool
>*
available_ports
;
std
::
unordered_map
<
uint16_t
,
bool
>*
available_ports
;
switch
(
address_family
)
switch
(
address_family
)
{
{
...
@@ -138,7 +138,7 @@ namespace RTC
...
@@ -138,7 +138,7 @@ namespace RTC
}
}
// Choose a random first port to start from.
// Choose a random first port to start from.
random_first_port
=
(
MS_PORT
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
TCPServer
::
minPort
,
(
uint32_t
)
RTC
::
TCPServer
::
maxPort
);
random_first_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
TCPServer
::
minPort
,
(
uint32_t
)
RTC
::
TCPServer
::
maxPort
);
// Make it even if pair is requested.
// Make it even if pair is requested.
if
(
pair
)
if
(
pair
)
random_first_port
&=
~
1
;
random_first_port
&=
~
1
;
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
a675da25
...
@@ -637,7 +637,7 @@ namespace RTC
...
@@ -637,7 +637,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onPacketRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onPacketRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -669,7 +669,7 @@ namespace RTC
...
@@ -669,7 +669,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onSTUNDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onSTUNDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -688,7 +688,7 @@ namespace RTC
...
@@ -688,7 +688,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onDTLSDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onDTLSDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -719,7 +719,7 @@ namespace RTC
...
@@ -719,7 +719,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onRTPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -748,7 +748,7 @@ namespace RTC
...
@@ -748,7 +748,7 @@ namespace RTC
}
}
inline
inline
void
Transport
::
onRTCPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onRTCPDataRecv
(
RTC
::
TransportTuple
*
tuple
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -766,7 +766,7 @@ namespace RTC
...
@@ -766,7 +766,7 @@ namespace RTC
MS_DEBUG
(
"received RTCP data"
);
MS_DEBUG
(
"received RTCP data"
);
}
}
void
Transport
::
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
void
Transport
::
onPacketRecv
(
RTC
::
UDPSocket
*
socket
,
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
remote_addr
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -785,7 +785,7 @@ namespace RTC
...
@@ -785,7 +785,7 @@ namespace RTC
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
this
->
iceServer
->
RemoveTuple
(
&
tuple
);
}
}
void
Transport
::
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onPacketRecv
(
RTC
::
TCPConnection
*
connection
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -901,7 +901,7 @@ namespace RTC
...
@@ -901,7 +901,7 @@ namespace RTC
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
this
->
notifier
->
Emit
(
this
->
transportId
,
"dtlsstatechange"
,
eventData
);
}
}
void
Transport
::
onDTLSConnected
(
RTC
::
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
MS_BYTE
*
srtp_local_key
,
size_t
srtp_local_key_len
,
MS_BYTE
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
void
Transport
::
onDTLSConnected
(
RTC
::
DTLSTransport
*
dtlsTransport
,
RTC
::
SRTPSession
::
SRTPProfile
srtp_profile
,
uint8_t
*
srtp_local_key
,
size_t
srtp_local_key_len
,
uint8_t
*
srtp_remote_key
,
size_t
srtp_remote_key_len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -959,7 +959,7 @@ namespace RTC
...
@@ -959,7 +959,7 @@ namespace RTC
Close
();
Close
();
}
}
void
Transport
::
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onOutgoingDTLSData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -976,7 +976,7 @@ namespace RTC
...
@@ -976,7 +976,7 @@ namespace RTC
this
->
selectedTuple
->
Send
(
data
,
len
);
this
->
selectedTuple
->
Send
(
data
,
len
);
}
}
void
Transport
::
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
MS_BYTE
*
data
,
size_t
len
)
void
Transport
::
onDTLSApplicationData
(
RTC
::
DTLSTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/RTC/TransportTuple.cpp
浏览文件 @
a675da25
...
@@ -26,7 +26,7 @@ namespace RTC
...
@@ -26,7 +26,7 @@ namespace RTC
Json
::
Value
json_remote
;
Json
::
Value
json_remote
;
int
ip_family
;
int
ip_family
;
std
::
string
ip
;
std
::
string
ip
;
MS_PORT
port
;
uint16_t
port
;
Utils
::
IP
::
GetAddressInfo
(
this
->
GetLocalAddress
(),
&
ip_family
,
ip
,
&
port
);
Utils
::
IP
::
GetAddressInfo
(
this
->
GetLocalAddress
(),
&
ip_family
,
ip
,
&
port
);
json_local
[
k_ip
]
=
ip
;
json_local
[
k_ip
]
=
ip
;
...
@@ -64,7 +64,7 @@ namespace RTC
...
@@ -64,7 +64,7 @@ namespace RTC
{
{
int
remote_family
;
int
remote_family
;
std
::
string
remote_ip
;
std
::
string
remote_ip
;
MS_PORT
remote_port
;
uint16_t
remote_port
;
Utils
::
IP
::
GetAddressInfo
(
GetRemoteAddress
(),
&
remote_family
,
remote_ip
,
&
remote_port
);
Utils
::
IP
::
GetAddressInfo
(
GetRemoteAddress
(),
&
remote_family
,
remote_ip
,
&
remote_port
);
...
...
worker/src/RTC/UDPSocket.cpp
浏览文件 @
a675da25
...
@@ -24,10 +24,10 @@ namespace RTC
...
@@ -24,10 +24,10 @@ namespace RTC
struct
sockaddr_storage
UDPSocket
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
UDPSocket
::
sockaddrStorageIPv4
;
struct
sockaddr_storage
UDPSocket
::
sockaddrStorageIPv6
;
struct
sockaddr_storage
UDPSocket
::
sockaddrStorageIPv6
;
MS_PORT
UDPSocket
::
minPort
;
uint16_t
UDPSocket
::
minPort
;
MS_PORT
UDPSocket
::
maxPort
;
uint16_t
UDPSocket
::
maxPort
;
std
::
unordered_map
<
MS_PORT
,
bool
>
UDPSocket
::
availableIPv4Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
UDPSocket
::
availableIPv4Ports
;
std
::
unordered_map
<
MS_PORT
,
bool
>
UDPSocket
::
availableIPv6Ports
;
std
::
unordered_map
<
uint16_t
,
bool
>
UDPSocket
::
availableIPv6Ports
;
/* Class methods. */
/* Class methods. */
...
@@ -54,7 +54,7 @@ namespace RTC
...
@@ -54,7 +54,7 @@ namespace RTC
UDPSocket
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
UDPSocket
::
minPort
=
Settings
::
configuration
.
rtcMinPort
;
UDPSocket
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
UDPSocket
::
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
MS_PORT
i
=
RTC
::
UDPSocket
::
minPort
;
uint16_t
i
=
RTC
::
UDPSocket
::
minPort
;
do
do
{
{
RTC
::
UDPSocket
::
availableIPv4Ports
[
i
]
=
true
;
RTC
::
UDPSocket
::
availableIPv4Ports
[
i
]
=
true
;
...
@@ -103,13 +103,13 @@ namespace RTC
...
@@ -103,13 +103,13 @@ namespace RTC
struct
sockaddr_storage
first_bind_addr
;
struct
sockaddr_storage
first_bind_addr
;
struct
sockaddr_storage
second_bind_addr
;
struct
sockaddr_storage
second_bind_addr
;
const
char
*
listenIP
;
const
char
*
listenIP
;
MS_PORT
random_first_port
;
uint16_t
random_first_port
;
MS_PORT
iterate_first_port
;
uint16_t
iterate_first_port
;
MS_PORT
iterate_second_port
;
uint16_t
iterate_second_port
;
uint16_t
attempt
=
0
;
uint16_t
attempt
=
0
;
uint16_t
bindAttempt
=
0
;
uint16_t
bindAttempt
=
0
;
int
flags
=
0
;
int
flags
=
0
;
std
::
unordered_map
<
MS_PORT
,
bool
>*
available_ports
;
std
::
unordered_map
<
uint16_t
,
bool
>*
available_ports
;
switch
(
address_family
)
switch
(
address_family
)
{
{
...
@@ -135,7 +135,7 @@ namespace RTC
...
@@ -135,7 +135,7 @@ namespace RTC
}
}
// Choose a random first port to start from.
// Choose a random first port to start from.
random_first_port
=
(
MS_PORT
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
UDPSocket
::
minPort
,
(
uint32_t
)
RTC
::
UDPSocket
::
maxPort
);
random_first_port
=
(
uint16_t
)
Utils
::
Crypto
::
GetRandomUInt
((
uint32_t
)
RTC
::
UDPSocket
::
minPort
,
(
uint32_t
)
RTC
::
UDPSocket
::
maxPort
);
// Make it even if pair is requested.
// Make it even if pair is requested.
if
(
pair
)
if
(
pair
)
random_first_port
&=
~
1
;
random_first_port
&=
~
1
;
...
@@ -320,7 +320,7 @@ namespace RTC
...
@@ -320,7 +320,7 @@ namespace RTC
MS_TRACE
();
MS_TRACE
();
}
}
void
UDPSocket
::
userOnUDPDatagramRecv
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
void
UDPSocket
::
userOnUDPDatagramRecv
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -334,7 +334,7 @@ namespace RTC
...
@@ -334,7 +334,7 @@ namespace RTC
if
(
Logger
::
HasDebugLevel
())
if
(
Logger
::
HasDebugLevel
())
{
{
int
family
;
int
family
;
MS_PORT
port
;
uint16_t
port
;
std
::
string
ip
;
std
::
string
ip
;
Utils
::
IP
::
GetAddressInfo
(
addr
,
&
family
,
ip
,
&
port
);
Utils
::
IP
::
GetAddressInfo
(
addr
,
&
family
,
ip
,
&
port
);
...
...
worker/src/Settings.cpp
浏览文件 @
a675da25
...
@@ -238,7 +238,7 @@ void Settings::SetDefaultRtcListenIP(int requested_family)
...
@@ -238,7 +238,7 @@ void Settings::SetDefaultRtcListenIP(int requested_family)
continue
;
continue
;
int
family
;
int
family
;
MS_PORT
port
;
uint16_t
port
;
std
::
string
ip
;
std
::
string
ip
;
Utils
::
IP
::
GetAddressInfo
((
struct
sockaddr
*
)(
&
address
.
address
.
address4
),
&
family
,
ip
,
&
port
);
Utils
::
IP
::
GetAddressInfo
((
struct
sockaddr
*
)(
&
address
.
address
.
address4
),
&
family
,
ip
,
&
port
);
...
@@ -371,8 +371,8 @@ void Settings::SetRtcPorts()
...
@@ -371,8 +371,8 @@ void Settings::SetRtcPorts()
{
{
MS_TRACE
();
MS_TRACE
();
MS_PORT
minPort
=
Settings
::
configuration
.
rtcMinPort
;
uint16_t
minPort
=
Settings
::
configuration
.
rtcMinPort
;
MS_PORT
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
uint16_t
maxPort
=
Settings
::
configuration
.
rtcMaxPort
;
if
(
minPort
<
1024
)
if
(
minPort
<
1024
)
MS_THROW_ERROR
(
"rtcMinPort must be greater or equal than 1024"
);
MS_THROW_ERROR
(
"rtcMinPort must be greater or equal than 1024"
);
...
...
worker/src/Utils/Crypto.cpp
浏览文件 @
a675da25
...
@@ -10,8 +10,8 @@ namespace Utils
...
@@ -10,8 +10,8 @@ namespace Utils
uint32_t
Crypto
::
seed
;
uint32_t
Crypto
::
seed
;
HMAC_CTX
Crypto
::
hmacSha1Ctx
;
HMAC_CTX
Crypto
::
hmacSha1Ctx
;
MS_BYTE
Crypto
::
hmacSha1Buffer
[
20
];
// SHA-1 result is 20 bytes long.
uint8_t
Crypto
::
hmacSha1Buffer
[
20
];
// SHA-1 result is 20 bytes long.
const
MS_4BYTES
Crypto
::
crc32Table
[]
=
const
uint32_t
Crypto
::
crc32Table
[]
=
{
{
0x00000000
,
0x77073096
,
0xee0e612c
,
0x990951ba
,
0x076dc419
,
0x706af48f
,
0x00000000
,
0x77073096
,
0xee0e612c
,
0x990951ba
,
0x076dc419
,
0x706af48f
,
0xe963a535
,
0x9e6495a3
,
0x0edb8832
,
0x79dcb8a4
,
0xe0d5e91e
,
0x97d2d988
,
0xe963a535
,
0x9e6495a3
,
0x0edb8832
,
0x79dcb8a4
,
0xe0d5e91e
,
0x97d2d988
,
...
@@ -79,7 +79,7 @@ namespace Utils
...
@@ -79,7 +79,7 @@ namespace Utils
HMAC_CTX_cleanup
(
&
Crypto
::
hmacSha1Ctx
);
HMAC_CTX_cleanup
(
&
Crypto
::
hmacSha1Ctx
);
}
}
const
MS_BYTE
*
Crypto
::
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
MS_BYTE
*
data
,
size_t
len
)
const
uint8_t
*
Crypto
::
GetHMAC_SHA1
(
const
std
::
string
&
key
,
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/Utils/IP.cpp
浏览文件 @
a675da25
...
@@ -3452,7 +3452,7 @@ case 85:
...
@@ -3452,7 +3452,7 @@ case 85:
return
AF_UNSPEC
;
return
AF_UNSPEC
;
}
}
void
IP
::
GetAddressInfo
(
const
struct
sockaddr
*
addr
,
int
*
family
,
std
::
string
&
ip
,
MS_PORT
*
port
)
void
IP
::
GetAddressInfo
(
const
struct
sockaddr
*
addr
,
int
*
family
,
std
::
string
&
ip
,
uint16_t
*
port
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -3465,13 +3465,13 @@ case 85:
...
@@ -3465,13 +3465,13 @@ case 85:
err
=
uv_inet_ntop
(
AF_INET
,
&
((
struct
sockaddr_in
*
)
addr
)
->
sin_addr
,
_ip
,
INET_ADDRSTRLEN
);
err
=
uv_inet_ntop
(
AF_INET
,
&
((
struct
sockaddr_in
*
)
addr
)
->
sin_addr
,
_ip
,
INET_ADDRSTRLEN
);
if
(
err
)
if
(
err
)
MS_ABORT
(
"uv_inet_ntop() failed: %s"
,
uv_strerror
(
err
));
MS_ABORT
(
"uv_inet_ntop() failed: %s"
,
uv_strerror
(
err
));
*
port
=
(
MS_PORT
)
ntohs
(((
struct
sockaddr_in
*
)
addr
)
->
sin_port
);
*
port
=
(
uint16_t
)
ntohs
(((
struct
sockaddr_in
*
)
addr
)
->
sin_port
);
break
;
break
;
case
AF_INET6
:
case
AF_INET6
:
err
=
uv_inet_ntop
(
AF_INET6
,
&
((
struct
sockaddr_in6
*
)
addr
)
->
sin6_addr
,
_ip
,
INET6_ADDRSTRLEN
);
err
=
uv_inet_ntop
(
AF_INET6
,
&
((
struct
sockaddr_in6
*
)
addr
)
->
sin6_addr
,
_ip
,
INET6_ADDRSTRLEN
);
if
(
err
)
if
(
err
)
MS_ABORT
(
"uv_inet_ntop() failed: %s"
,
uv_strerror
(
err
));
MS_ABORT
(
"uv_inet_ntop() failed: %s"
,
uv_strerror
(
err
));
*
port
=
(
MS_PORT
)
ntohs
(((
struct
sockaddr_in6
*
)
addr
)
->
sin6_port
);
*
port
=
(
uint16_t
)
ntohs
(((
struct
sockaddr_in6
*
)
addr
)
->
sin6_port
);
break
;
break
;
default
:
default
:
MS_ABORT
(
"unknown network family: %d"
,
(
int
)
addr
->
sa_family
);
MS_ABORT
(
"unknown network family: %d"
,
(
int
)
addr
->
sa_family
);
...
...
worker/src/Utils/IP.rl
浏览文件 @
a675da25
...
@@ -68,7 +68,7 @@ namespace Utils
...
@@ -68,7 +68,7 @@ namespace Utils
return AF_UNSPEC;
return AF_UNSPEC;
}
}
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip,
MS_PORT
* port)
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip,
uint16_t
* port)
{
{
MS_TRACE();
MS_TRACE();
...
@@ -81,13 +81,13 @@ namespace Utils
...
@@ -81,13 +81,13 @@ namespace Utils
err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, INET_ADDRSTRLEN);
err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, INET_ADDRSTRLEN);
if (err)
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (
MS_PORT
)ntohs(((struct sockaddr_in*)addr)->sin_port);
*port = (
uint16_t
)ntohs(((struct sockaddr_in*)addr)->sin_port);
break;
break;
case AF_INET6:
case AF_INET6:
err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, INET6_ADDRSTRLEN);
err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, INET6_ADDRSTRLEN);
if (err)
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (
MS_PORT
)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
*port = (
uint16_t
)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
break;
break;
default:
default:
MS_ABORT("unknown network family: %d", (int)addr->sa_family);
MS_ABORT("unknown network family: %d", (int)addr->sa_family);
...
...
worker/src/handles/TCPConnection.cpp
浏览文件 @
a675da25
...
@@ -71,7 +71,7 @@ TCPConnection::~TCPConnection()
...
@@ -71,7 +71,7 @@ TCPConnection::~TCPConnection()
delete
[]
this
->
buffer
;
delete
[]
this
->
buffer
;
}
}
void
TCPConnection
::
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
MS_PORT
localPort
)
void
TCPConnection
::
Setup
(
Listener
*
listener
,
struct
sockaddr_storage
*
localAddr
,
const
std
::
string
&
localIP
,
uint16_t
localPort
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -155,7 +155,7 @@ void TCPConnection::Start()
...
@@ -155,7 +155,7 @@ void TCPConnection::Start()
MS_THROW_ERROR
(
"error setting peer IP and port"
);
MS_THROW_ERROR
(
"error setting peer IP and port"
);
}
}
void
TCPConnection
::
Write
(
const
MS_BYTE
*
data
,
size_t
len
)
void
TCPConnection
::
Write
(
const
uint8_t
*
data
,
size_t
len
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -213,7 +213,7 @@ void TCPConnection::Write(const MS_BYTE* data, size_t len)
...
@@ -213,7 +213,7 @@ void TCPConnection::Write(const MS_BYTE* data, size_t len)
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
MS_ABORT
(
"uv_write() failed: %s"
,
uv_strerror
(
err
));
}
}
void
TCPConnection
::
Write
(
const
MS_BYTE
*
data1
,
size_t
len1
,
const
MS_BYTE
*
data2
,
size_t
len2
)
void
TCPConnection
::
Write
(
const
uint8_t
*
data1
,
size_t
len1
,
const
uint8_t
*
data2
,
size_t
len2
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -311,7 +311,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
...
@@ -311,7 +311,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
if
(
!
this
->
buffer
)
if
(
!
this
->
buffer
)
this
->
buffer
=
new
MS_BYTE
[
this
->
bufferSize
];
this
->
buffer
=
new
uint8_t
[
this
->
bufferSize
];
// Tell UV to write after the last data byte in the buffer.
// Tell UV to write after the last data byte in the buffer.
buf
->
base
=
(
char
*
)(
this
->
buffer
+
this
->
bufferDataLen
);
buf
->
base
=
(
char
*
)(
this
->
buffer
+
this
->
bufferDataLen
);
...
...
worker/src/handles/TCPServer.cpp
浏览文件 @
a675da25
...
@@ -28,7 +28,7 @@ void on_error_close(uv_handle_t* handle)
...
@@ -28,7 +28,7 @@ void on_error_close(uv_handle_t* handle)
/* Instance methods. */
/* Instance methods. */
TCPServer
::
TCPServer
(
const
std
::
string
&
ip
,
MS_PORT
port
,
int
backlog
)
TCPServer
::
TCPServer
(
const
std
::
string
&
ip
,
uint16_t
port
,
int
backlog
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -173,7 +173,7 @@ const std::string& TCPServer::GetLocalIP()
...
@@ -173,7 +173,7 @@ const std::string& TCPServer::GetLocalIP()
return
this
->
localIP
;
return
this
->
localIP
;
}
}
MS_PORT
TCPServer
::
GetLocalPort
()
uint16_t
TCPServer
::
GetLocalPort
()
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/handles/Timer.cpp
浏览文件 @
a675da25
...
@@ -50,7 +50,7 @@ void Timer::Close()
...
@@ -50,7 +50,7 @@ void Timer::Close()
delete
this
;
delete
this
;
}
}
void
Timer
::
Start
(
MS_8BYTES
timeout
)
void
Timer
::
Start
(
uint64_t
timeout
)
{
{
MS_TRACE
();
MS_TRACE
();
...
...
worker/src/handles/UDPSocket.cpp
浏览文件 @
a675da25
...
@@ -50,11 +50,11 @@ void on_error_close(uv_handle_t* handle)
...
@@ -50,11 +50,11 @@ void on_error_close(uv_handle_t* handle)
/* Class variables. */
/* Class variables. */
MS_BYTE
UDPSocket
::
readBuffer
[
MS_READ_BUFFER_SIZE
];
uint8_t
UDPSocket
::
readBuffer
[
MS_READ_BUFFER_SIZE
];
/* Instance methods. */
/* Instance methods. */
UDPSocket
::
UDPSocket
(
const
std
::
string
&
ip
,
MS_PORT
port
)
UDPSocket
::
UDPSocket
(
const
std
::
string
&
ip
,
uint16_t
port
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -176,7 +176,7 @@ void UDPSocket::Dump()
...
@@ -176,7 +176,7 @@ void UDPSocket::Dump()
(
!
this
->
isClosing
)
?
"open"
:
"closed"
);
(
!
this
->
isClosing
)
?
"open"
:
"closed"
);
}
}
void
UDPSocket
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
void
UDPSocket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
struct
sockaddr
*
addr
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -239,7 +239,7 @@ void UDPSocket::Send(const MS_BYTE* data, size_t len, const struct sockaddr* add
...
@@ -239,7 +239,7 @@ void UDPSocket::Send(const MS_BYTE* data, size_t len, const struct sockaddr* add
}
}
}
}
void
UDPSocket
::
Send
(
const
MS_BYTE
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
MS_PORT
port
)
void
UDPSocket
::
Send
(
const
uint8_t
*
data
,
size_t
len
,
const
std
::
string
&
ip
,
uint16_t
port
)
{
{
MS_TRACE
();
MS_TRACE
();
...
@@ -333,7 +333,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
...
@@ -333,7 +333,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
if
(
nread
>
0
)
if
(
nread
>
0
)
{
{
// Notify the subclass.
// Notify the subclass.
userOnUDPDatagramRecv
((
MS_BYTE
*
)
buf
->
base
,
nread
,
addr
);
userOnUDPDatagramRecv
((
uint8_t
*
)
buf
->
base
,
nread
,
addr
);
}
}
// Some error.
// Some error.
...
...
worker/src/handles/UnixStreamSocket.cpp
浏览文件 @
a675da25
...
@@ -138,7 +138,7 @@ void UnixStreamSocket::Close()
...
@@ -138,7 +138,7 @@ void UnixStreamSocket::Close()
}
}
}
}
void
UnixStreamSocket
::
Write
(
const
MS_BYTE
*
data
,
size_t
len
)
void
UnixStreamSocket
::
Write
(
const
uint8_t
*
data
,
size_t
len
)
{
{
if
(
this
->
isClosing
)
if
(
this
->
isClosing
)
return
;
return
;
...
@@ -198,7 +198,7 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
...
@@ -198,7 +198,7 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
if
(
!
this
->
buffer
)
if
(
!
this
->
buffer
)
this
->
buffer
=
new
MS_BYTE
[
this
->
bufferSize
];
this
->
buffer
=
new
uint8_t
[
this
->
bufferSize
];
// Tell UV to write after the last data byte in the buffer.
// Tell UV to write after the last data byte in the buffer.
buf
->
base
=
(
char
*
)(
this
->
buffer
+
this
->
bufferDataLen
);
buf
->
base
=
(
char
*
)(
this
->
buffer
+
this
->
bufferDataLen
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论