Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test usrsctp with usrsctp_get_timeout() #1351

Draft
wants to merge 1 commit into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions worker/include/DepUsrSCTP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DepUsrSCTP
public:
void Start();
void Stop();
void HandleUsrSctpTimers();

/* Pure virtual methods inherited from TimerHandle::Listener. */
public:
Expand All @@ -37,6 +38,7 @@ class DepUsrSCTP
static void RegisterSctpAssociation(RTC::SctpAssociation* sctpAssociation);
static void DeregisterSctpAssociation(RTC::SctpAssociation* sctpAssociation);
static RTC::SctpAssociation* RetrieveSctpAssociation(uintptr_t id);
static void HandleUsrSctpTimers();

private:
thread_local static Checker* checker;
Expand Down
39 changes: 35 additions & 4 deletions worker/src/DepUsrSCTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,42 @@

/* Static. */

static constexpr size_t CheckerInterval{ 10u }; // In ms.
static std::mutex GlobalSyncMutex;
static size_t GlobalInstances{ 0u };

/* Static methods for usrsctp global callbacks. */

inline static int onSendSctpData(void* addr, void* data, size_t len, uint8_t /*tos*/, uint8_t /*setDf*/)
static int onSendSctpData(void* addr, void* data, size_t len, uint8_t /*tos*/, uint8_t /*setDf*/)
{
MS_TRACE();

auto* sctpAssociation = DepUsrSCTP::RetrieveSctpAssociation(reinterpret_cast<uintptr_t>(addr));

if (!sctpAssociation)
{
MS_WARN_TAG(sctp, "no SctpAssociation found");

DepUsrSCTP::HandleUsrSctpTimers();

// TODO: Why are we returning -1 here? What does it tell usrsctp?
// If the SctpAssociation doesn't exist anymore we don't want that usrscp
// insists.
return -1;
}

sctpAssociation->OnUsrSctpSendSctpData(data, len);

// NOTE: Must not free data, usrsctp lib does it.

DepUsrSCTP::HandleUsrSctpTimers();

return 0;
}

// Static method for printing usrsctp debug.
inline static void sctpDebug(const char* format, ...)
static void sctpDebug(const char* format, ...)
{
MS_TRACE();
char buffer[10000];
va_list ap;

Expand Down Expand Up @@ -207,6 +216,13 @@ RTC::SctpAssociation* DepUsrSCTP::RetrieveSctpAssociation(uintptr_t id)
return it->second;
}

void DepUsrSCTP::HandleUsrSctpTimers()
{
MS_TRACE();

DepUsrSCTP::checker->HandleUsrSctpTimers();
}

/* DepUsrSCTP::Checker instance methods. */

DepUsrSCTP::Checker::Checker() : timer(new TimerHandle(this))
Expand All @@ -229,7 +245,7 @@ void DepUsrSCTP::Checker::Start()

this->lastCalledAtMs = 0u;

this->timer->Start(CheckerInterval, CheckerInterval);
HandleUsrSctpTimers();
}

void DepUsrSCTP::Checker::Stop()
Expand All @@ -243,10 +259,23 @@ void DepUsrSCTP::Checker::Stop()
this->timer->Stop();
}

void DepUsrSCTP::Checker::HandleUsrSctpTimers()
{
MS_TRACE();

auto timeout = static_cast<uint64_t>(usrsctp_get_timeout());

MS_DUMP("------ starting timer with usrsctp timeout: %" PRIu64 " ms", timeout);

this->timer->Start(timeout);
}

void DepUsrSCTP::Checker::OnTimer(TimerHandle* /*timer*/)
{
MS_TRACE();

MS_DUMP("------ onTimer!");

auto nowMs = DepLibUV::GetTimeMs();
const int elapsedMs = this->lastCalledAtMs ? static_cast<int>(nowMs - this->lastCalledAtMs) : 0;

Expand All @@ -267,4 +296,6 @@ void DepUsrSCTP::Checker::OnTimer(TimerHandle* /*timer*/)
#endif

this->lastCalledAtMs = nowMs;

HandleUsrSctpTimers();
}
4 changes: 4 additions & 0 deletions worker/src/RTC/SctpAssociation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ namespace RTC
#endif

usrsctp_conninput(reinterpret_cast<void*>(this->id), data, len, 0);

// TODO: IMHO it makes sense that we handle/refresh usrsctp timers when
// SCTP data is received.
DepUsrSCTP::HandleUsrSctpTimers();
}

void SctpAssociation::SendSctpMessage(
Expand Down
8 changes: 4 additions & 4 deletions worker/subprojects/usrsctp.wrap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[wrap-file]
directory = usrsctp-ebb18adac6501bad4501b1f6dccb67a1c85cc299
source_url = https://github.com/sctplab/usrsctp/archive/ebb18adac6501bad4501b1f6dccb67a1c85cc299.zip
source_filename = ebb18adac6501bad4501b1f6dccb67a1c85cc299.zip
source_hash = e77a855ce395b877e9f2aa7ebe070dfaf5cb11cfecdeb424cc876fc0d98e5d11
directory = usrsctp-0.9.6.0
source_url = https://github.com/versatica/usrsctp/archive/refs/tags/0.9.6.0.zip
source_filename = usrsctp-0.9.6.0.zip
source_hash = 13518f1912631c796da167ba3c3e4fd7f80886de4afa75abc6fcf843160b65f8

[provide]
usrsctp = usrsctp_dep
Loading