Compare commits

..

8 Commits

7 changed files with 28 additions and 18 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.7)
project(libdatachannel project(libdatachannel
VERSION 0.11.2 VERSION 0.11.4
LANGUAGES CXX) LANGUAGES CXX)
set(PROJECT_DESCRIPTION "WebRTC Data Channels Library") set(PROJECT_DESCRIPTION "WebRTC Data Channels Library")

2
deps/usrsctp vendored

View File

@ -298,13 +298,16 @@ public:
private: private:
uint8_t _length; uint8_t _length;
char _text; char _text[1];
public: public:
inline std::string text() const { return std::string(&_text, _length); } inline std::string text() const { return std::string(_text, _length); }
inline void setText(std::string text) { inline void setText(std::string text) {
_length = text.length(); if(text.size() > 0xFF)
memcpy(&_text, text.data(), _length); throw std::invalid_argument("text is too long");
_length = uint8_t(text.size());
memcpy(_text, text.data(), text.size());
} }
inline uint8_t length() { return _length; } inline uint8_t length() { return _length; }
@ -334,12 +337,12 @@ public:
return reinterpret_cast<RTCP_SDES_ITEM *>(base); return reinterpret_cast<RTCP_SDES_ITEM *>(base);
} }
long safelyCountChunkSize(unsigned int maxChunkSize) { long safelyCountChunkSize(size_t maxChunkSize) {
if (maxChunkSize < RTCP_SDES_CHUNK::size({})) { if (maxChunkSize < RTCP_SDES_CHUNK::size({})) {
// chunk is truncated // chunk is truncated
return -1; return -1;
} else { } else {
unsigned int size = sizeof(SSRC); size_t size = sizeof(SSRC);
unsigned int i = 0; unsigned int i = 0;
// We can always access first 4 bytes of first item (in case of no items there will be 4 // We can always access first 4 bytes of first item (in case of no items there will be 4
// null bytes) // null bytes)
@ -407,7 +410,7 @@ public:
auto chunk = getChunk(i); auto chunk = getChunk(i);
chunkSize += chunk->getSize(); chunkSize += chunk->getSize();
} }
uint16_t length = (sizeof(header) + chunkSize) / 4 - 1; uint16_t length = uint16_t((sizeof(header) + chunkSize) / 4 - 1);
header.prepareHeader(202, chunkCount, length); header.prepareHeader(202, chunkCount, length);
} }
@ -629,10 +632,10 @@ struct RTCP_NACK_PART {
std::vector<uint16_t> getSequenceNumbers() { std::vector<uint16_t> getSequenceNumbers() {
std::vector<uint16_t> result{}; std::vector<uint16_t> result{};
result.reserve(17); result.reserve(17);
auto pid = getPID(); uint16_t pid = getPID();
result.push_back(pid); result.push_back(pid);
auto bitmask = getBLP(); uint16_t bitmask = getBLP();
auto i = pid + 1; uint16_t i = pid + 1;
while (bitmask > 0) { while (bitmask > 0) {
if (bitmask & 0x1) { if (bitmask & 0x1) {
result.push_back(i); result.push_back(i);
@ -673,9 +676,9 @@ public:
(*fciCount)++; (*fciCount)++;
return true; return true;
} else { } else {
// TODO SPEEED! // TODO SPEED!
auto blp = parts[(*fciCount) - 1].getBLP(); uint16_t blp = parts[(*fciCount) - 1].getBLP();
auto newBit = 1u << (unsigned int)(missingPacket - (1 + *fciPID)); uint16_t newBit = uint16_t(1u << (missingPacket - (1 + *fciPID)));
parts[(*fciCount) - 1].setBLP(blp | newBit); parts[(*fciCount) - 1].setBLP(blp | newBit);
return false; return false;
} }

View File

@ -667,6 +667,8 @@ void PeerConnection::forwardMessage(message_ptr message) {
stream); stream);
channel->onOpen(weak_bind(&PeerConnection::triggerDataChannel, this, channel->onOpen(weak_bind(&PeerConnection::triggerDataChannel, this,
weak_ptr<DataChannel>{channel})); weak_ptr<DataChannel>{channel}));
std::unique_lock lock(mDataChannelsMutex); // we are going to emplace
mDataChannels.emplace(stream, channel); mDataChannels.emplace(stream, channel);
} else { } else {
// Invalid, close the DataChannel // Invalid, close the DataChannel

View File

@ -349,6 +349,10 @@ void SctpTransport::incoming(message_ptr message) {
} }
PLOG_VERBOSE << "Incoming size=" << message->size(); PLOG_VERBOSE << "Incoming size=" << message->size();
// TODO: There seems to be a possible data race between usrsctp_sendv() and usrsctp_conninput()
// As a mitigation, lock the send mutex before calling usrsctp_conninput()
std::lock_guard lock(mSendMutex);
usrsctp_conninput(this, message->data(), message->size(), 0); usrsctp_conninput(this, message->data(), message->size(), 0);
} }

View File

@ -43,8 +43,7 @@ int ThreadPool::count() const {
} }
void ThreadPool::spawn(int count) { void ThreadPool::spawn(int count) {
std::scoped_lock lock(mMutex, mWorkersMutex); std::unique_lock lock(mWorkersMutex);
mJoining = false;
while (count-- > 0) while (count-- > 0)
mWorkers.emplace_back(std::bind(&ThreadPool::run, this)); mWorkers.emplace_back(std::bind(&ThreadPool::run, this));
} }
@ -62,6 +61,8 @@ void ThreadPool::join() {
w.join(); w.join();
mWorkers.clear(); mWorkers.clear();
mJoining = false;
} }
void ThreadPool::run() { void ThreadPool::run() {

View File

@ -73,7 +73,7 @@ protected:
std::vector<std::thread> mWorkers; std::vector<std::thread> mWorkers;
int mWaitingWorkers = 0; int mWaitingWorkers = 0;
bool mJoining = false; std::atomic<bool> mJoining = false;
struct Task { struct Task {
clock::time_point time; clock::time_point time;