Skip to content

Commit

Permalink
fix packets receiving in native webrtc driver and update pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
nathhB committed Jan 3, 2024
1 parent 4bc7b16 commit bcf3199
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nbnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ jobs:
cd build
cmake -DLIBDATACHANNEL_LIBRARY_PATH=${{ github.workspace }}/libdatachannel/build/libdatachannel.so -DLIBDATACHANNEL_INCLUDE_PATH=${{ github.workspace }}/libdatachannel/include -DWEBRTC_C_DRIVER=ON ..
make
cd ..
npm install
- name: Compile soak test (web)
run: |
cd emsdk
Expand All @@ -226,6 +224,8 @@ jobs:
cd build_web
emcmake cmake ..
make
cd ..
npm install
- name: Run soak test
run: WEBRTC_NATIVE=1 timeout 240 ./bin/github-actions/run_soak.sh

Expand Down
83 changes: 54 additions & 29 deletions bin/github-actions/run_soak.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ CHANNEL_COUNT=3
MESSAGE_COUNT=500
NODE_CMD="$EMSDK_NODE --experimental-wasm-threads"

run_client () {
node_client=$1
echo "Running soak client (run in node: $node_client)..."

if [ $node_client -eq 1 ]
then
$NODE_CMD build_web/client.js --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out
else
./build/client --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out
fi

RESULT=$?

# when running the soak test in the latest version of emscripten with node 16
# the client aborts at the end when calling emscripten_force_exit
# I could not figure out why, hence the condition
[[ $node_client -eq 1 ]] && EXPECTED_RESULT=7 || EXPECTED_RESULT=0

if [ $RESULT -eq $EXPECTED_RESULT ]
then
echo "Soak test completed with success!"
echo "Printing the end of client logs..."

tail -n 150 soak_cli_out

return 0
else
echo "Soak test failed! (code: $RESULT)"
echo "Printing the end of client logs..."
tail -n 150 soak_cli_out
echo "Printing the end of server logs..."
tail -n 150 soak_serv_out

return 1
fi
}

exit_soak () {
kill -SIGINT $SERV_PID 2> /dev/null

exit $1
}

cd soak
echo "Starting soak server..."

Expand All @@ -33,36 +76,18 @@ sleep 3

if [ -n "$WEBRTC" ]
then
$NODE_CMD build/client.js --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out
else
./build/client --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out
fi

RESULT=$?

# when running the soak test in the latest version of emscripten with node 16
# the client aborts at the end when calling emscripten_force_exit
# I could not figure out why, hence the condition
[[ -n "$WEBRTC" ]] && EXPECTED_RESULT=7 || EXPECTED_RESULT=0

if [ $RESULT -eq $EXPECTED_RESULT ]
then
echo "Soak test completed with success!"
echo "Printing the end of client logs..."

tail -n 150 soak_cli_out
run_client 1

EXIT_CODE=0
exit_soak $?
else
echo "Soak test failed! (code: $RESULT)"
echo "Printing the end of client logs..."
tail -n 150 soak_cli_out
echo "Printing the end of server logs..."
tail -n 150 soak_serv_out
if [ -n "$WEBRTC_NATIVE" ]
then
# run both UDP and webrtc clients on the same server

EXIT_CODE=1
if run_client 0 && run_client 1; then
exit_soak 0
else
exit_soak 1
fi
fi
fi

kill -SIGINT $SERV_PID 2> /dev/null

exit $EXIT_CODE
8 changes: 4 additions & 4 deletions net_drivers/webrtc_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,16 @@ static void NBN_WebRTC_C_ServStop(void)

static int NBN_WebRTC_C_ServRecvPackets(void)
{
int size;
const int buffer_size = sizeof(nbn_wrtc_c_serv.packet_buffer);
int size = buffer_size;

for (unsigned int i = 0; i < nbn_wrtc_c_serv.peers->capacity; i++)
{
NBN_WebRTC_C_HTableEntry *entry = nbn_wrtc_c_serv.peers->internal_array[i];

if (entry)
{
size = NBN_PACKET_MAX_SIZE;

while (rtcReceiveMessage(entry->peer->channel_id, nbn_wrtc_c_serv.packet_buffer, &size) != RTC_ERR_NOT_AVAIL)
while (rtcReceiveMessage(entry->peer->channel_id, nbn_wrtc_c_serv.packet_buffer, &size) == RTC_ERR_SUCCESS)
{
NBN_Packet packet;

Expand All @@ -629,6 +628,7 @@ static int NBN_WebRTC_C_ServRecvPackets(void)

packet.sender = entry->peer->conn;
NBN_Driver_RaiseEvent(NBN_DRIVER_SERV_CLIENT_PACKET_RECEIVED, &packet);
size = buffer_size;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion soak/soak_cli_out

This file was deleted.

1 change: 0 additions & 1 deletion soak/soak_serv_out

This file was deleted.

0 comments on commit bcf3199

Please sign in to comment.