mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Fixed unordered flag and renamed reliability type for consistency
This commit is contained in:
@ -27,13 +27,9 @@
|
||||
namespace rtc {
|
||||
|
||||
struct Reliability {
|
||||
enum Type : uint8_t {
|
||||
TYPE_RELIABLE = 0x00,
|
||||
TYPE_PARTIAL_RELIABLE_REXMIT = 0x01,
|
||||
TYPE_PARTIAL_RELIABLE_TIMED = 0x02,
|
||||
};
|
||||
enum class Type { Reliable = 0, Rexmit, Timed };
|
||||
|
||||
Type type = TYPE_RELIABLE;
|
||||
Type type = Type::Reliable;
|
||||
bool unordered = false;
|
||||
std::variant<int, std::chrono::milliseconds> rexmit = 0;
|
||||
};
|
||||
|
@ -31,6 +31,7 @@ namespace rtc {
|
||||
|
||||
using std::shared_ptr;
|
||||
using std::weak_ptr;
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
// Messages for the DataChannel establishment protocol
|
||||
// See https://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-09
|
||||
@ -43,6 +44,12 @@ enum MessageType : uint8_t {
|
||||
MESSAGE_CLOSE = 0x04
|
||||
};
|
||||
|
||||
enum ChannelType : uint8_t {
|
||||
CHANNEL_RELIABLE = 0x00,
|
||||
CHANNEL_PARTIAL_RELIABLE_REXMIT = 0x01,
|
||||
CHANNEL_PARTIAL_RELIABLE_TIMED = 0x02
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct OpenMessage {
|
||||
uint8_t type = MESSAGE_OPEN;
|
||||
@ -168,22 +175,33 @@ size_t DataChannel::availableAmount() const { return mRecvQueue.amount(); }
|
||||
void DataChannel::open(shared_ptr<SctpTransport> transport) {
|
||||
mSctpTransport = transport;
|
||||
|
||||
uint8_t channelType = static_cast<uint8_t>(mReliability->type);
|
||||
if (mReliability->unordered)
|
||||
channelType &= 0x80;
|
||||
|
||||
using std::chrono::milliseconds;
|
||||
uint32_t reliabilityParameter = 0;
|
||||
if (mReliability->type == Reliability::TYPE_PARTIAL_RELIABLE_REXMIT)
|
||||
uint8_t channelType;
|
||||
uint32_t reliabilityParameter;
|
||||
switch (mReliability->type) {
|
||||
case Reliability::Type::Rexmit:
|
||||
channelType = CHANNEL_PARTIAL_RELIABLE_REXMIT;
|
||||
reliabilityParameter = uint32_t(std::get<int>(mReliability->rexmit));
|
||||
else if (mReliability->type == Reliability::TYPE_PARTIAL_RELIABLE_TIMED)
|
||||
break;
|
||||
|
||||
case Reliability::Type::Timed:
|
||||
channelType = CHANNEL_PARTIAL_RELIABLE_TIMED;
|
||||
reliabilityParameter = uint32_t(std::get<milliseconds>(mReliability->rexmit).count());
|
||||
break;
|
||||
|
||||
default:
|
||||
channelType = CHANNEL_RELIABLE;
|
||||
reliabilityParameter = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mReliability->unordered)
|
||||
channelType |= 0x80;
|
||||
|
||||
const size_t len = sizeof(OpenMessage) + mLabel.size() + mProtocol.size();
|
||||
binary buffer(len, byte(0));
|
||||
auto &open = *reinterpret_cast<OpenMessage *>(buffer.data());
|
||||
open.type = MESSAGE_OPEN;
|
||||
open.channelType = mReliability->type;
|
||||
open.channelType = channelType;
|
||||
open.priority = htons(0);
|
||||
open.reliabilityParameter = htonl(reliabilityParameter);
|
||||
open.labelLength = htons(uint16_t(mLabel.size()));
|
||||
@ -272,19 +290,18 @@ void DataChannel::processOpenMessage(message_ptr message) {
|
||||
mLabel.assign(end, open.labelLength);
|
||||
mProtocol.assign(end + open.labelLength, open.protocolLength);
|
||||
|
||||
using std::chrono::milliseconds;
|
||||
mReliability->unordered = (open.reliabilityParameter & 0x80) != 0;
|
||||
switch (open.channelType & 0x7F) {
|
||||
case Reliability::TYPE_PARTIAL_RELIABLE_REXMIT:
|
||||
mReliability->type = Reliability::TYPE_PARTIAL_RELIABLE_REXMIT;
|
||||
case CHANNEL_PARTIAL_RELIABLE_REXMIT:
|
||||
mReliability->type = Reliability::Type::Rexmit;
|
||||
mReliability->rexmit = int(open.reliabilityParameter);
|
||||
break;
|
||||
case Reliability::TYPE_PARTIAL_RELIABLE_TIMED:
|
||||
mReliability->type = Reliability::TYPE_PARTIAL_RELIABLE_TIMED;
|
||||
case CHANNEL_PARTIAL_RELIABLE_TIMED:
|
||||
mReliability->type = Reliability::Type::Timed;
|
||||
mReliability->rexmit = milliseconds(open.reliabilityParameter);
|
||||
break;
|
||||
default:
|
||||
mReliability->type = Reliability::TYPE_RELIABLE;
|
||||
mReliability->type = Reliability::Type::Reliable;
|
||||
mReliability->rexmit = int(0);
|
||||
}
|
||||
|
||||
|
10
src/rtc.cpp
10
src/rtc.cpp
@ -254,14 +254,14 @@ int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
r.unordered = reliability->unordered;
|
||||
if (reliability->unreliable) {
|
||||
if (reliability->maxPacketLifeTime > 0) {
|
||||
r.type = Reliability::TYPE_PARTIAL_RELIABLE_TIMED;
|
||||
r.type = Reliability::Type::Timed;
|
||||
r.rexmit = milliseconds(reliability->maxPacketLifeTime);
|
||||
} else {
|
||||
r.type = Reliability::TYPE_PARTIAL_RELIABLE_REXMIT;
|
||||
r.type = Reliability::Type::Rexmit;
|
||||
r.rexmit = int(reliability->maxRetransmits);
|
||||
}
|
||||
} else {
|
||||
r.type = Reliability::TYPE_RELIABLE;
|
||||
r.type = Reliability::Type::Reliable;
|
||||
}
|
||||
}
|
||||
auto peerConnection = getPeerConnection(pc);
|
||||
@ -499,10 +499,10 @@ int rtcGetDataChannelReliability(int dc, rtcReliability *reliability) {
|
||||
Reliability r = dataChannel->reliability();
|
||||
std::memset(reliability, sizeof(*reliability), 0);
|
||||
reliability->unordered = r.unordered;
|
||||
if (r.type == Reliability::TYPE_PARTIAL_RELIABLE_TIMED) {
|
||||
if (r.type == Reliability::Type::Timed) {
|
||||
reliability->unreliable = true;
|
||||
reliability->maxPacketLifeTime = std::get<milliseconds>(r.rexmit).count();
|
||||
} else if (r.type == Reliability::TYPE_PARTIAL_RELIABLE_REXMIT) {
|
||||
} else if (r.type == Reliability::Type::Rexmit) {
|
||||
reliability->unreliable = true;
|
||||
reliability->maxRetransmits = unsigned(std::get<int>(r.rexmit));
|
||||
} else {
|
||||
|
@ -372,12 +372,12 @@ bool SctpTransport::trySendMessage(message_ptr message) {
|
||||
spa.sendv_sndinfo.snd_flags |= SCTP_UNORDERED;
|
||||
|
||||
switch (reliability.type) {
|
||||
case Reliability::TYPE_PARTIAL_RELIABLE_REXMIT:
|
||||
case Reliability::Type::Rexmit:
|
||||
spa.sendv_flags |= SCTP_SEND_PRINFO_VALID;
|
||||
spa.sendv_prinfo.pr_policy = SCTP_PR_SCTP_RTX;
|
||||
spa.sendv_prinfo.pr_value = uint32_t(std::get<int>(reliability.rexmit));
|
||||
break;
|
||||
case Reliability::TYPE_PARTIAL_RELIABLE_TIMED:
|
||||
case Reliability::Type::Timed:
|
||||
spa.sendv_flags |= SCTP_SEND_PRINFO_VALID;
|
||||
spa.sendv_prinfo.pr_policy = SCTP_PR_SCTP_TTL;
|
||||
spa.sendv_prinfo.pr_value = uint32_t(std::get<milliseconds>(reliability.rexmit).count());
|
||||
|
Reference in New Issue
Block a user