-
Notifications
You must be signed in to change notification settings - Fork 41
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
Implement datachannel close #24
base: master
Are you sure you want to change the base?
Changes from 1 commit
6f98e0e
91db2d4
1813331
5dd5d92
289b7ef
aae7eca
216331e
55b64e1
4b5830d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,42 @@ void SCTPWrapper::OnNotification(union sctp_notification *notify, size_t len) { | |
break; | ||
case SCTP_STREAM_RESET_EVENT: | ||
SPDLOG_TRACE(logger, "OnNotification(type=SCTP_STREAM_RESET_EVENT)"); | ||
struct sctp_stream_reset_event reset_event; | ||
reset_event = notify->sn_strreset_event; | ||
for (int i = 1; i < 2; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets drop the Alternatively, if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The event could hold multiple streams as it's a list. I would ideally want to loop across each of them, but I'm not sure how to do that without knowing the size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix in 289b7ef |
||
uint16_t streamid = reset_event.strreset_stream_list[i]; | ||
uint16_t set_flags; | ||
if (reset_event.strreset_flags != 0) { | ||
if ((reset_event.strreset_flags ^ SCTP_STREAM_RESET_INCOMING_SSN) == 0) { | ||
set_flags = SCTP_STREAM_RESET_INCOMING; | ||
} | ||
if ((reset_event.strreset_flags ^ SCTP_STREAM_RESET_OUTGOING_SSN) == 0) { | ||
//fires when we close the stream from our side explicity or | ||
//as a result of remote close or some error. | ||
|
||
logger->info("Outgoing stream_id#{} have been reset, calling onClose CB", streamid); | ||
const uint8_t dc_close_data = DC_TYPE_CLOSE; | ||
const uint8_t *dc_close_ptr = &dc_close_data; | ||
OnMsgReceived(dc_close_ptr, sizeof(dc_close_ptr), streamid + 1, PPID_CONTROL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 55b64e1 |
||
//The above signals to call our onClose callback | ||
} | ||
if ((reset_event.strreset_flags ^ SCTP_STREAM_RESET_DENIED) == 0) { | ||
logger->error("Stream reset denied by peer"); | ||
} | ||
if ((reset_event.strreset_flags ^ SCTP_STREAM_RESET_FAILED) == 0) { | ||
logger->error("Stream reset failed"); | ||
} | ||
} else { | ||
continue; | ||
} | ||
if (set_flags == SCTP_STREAM_RESET_INCOMING) { | ||
// Reset the stream when a remote close is received. | ||
logger->info("SCTP Reset received for stream_id#{} from remote", streamid); | ||
ResetSCTPStream(streamid + 1, set_flags); | ||
// This will cause another event SCTP_STREAM_RESET_OUTGOING_SSN | ||
// where we can finally call our callbacks. | ||
} | ||
} | ||
break; | ||
case SCTP_ASSOC_RESET_EVENT: | ||
SPDLOG_TRACE(logger, "OnNotification(type=SCTP_ASSOC_RESET_EVENT)"); | ||
|
@@ -291,6 +327,22 @@ void SCTPWrapper::Stop() { | |
usrsctp_close(sock); | ||
sock = nullptr; | ||
} | ||
usrsctp_deregister_address(this); | ||
} | ||
|
||
void SCTPWrapper::ResetSCTPStream(uint16_t stream_id, uint16_t srs_flags) { | ||
struct sctp_reset_streams stream_close; | ||
size_t no_of_streams = 1; | ||
size_t len = sizeof(sctp_assoc_t) + (2 + no_of_streams) * sizeof(uint16_t); | ||
memset(&stream_close, 0, len); | ||
stream_close.srs_flags = srs_flags; | ||
stream_close.srs_number_streams = no_of_streams; | ||
stream_close.srs_stream_list[0] = stream_id; | ||
if (usrsctp_setsockopt(this->sock, IPPROTO_SCTP, SCTP_RESET_STREAMS, &stream_close, (socklen_t)len) == -1) { | ||
logger->error("Could not set socket options for SCTP_RESET_STREAMS. errno={}", errno); | ||
} else { | ||
logger->info("SCTP_RESET_STREAMS socket option has been set successfully"); | ||
} | ||
} | ||
|
||
void SCTPWrapper::DTLSForSCTP(ChunkPtr chunk) { this->recv_queue.push(chunk); } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to hide the specifics of resetting streams inside the DataChannel - the PeerConnection here is meant to be a somewhat close mirror of the Javascript DataChannel API, which doesn't expose SCTP directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I shouldn't expose this. Will fix soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 91db2d4. Let me know if this is okay.