Skip to content

Commit

Permalink
Fixed possibility of race condition in DTLS
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Aug 3, 2020
1 parent 894db44 commit 4d90c66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/projects/modules/dtls_srtp/dtls_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ DtlsTransport::~DtlsTransport()

bool DtlsTransport::Stop()
{
std::lock_guard<std::mutex> lock(_tls_lock);

_tls.Uninitialize();

return SessionNode::Stop();
Expand All @@ -40,6 +42,8 @@ void DtlsTransport::SetPeerFingerprint(ov::String algorithm, ov::String fingerpr
// Start DTLS
bool DtlsTransport::StartDTLS()
{
std::lock_guard<std::mutex> lock(_tls_lock);

// Ice 상태가 Completed 일 경우에만 시작한다.
// Polling 방식이 아니므로 밖에서 이벤트를 확실하게 받고 진입해야 한다.
/*
Expand Down Expand Up @@ -109,7 +113,6 @@ bool DtlsTransport::StartDTLS()
bool DtlsTransport::ContinueSSL()
{
logtd("Continue DTLS...");

int error = _tls.Accept();

if(error == SSL_ERROR_NONE)
Expand Down Expand Up @@ -179,6 +182,8 @@ bool DtlsTransport::VerifyPeerCertificate()
// Session -> Makes SRTP Packet -> DtlsTransport -> Ice로 전송
bool DtlsTransport::SendData(pub::SessionNodeType from_node, const std::shared_ptr<ov::Data> &data)
{
std::lock_guard<std::mutex> lock(_tls_lock);

// Node 시작 전에는 아무것도 하지 않는다.
if(GetState() != SessionNode::NodeState::Started)
{
Expand Down Expand Up @@ -236,6 +241,8 @@ bool DtlsTransport::SendData(pub::SessionNodeType from_node, const std::shared_p
// IcePort -> Publisher ->[queue] Application {thread}-> Session -> DtlsTransport -> SRTP || SCTP
bool DtlsTransport::OnDataReceived(pub::SessionNodeType from_node, const std::shared_ptr<const ov::Data> &data)
{
std::lock_guard<std::mutex> lock(_tls_lock);

// Node 시작 전에는 아무것도 하지 않는다.
if(GetState() != SessionNode::NodeState::Started)
{
Expand Down
2 changes: 2 additions & 0 deletions src/projects/modules/dtls_srtp/dtls_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ class DtlsTransport : public pub::SessionNode
// SSL *_ssl;
// SSL_CTX *_ssl_ctx;

std::mutex _tls_lock;

ov::Tls _tls;
};

0 comments on commit 4d90c66

Please sign in to comment.