Skip to content

Commit

Permalink
Realign branches during transition (#1257)
Browse files Browse the repository at this point in the history
* create data channel sample (#1203)

* create data channel sample

* moved variables to Samples.h, encapsulated with ENABLE_DATA_CHANNEL directive

* removed unused variables, moved variable declarations to the top of a block

* create data channel sample

* moved variables to Samples.h, encapsulated with ENABLE_DATA_CHANNEL directive

* Cancel the thread once mediaThreadStarted flag is set to false (#1227)

* Initial stale PR template (#1226)

* Update stale issue template

* Testing every minute

* Fix stale issue PR template (#1234)

No code changed. Just a template change. So merging

* Add bug and question label

* Switch stale PR action to daily cadence

* [FIX] When protocol in DCEP header of data channel open command is not empty, there is a check preventing the data channel to be opened. Now protocol length is correctly handled to avoid check failing. (#1228)

Co-authored-by: Niyati Maheshwari <[email protected]>
Co-authored-by: Divya Sampath Kumar <[email protected]>
Co-authored-by: ela34 <[email protected]>
  • Loading branch information
4 people authored Sep 1, 2021
1 parent 00e00b2 commit 49b1cac
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/close-stale-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Close Stale Issues

# Controls when the action will be run
on:
schedule:
- cron: "0 0 * * *"

jobs:
cleanup:
runs-on: ubuntu-latest
name: Close stale issues
steps:
- uses: actions/[email protected]
with:
stale-issue-message: It looks like this issue has not been active for a long time. If the issue is not resolved, please add an update to the ticket, else it will be automatically resolved in a few days.
close-issue-message: The issue has been stale for a while and hence it has been auto-closed. If the issue persists, feel free to open a new issue with details.

# labels to be added
stale-issue-label: closing-soon
any-of-labels: question,bug

# SLAs
days-before-issue-stale: 7
days-before-issue-close: 3


repo-token: ${{ secrets.GITHUB_TOKEN }}
loglevel: DEBUG
# Set dry-run to true to not perform label or close actions.
dry-run: false


12 changes: 12 additions & 0 deletions samples/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL
} else {
DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage);
}
// Send a response to the message sent by the viewer
STATUS retStatus = STATUS_SUCCESS;
retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE));
if(retStatus != STATUS_SUCCESS) {
DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus);
}
}

VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel)
Expand Down Expand Up @@ -1019,6 +1025,12 @@ STATUS freeSampleConfiguration(PSampleConfiguration* ppSampleConfiguration)
MUTEX_LOCK(pSampleConfiguration->sampleConfigurationObjLock);
locked = TRUE;
}
// Cancel the media thread
if(!(pSampleConfiguration->mediaThreadStarted)) {
DLOGD("Canceling media thread");
THREAD_CANCEL(pSampleConfiguration->mediaSenderTid);
}

for (i = 0; i < pSampleConfiguration->streamingSessionCount; ++i) {
retStatus = gatherIceServerStats(pSampleConfiguration->sampleStreamingSessionList[i]);
if (STATUS_FAILED(retStatus)) {
Expand Down
3 changes: 3 additions & 0 deletions samples/Samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ extern "C" {
#define IOT_CORE_ROLE_ALIAS ((PCHAR) "AWS_IOT_CORE_ROLE_ALIAS")
#define IOT_CORE_THING_NAME ((PCHAR) "AWS_IOT_CORE_THING_NAME")

#define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master"
#define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer"

/* Uncomment the following line in order to enable IoT credentials checks in the provided samples */
//#define IOT_CORE_ENABLE_CREDENTIALS 1

Expand Down
49 changes: 47 additions & 2 deletions samples/kvsWebRTCClientViewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

extern PSampleConfiguration gSampleConfiguration;

// onMessage callback for a message received by the viewer on a data channel
VOID dataChannelOnMessageCallback(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen)
{
UNUSED_PARAM(customData);
UNUSED_PARAM(pDataChannel);
if (isBinary) {
DLOGI("DataChannel Binary Message");
} else {
DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage);
}
}

// onOpen callback for the onOpen event of a viewer created data channel
VOID dataChannelOnOpenCallback(UINT64 customData, PRtcDataChannel pDataChannel) {
STATUS retStatus = STATUS_SUCCESS;
DLOGI("New DataChannel has been opened %s \n", pDataChannel->name);
dataChannelOnMessage(pDataChannel, customData, dataChannelOnMessageCallback);
ATOMIC_INCREMENT((PSIZE_T) customData);
// Sending first message to the master over the data channel
retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) VIEWER_DATA_CHANNEL_MESSAGE, STRLEN(VIEWER_DATA_CHANNEL_MESSAGE));
if(retStatus != STATUS_SUCCESS){
DLOGI("[KVS Viewer] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus);
}
}

INT32 main(INT32 argc, CHAR* argv[])
{
STATUS retStatus = STATUS_SUCCESS;
Expand Down Expand Up @@ -81,13 +106,11 @@ INT32 main(INT32 argc, CHAR* argv[])
// Initialize streaming session
MUTEX_LOCK(pSampleConfiguration->sampleConfigurationObjLock);
locked = TRUE;

retStatus = createSampleStreamingSession(pSampleConfiguration, NULL, FALSE, &pSampleStreamingSession);
if (retStatus != STATUS_SUCCESS) {
printf("[KVS Viewer] createSampleStreamingSession(): operation returned status code: 0x%08x \n", retStatus);
goto CleanUp;
}

printf("[KVS Viewer] Creating streaming session...completed\n");
pSampleConfiguration->sampleStreamingSessionList[pSampleConfiguration->streamingSessionCount++] = pSampleStreamingSession;

Expand Down Expand Up @@ -165,6 +188,28 @@ INT32 main(INT32 argc, CHAR* argv[])
goto CleanUp;
}

#ifdef ENABLE_DATA_CHANNEL
PRtcDataChannel pDataChannel = NULL;
PRtcPeerConnection pPeerConnection = pSampleStreamingSession->pPeerConnection;
SIZE_T datachannelLocalOpenCount = 0;

// Creating a new datachannel on the peer connection of the existing sample streaming session
retStatus = createDataChannel(pPeerConnection, pChannelName, NULL, &pDataChannel);
if(retStatus != STATUS_SUCCESS) {
printf("[KVS Viewer] createDataChannel(): operation returned status code: 0x%08x \n", retStatus);
goto CleanUp;
}
printf("[KVS Viewer] Creating data channel...completed\n");

// Setting a callback for when the data channel is open
retStatus = dataChannelOnOpen(pDataChannel, (UINT64) &datachannelLocalOpenCount, dataChannelOnOpenCallback);
if(retStatus != STATUS_SUCCESS) {
printf("[KVS Viewer] dataChannelOnOpen(): operation returned status code: 0x%08x \n", retStatus);
goto CleanUp;
}
printf("[KVS Viewer] Data Channel open now...\n");
#endif

// Block until interrupted
while (!ATOMIC_LOAD_BOOL(&pSampleConfiguration->interrupted) && !ATOMIC_LOAD_BOOL(&pSampleStreamingSession->terminateFlag)) {
THREAD_SLEEP(HUNDREDS_OF_NANOS_IN_A_SECOND);
Expand Down
9 changes: 6 additions & 3 deletions src/source/Sctp/Sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,17 @@ STATUS handleDcepPacket(PSctpSession pSctpSession, UINT32 streamId, PBYTE data,
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
UINT16 labelLength = 0;
UINT16 protocolLength = 0;

// Assert that is DCEP of type DataChannelOpen
CHK(length > SCTP_DCEP_HEADER_LENGTH && data[0] == DCEP_DATA_CHANNEL_OPEN, STATUS_SUCCESS);

MEMCPY(&labelLength, data + 8, SIZEOF(UINT16));
putInt16((PINT16) &labelLength, labelLength);
MEMCPY(&labelLength, data + 8, SIZEOF(UINT16));
MEMCPY(&protocolLength, data + 10, SIZEOF(UINT16));
putInt16((PINT16) &labelLength, labelLength);
putInt16((PINT16) &protocolLength, protocolLength);

CHK((labelLength + SCTP_DCEP_HEADER_LENGTH) >= length, STATUS_SCTP_INVALID_DCEP_PACKET);
CHK((labelLength + protocolLength + SCTP_DCEP_HEADER_LENGTH) >= length, STATUS_SCTP_INVALID_DCEP_PACKET);

pSctpSession->sctpSessionCallbacks.dataChannelOpenFunc(pSctpSession->sctpSessionCallbacks.customData, streamId, data + SCTP_DCEP_HEADER_LENGTH,
labelLength);
Expand Down

0 comments on commit 49b1cac

Please sign in to comment.