Skip to content

Commit 40ce0cf

Browse files
fix e2ee connection options defaults for proto
1 parent 2852238 commit 40ce0cf

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

src/ffi_client.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ namespace livekit {
3737

3838
namespace {
3939

40+
inline constexpr int kDefaultKeyRingSize = 16;
41+
inline constexpr proto::KeyDerivationFunction kDefaultKeyDerivationFunction = proto::PBKDF2;
42+
4043
std::string bytesToString(const std::vector<std::uint8_t>& b) {
4144
return std::string(reinterpret_cast<const char*>(b.data()), b.size());
4245
}
4346

47+
std::vector<std::uint8_t> defaultRatchetSalt() {
48+
return std::vector<std::uint8_t>(kDefaultRatchetSalt,
49+
kDefaultRatchetSalt + std::char_traits<char>::length(kDefaultRatchetSalt));
50+
}
51+
4452
inline void logAndThrow(const std::string& error_msg) {
4553
LK_LOG_ERROR("LiveKit SDK Error: {}", error_msg);
4654
throw std::runtime_error(error_msg);
@@ -340,28 +348,13 @@ std::future<proto::ConnectCallback> FfiClient::connectAsync(const std::string& u
340348
} else {
341349
kp->clear_shared_key();
342350
}
343-
// Only set ratchet_salt if caller overrides. Otherwise clear so Rust side
344-
// uses default.
345-
if (!kpo.ratchet_salt.empty() &&
346-
kpo.ratchet_salt !=
347-
std::vector<std::uint8_t>(kDefaultRatchetSalt,
348-
kDefaultRatchetSalt + std::char_traits<char>::length(kDefaultRatchetSalt))) {
349-
kp->set_ratchet_salt(bytesToString(kpo.ratchet_salt));
350-
} else {
351-
kp->clear_ratchet_salt();
352-
}
353-
// Same idea for window size / tolerance: set only on override; otherwise
354-
// clear.
355-
if (kpo.ratchet_window_size != kDefaultRatchetWindowSize) {
356-
kp->set_ratchet_window_size(kpo.ratchet_window_size);
357-
} else {
358-
kp->clear_ratchet_window_size();
359-
}
360-
if (kpo.failure_tolerance != kDefaultFailureTolerance) {
361-
kp->set_failure_tolerance(kpo.failure_tolerance);
362-
} else {
363-
kp->clear_failure_tolerance();
364-
}
351+
352+
const auto ratchet_salt = kpo.ratchet_salt.empty() ? defaultRatchetSalt() : kpo.ratchet_salt;
353+
kp->set_ratchet_window_size(kpo.ratchet_window_size);
354+
kp->set_ratchet_salt(bytesToString(ratchet_salt));
355+
kp->set_failure_tolerance(kpo.failure_tolerance);
356+
kp->set_key_ring_size(kDefaultKeyRingSize);
357+
kp->set_key_derivation_function(kDefaultKeyDerivationFunction);
365358
}
366359

367360
// --- RTC configuration (optional) ---

0 commit comments

Comments
 (0)