Skip to content

Commit

Permalink
Fire SCTP onopen for INIT/INIT_ACK
Browse files Browse the repository at this point in the history
Before we only fired on DATA. If we are the creator of the
DataChannel the remote isn't going to send us a message.
Changing this allows the DataChannel to be created in the callback when
SCTP has opened.
  • Loading branch information
Sean-Der committed Jan 3, 2025
1 parent 6261915 commit a3db026
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ void sctp_incoming_data(Sctp* sctp, char* buf, size_t len) {
data_chunk->length = htons(1 + sizeof(SctpDataChunk));
data_chunk->data[0] = DATA_CHANNEL_ACK;
length += ntohs(data_chunk->length);

if (!sctp->connected) {
sctp->connected = 1;
if (sctp->onopen) {
sctp->onopen(sctp->userdata);
}
}

} else if (ntohl(data_chunk->ppid) == DATA_CHANNEL_PPID_DOMSTRING) {
if (sctp->onmessage) {
sctp->onmessage((char*)data_chunk->data, ntohs(data_chunk->length) - sizeof(SctpDataChunk),
Expand Down Expand Up @@ -310,6 +302,13 @@ void sctp_incoming_data(Sctp* sctp, char* buf, size_t len) {
param->length = htons(8);
*(uint32_t*)&param->value = htonl(0x02);
length = ntohs(init_ack->common.length) + sizeof(SctpHeader);

if (!sctp->connected) {
sctp->connected = 1;
if (sctp->onopen) {
sctp->onopen(sctp->userdata);
}
}
} break;
case SCTP_INIT_ACK: {
SctpInitChunk* init_ack = (SctpInitChunk*)in_packet->chunks;
Expand All @@ -336,6 +335,13 @@ void sctp_incoming_data(Sctp* sctp, char* buf, size_t len) {
// param: type + length (4 bytes) + cookie
memcpy(cookie_echo->cookie, param->value, ntohs(param->length) - 4);
length = ntohs(cookie_echo->common.length) + sizeof(SctpHeader);

if (!sctp->connected) {
sctp->connected = 1;
if (sctp->onopen) {
sctp->onopen(sctp->userdata);
}
}
} break;
case SCTP_SACK:
#if 0
Expand Down

0 comments on commit a3db026

Please sign in to comment.