Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
9af2a269
Unverified
提交
9af2a269
authored
2月 27, 2024
作者:
Iñaki Baz Castillo
提交者:
GitHub
2月 27, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix DTLS packets do not honor configured DTLS MTU (attempt 3) (#1345)
上级
898c760f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
86 行增加
和
59 行删除
+86
-59
CHANGELOG.md
CHANGELOG.md
+4
-0
DtlsTransport.hpp
worker/include/RTC/DtlsTransport.hpp
+2
-1
DtlsTransport.cpp
worker/src/RTC/DtlsTransport.cpp
+80
-58
没有找到文件。
CHANGELOG.md
浏览文件 @
9af2a269
# Changelog
### Next
-
Fix DTLS packets do not honor configured DTLS MTU (attempt 3) (
[
PR #1345
](
https://github.com/versatica/mediasoup/pull/1345
)
).
### 3.13.22
-
Fix wrong publication of mediasoup NPM 3.13.21.
...
...
worker/include/RTC/DtlsTransport.hpp
浏览文件 @
9af2a269
...
...
@@ -152,6 +152,8 @@ namespace RTC
return
this
->
localRole
;
}
void
SendApplicationData
(
const
uint8_t
*
data
,
size_t
len
);
// This method must be public since it's called within an OpenSSL callback.
void
SendDtlsData
(
const
uint8_t
*
data
,
size_t
len
);
private
:
bool
IsRunning
()
const
...
...
@@ -173,7 +175,6 @@ namespace RTC
}
void
Reset
();
bool
CheckStatus
(
int
returnCode
);
void
SendPendingOutgoingDtlsData
();
bool
SetTimeout
();
bool
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
...
...
worker/src/RTC/DtlsTransport.cpp
浏览文件 @
9af2a269
...
...
@@ -47,15 +47,49 @@ inline static void onSslInfo(const SSL* ssl, int where, int ret)
static_cast
<
RTC
::
DtlsTransport
*>
(
SSL_get_ex_data
(
ssl
,
0
))
->
OnSslInfo
(
where
,
ret
);
}
/**
* This callback is called by OpenSSL when it wants to send DTLS data to the
* endpoint. Such a data could be a full DTLS message, various DTLS messages,
* a DTLS message fragment, various DTLS message fragments or a combination of
* these. It's guaranteed (by observation) that |len| argument corresponds to
* the entire content of our BIO mem buffer |this->sslBioToNetwork| and it
* never exceeds our |DtlsMtu| limit.
*/
inline
static
long
onSslBioOut
(
BIO
*
bio
,
int
operationType
,
const
char
*
argp
,
size_t
len
,
int
/*argi*/
,
long
/*argl*/
,
int
ret
,
size_t
*
/*processed*/
)
{
long
resultOfcallback
=
(
operationType
==
BIO_CB_RETURN
)
?
static_cast
<
long
>
(
ret
)
:
1
;
// This callback is called twice for write operations:
// - First one with operationType = BIO_CB_WRITE.
// - Second one with operationType = BIO_CB_RETURN | BIO_CB_WRITE.
// We only care about the former.
if
((
operationType
==
BIO_CB_WRITE
)
&&
argp
&&
len
>
0
)
{
auto
*
dtlsTransport
=
reinterpret_cast
<
RTC
::
DtlsTransport
*>
(
BIO_get_callback_arg
(
bio
));
dtlsTransport
->
SendDtlsData
(
reinterpret_cast
<
const
uint8_t
*>
(
argp
),
len
);
}
return
resultOfcallback
;
}
inline
static
unsigned
int
onSslDtlsTimer
(
SSL
*
/*ssl*/
,
unsigned
int
timerUs
)
{
if
(
timerUs
==
0
)
if
(
timerUs
==
0
u
)
{
return
100000
;
return
100000
u
;
}
else
if
(
timerUs
>=
4000000
)
else
if
(
timerUs
>=
4000000
u
)
{
return
4000000
;
return
4000000
u
;
}
else
{
...
...
@@ -71,15 +105,15 @@ namespace RTC
static
constexpr
int
DtlsMtu
{
1350
};
static
constexpr
int
SslReadBufferSize
{
65536
};
// AES-HMAC: http://tools.ietf.org/html/rfc3711
static
constexpr
size_t
SrtpMasterKeyLength
{
16
};
static
constexpr
size_t
SrtpMasterSaltLength
{
14
};
static
constexpr
size_t
SrtpMasterKeyLength
{
16
u
};
static
constexpr
size_t
SrtpMasterSaltLength
{
14
u
};
static
constexpr
size_t
SrtpMasterLength
{
SrtpMasterKeyLength
+
SrtpMasterSaltLength
};
// AES-GCM: http://tools.ietf.org/html/rfc7714
static
constexpr
size_t
SrtpAesGcm256MasterKeyLength
{
32
};
static
constexpr
size_t
SrtpAesGcm256MasterSaltLength
{
12
};
static
constexpr
size_t
SrtpAesGcm256MasterKeyLength
{
32
u
};
static
constexpr
size_t
SrtpAesGcm256MasterSaltLength
{
12
u
};
static
constexpr
size_t
SrtpAesGcm256MasterLength
{
SrtpAesGcm256MasterKeyLength
+
SrtpAesGcm256MasterSaltLength
};
static
constexpr
size_t
SrtpAesGcm128MasterKeyLength
{
16
};
static
constexpr
size_t
SrtpAesGcm128MasterSaltLength
{
12
};
static
constexpr
size_t
SrtpAesGcm128MasterKeyLength
{
16
u
};
static
constexpr
size_t
SrtpAesGcm128MasterSaltLength
{
12
u
};
static
constexpr
size_t
SrtpAesGcm128MasterLength
{
SrtpAesGcm128MasterKeyLength
+
SrtpAesGcm128MasterSaltLength
};
// clang-format on
...
...
@@ -708,15 +742,19 @@ namespace RTC
goto
error
;
}
SSL_set_bio
(
this
->
ssl
,
this
->
sslBioFromNetwork
,
this
->
sslBioToNetwork
);
// Set the MTU so that we don't send packets that are too large with no
// fragmentation.
// TODO: This is not honored, see issue:
// https://github.com/versatica/mediasoup/issues/1100
SSL_set_mtu
(
this
->
ssl
,
DtlsMtu
);
DTLS_set_link_mtu
(
this
->
ssl
,
DtlsMtu
);
// We want to monitor OpenSSL write operations into our |sslBioToNetwork|
// buffer so we can immediately send those DTLS bytes (containing full DTLS
// messages, or valid DTLS fragment messages, or combination of them) to
// the endpoint, and hence we honor the configured DTLS MTU.
BIO_set_callback_ex
(
this
->
sslBioToNetwork
,
onSslBioOut
);
BIO_set_callback_arg
(
this
->
sslBioToNetwork
,
reinterpret_cast
<
char
*>
(
this
));
SSL_set_bio
(
this
->
ssl
,
this
->
sslBioFromNetwork
,
this
->
sslBioToNetwork
);
// Set callback handler for setting DTLS timer interval.
DTLS_set_timer_cb
(
this
->
ssl
,
onSslDtlsTimer
);
...
...
@@ -757,7 +795,6 @@ namespace RTC
{
// Send close alert to the peer.
SSL_shutdown
(
this
->
ssl
);
SendPendingOutgoingDtlsData
();
}
if
(
this
->
ssl
)
...
...
@@ -880,7 +917,6 @@ namespace RTC
SSL_set_connect_state
(
this
->
ssl
);
SSL_do_handshake
(
this
->
ssl
);
SendPendingOutgoingDtlsData
();
SetTimeout
();
break
;
...
...
@@ -951,9 +987,6 @@ namespace RTC
// Must call SSL_read() to process received DTLS data.
read
=
SSL_read
(
this
->
ssl
,
static_cast
<
void
*>
(
DtlsTransport
::
sslReadBuffer
),
SslReadBufferSize
);
// Send data if it's ready.
SendPendingOutgoingDtlsData
();
// Check SSL status and return if it is bad/closed.
if
(
!
CheckStatus
(
read
))
{
...
...
@@ -1022,9 +1055,31 @@ namespace RTC
MS_WARN_TAG
(
dtls
,
"OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)"
,
written
,
len
);
}
}
/**
* This method is called within our |onSslBioOut| callback above. As told
* there, it's guaranteed that OpenSSL invokes that callback with all the
* bytes currently written in our BIO mem buffer |this->sslBioToNetwork| so
* we can safely reset/clear that buffer once we have sent the data to the
* endpoint.
*/
void
DtlsTransport
::
SendDtlsData
(
const
uint8_t
*
data
,
size_t
len
)
{
MS_TRACE
();
MS_DEBUG_DEV
(
"%zu bytes of DTLS data ready to be sent"
,
len
);
// Send data.
SendPendingOutgoingDtlsData
();
// Notify the listener.
this
->
listener
->
OnDtlsTransportSendData
(
this
,
data
,
len
);
// Clear the BIO buffer.
auto
ret
=
BIO_reset
(
this
->
sslBioToNetwork
);
if
(
ret
!=
1
)
{
MS_ERROR
(
"BIO_reset() failed [ret:%d]"
,
ret
);
}
}
void
DtlsTransport
::
Reset
()
...
...
@@ -1044,8 +1099,9 @@ namespace RTC
this
->
timer
->
Stop
();
// NOTE: We need to reset the SSL instance so we need to "shutdown" it, but
// we don't want to send a Close Alert to the peer, so just don't call
// SendPendingOutgoingDTLSData().
// we don't want to send a DTLS Close Alert to the peer. However this is
// gonna happen since SSL_shutdown() will trigger a DTLS Close Alert and
// we'll have our onSslBioOut() callback called to deliver it.
SSL_shutdown
(
this
->
ssl
);
this
->
localRole
.
reset
();
...
...
@@ -1069,10 +1125,9 @@ namespace RTC
{
MS_TRACE
();
int
err
;
const
bool
wasHandshakeDone
=
this
->
handshakeDone
;
err
=
SSL_get_error
(
this
->
ssl
,
returnCode
);
int
err
=
SSL_get_error
(
this
->
ssl
,
returnCode
);
switch
(
err
)
{
...
...
@@ -1182,36 +1237,6 @@ namespace RTC
}
}
void
DtlsTransport
::
SendPendingOutgoingDtlsData
()
{
MS_TRACE
();
if
(
BIO_eof
(
this
->
sslBioToNetwork
))
{
return
;
}
int64_t
read
;
char
*
data
{
nullptr
};
read
=
BIO_get_mem_data
(
this
->
sslBioToNetwork
,
&
data
);
// NOLINT
if
(
read
<=
0
)
{
return
;
}
MS_DEBUG_DEV
(
"%"
PRIu64
" bytes of DTLS data ready to sent to the peer"
,
read
);
// Notify the listener.
this
->
listener
->
OnDtlsTransportSendData
(
this
,
reinterpret_cast
<
uint8_t
*>
(
data
),
static_cast
<
size_t
>
(
read
));
// Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning.
(
void
)
BIO_reset
(
this
->
sslBioToNetwork
);
}
bool
DtlsTransport
::
SetTimeout
()
{
MS_TRACE
();
...
...
@@ -1684,9 +1709,6 @@ namespace RTC
if
(
ret
==
1
)
{
// If required, send DTLS data.
SendPendingOutgoingDtlsData
();
// Set the DTLS timer again.
SetTimeout
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论