Skip to content
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

Fix Windows and MacOS CI with SCTP/usrsctp #23

Draft
wants to merge 90 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
3d746b2
feat: sctp connection using usrsctp
lchenut Mar 8, 2024
654a69a
feat: added sctp ping&pong examples
lchenut Mar 8, 2024
4b9c506
Unregister address while closing
lchenut Mar 21, 2024
9b51d57
change ci building examples
lchenut Apr 15, 2024
c8a9fd3
Merge remote-tracking branch 'origin/master' into sctp-protocol
lchenut Jul 24, 2024
9b5c58d
chore: split files
lchenut Jul 26, 2024
3aa14e9
chore: expose what should be exposed & removed artifact object fields
lchenut Jul 26, 2024
d09aa30
fix: examples
lchenut Jul 26, 2024
ccf671c
chore: shuffle part of the code to its correct file
lchenut Jul 26, 2024
3f11895
chore: rename handleUpcall into recvCallback
lchenut Jul 26, 2024
a53f87f
chore: remove import & change variable name
lchenut Jul 26, 2024
d6f73ce
feat: check if socket is nil after accepting
lchenut Jul 26, 2024
8910d1e
chore: renaming address into raddr
lchenut Jul 26, 2024
73e4731
chore: rewrite connect / accept to manage error while calling usrsctp…
lchenut Jul 26, 2024
bd5841c
chore: update comment
lchenut Jul 26, 2024
a9df70a
Merge remote-tracking branch 'origin/master' into sctp-protocol
lchenut Aug 13, 2024
b77410b
fix: ci
lchenut Aug 20, 2024
ac65c6f
chore: remove useless field
lchenut Aug 20, 2024
df5eddd
feat: add testsctp & make it work
lchenut Aug 22, 2024
62cc2c7
chore: remove timer handler
lchenut Aug 23, 2024
2d2f012
Merge remote-tracking branch 'origin/master' into sctp-protocol
lchenut Aug 23, 2024
201a163
feat: add async exception tracking
lchenut Aug 23, 2024
4a59265
style: pass nph on sctp files
lchenut Aug 23, 2024
96a363e
feat: add sctp tracker counter
lchenut Aug 23, 2024
197c0c3
fix: readloop is back
lchenut Aug 23, 2024
722db0f
fix: windows ci
lchenut Aug 26, 2024
54612e9
chore: remove raddr from SctpConn
lchenut Aug 26, 2024
ecc4fbb
fix: defined EINPROGRESS when using windows
lchenut Aug 26, 2024
d6b00e5
fix: windows & macos ci
lchenut Aug 26, 2024
6e96abe
feat: add testsctp.nim to runalltest.nim
lchenut Aug 26, 2024
785d2bb
chore: turn on sctp debug
lchenut Aug 26, 2024
c8ebe7e
fix: windows EINPROGRESS error
lchenut Aug 26, 2024
2b1228f
fix: debug all
lchenut Aug 26, 2024
108841d
fix: remove useless code
lchenut Aug 26, 2024
5fcc26d
fix: change EINPROGRESS again
lchenut Aug 27, 2024
57cd0f0
fix: change EINPROGRESS again
lchenut Aug 27, 2024
e914f69
fix: change EINPROGRESS again
lchenut Aug 27, 2024
183d8d5
feat: add a test
lchenut Aug 27, 2024
f317070
chore: move socket/error constant to sctp_utils.nim
lchenut Aug 27, 2024
2a80d57
fix: change EINPROGRESS again
lchenut Aug 27, 2024
3305615
fix: multiple initialization causing issues
lchenut Aug 28, 2024
41a091f
Merge remote-tracking branch 'origin/master' into sctp-protocol
lchenut Aug 30, 2024
b97ffaf
fix: closing sctp connection should close underlying dtls connection
lchenut Aug 30, 2024
f0ff34c
fix: remove printf for windows temporarily
lchenut Aug 30, 2024
a59bb76
fix: add iphlpapi for windows
lchenut Sep 5, 2024
4a80ffd
chore: change add errno to log
lchenut Sep 5, 2024
5f50e55
feat: replace sentFuture by sendQueue
lchenut Sep 6, 2024
374c83d
feat: better use of SctpState
lchenut Sep 6, 2024
0d7f15e
fix: read now raises WebRtcError
lchenut Sep 6, 2024
ab707d4
fix: conninput and connect are now awaited
lchenut Sep 6, 2024
13e4560
fix: readLoop is now stop when SctpConn is closed
lchenut Sep 6, 2024
1d66aac
chore: remove useless code and rewrite trace/warn
lchenut Sep 10, 2024
f231a9d
fix: remove doAssert
lchenut Sep 10, 2024
3647e11
fix: renaming close into stop and change logs
lchenut Sep 10, 2024
baf91b9
chore: move `toFlags` to a more relevant place
lchenut Sep 10, 2024
413f323
feat: close every connection when stopping transport
lchenut Sep 10, 2024
857e5da
chore: remove exposed attributes
lchenut Sep 12, 2024
21e0cfe
chore: add description and remove trace
lchenut Sep 12, 2024
185642b
chore: remove comments & exposition
lchenut Sep 12, 2024
9c6b197
chore: update logs
lchenut Sep 12, 2024
38d40f8
chore: remove outdated comments
lchenut Sep 12, 2024
8d26ed6
chore: update comment
lchenut Sep 12, 2024
3280cae
remove linux from ci
lchenut Sep 17, 2024
bfe84db
add logs
lchenut Sep 17, 2024
ed8d888
update logScope & remote tests
lchenut Sep 17, 2024
bd2b6fa
fix nim flag
lchenut Sep 17, 2024
47b17ed
check usrsctp
lchenut Sep 19, 2024
26c6573
fix
lchenut Sep 19, 2024
1b8fdff
install automake
lchenut Sep 19, 2024
92d3f42
remove windows and checkout usrsctp
lchenut Sep 19, 2024
dc2e322
add logs
lchenut Sep 19, 2024
464f7b5
try modify user_socket.c
lchenut Sep 19, 2024
03eb0ce
change nimble install order
lchenut Sep 19, 2024
7e1472b
change sed command
lchenut Sep 19, 2024
9ede712
sed work weirdly on macos
lchenut Sep 19, 2024
c4f3289
why apple... why
lchenut Sep 19, 2024
8c13dc2
change sed by awk
lchenut Sep 19, 2024
64a5146
newline fix
lchenut Sep 19, 2024
ce63acb
add logs on usrsctp_socket
lchenut Sep 20, 2024
d5e90d4
fix
lchenut Sep 20, 2024
462f6c0
fix macos Sockaddr_conn
lchenut Sep 20, 2024
a83644b
add log to check sconn_len is properly set
lchenut Sep 20, 2024
34ede96
make awk command more modular
lchenut Sep 20, 2024
906a6f4
fix awk one last time
lchenut Sep 20, 2024
0dc4d41
switch to debug windows
lchenut Sep 20, 2024
f09deb3
come on windows, do the thing
lchenut Sep 20, 2024
cb3d264
fix ci.yml
lchenut Sep 20, 2024
f7ae89a
install vs
lchenut Sep 20, 2024
fdfda47
install vs
lchenut Sep 20, 2024
0ede149
remove vs_buildtools.exe
lchenut Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ jobs:
fail-fast: false
matrix:
target:
- os: linux
cpu: amd64
- os: linux
cpu: i386
- os: macos
cpu: amd64
#- os: linux
# cpu: amd64
#- os: linux
# cpu: i386
#- os: macos
# cpu: amd64
- os: windows
cpu: amd64
nim: [1.6.16, devel]
include:
- target:
os: linux
builder: ubuntu-22.04
shell: bash
- target:
os: macos
builder: macos-13
shell: bash
#- target:
# os: linux
# builder: ubuntu-22.04
# shell: bash
#- target:
# os: macos
# builder: macos-13
# shell: bash
- target:
os: windows
builder: windows-2022
Expand All @@ -57,6 +57,16 @@ jobs:
base-devel
git
mingw-w64-x86_64-toolchain
- name: Install Chocolatey in MSYS2 Shell
run: |
powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"

- name: Install Visual Studio Build Tools (for nmake)
run: |
choco install visualstudio2019buildtools --includeOptional --includeRecommended -y
shell: msys2 {0}

- uses: iffy/install-nim@v3
with:
Expand All @@ -65,6 +75,11 @@ jobs:
- name: Install deps
run: |
nimble install -dy
git clone https://github.com/sctplab/usrsctp.git
cd usrsctp
git checkout 01cc4e042e2235b29d9d489d89728a6f9ac063ed
nmake VERBOSE=1 -f Makefile.nmake
cd ..

- name: Run tests
run: |
Expand Down
21 changes: 21 additions & 0 deletions examples/ping.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import chronos, stew/byteutils
import ../webrtc/udp_transport
import ../webrtc/stun/stun_transport
import ../webrtc/dtls/dtls_transport
import ../webrtc/sctp/[sctp_transport, sctp_connection]

proc main() {.async.} =
let laddr = initTAddress("127.0.0.1:4244")
let udp = UdpTransport.new(laddr)
let stun = Stun.new(udp)
let dtls = Dtls.new(stun)
let sctp = Sctp.new(dtls)

let conn = await sctp.connect(initTAddress("127.0.0.1:4242"), sctpPort = 13)
while true:
await conn.write("ping".toBytes)
let msg = await conn.read()
echo "Received: ", string.fromBytes(msg.data)
await sleepAsync(1.seconds)

waitFor(main())
27 changes: 27 additions & 0 deletions examples/pong.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chronos, stew/byteutils
import ../webrtc/udp_transport
import ../webrtc/stun/stun_transport
import ../webrtc/dtls/dtls_transport
import ../webrtc/sctp/[sctp_transport, sctp_connection]

proc sendPong(conn: SctpConn) {.async.} =
var i = 0
while true:
let msg = await conn.read()
echo "Received: ", string.fromBytes(msg.data)
await conn.write(("pong " & $i).toBytes)
i.inc()

proc main() {.async.} =
let laddr = initTAddress("127.0.0.1:4242")
let udp = UdpTransport.new(laddr)
let stun = Stun.new(udp)
let dtls = Dtls.new(stun)
let sctp = Sctp.new(dtls)

sctp.listen(13)
while true:
let conn = await sctp.accept()
asyncSpawn conn.sendPong()

waitFor(main())
7 changes: 5 additions & 2 deletions tests/runalltests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@

{.used.}

import teststun
import testdtls
{.passc: "-DSCTP_DEBUG".}

#import teststun
#import testdtls
import testsctp
105 changes: 105 additions & 0 deletions tests/testsctp.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Nim-WebRTC
# Copyright (c) 2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.

{.used.}

import chronos
import ../webrtc/udp_transport
import ../webrtc/stun/stun_transport
import ../webrtc/dtls/dtls_transport
import ../webrtc/sctp/sctp_transport
import ../webrtc/sctp/sctp_connection
import ./asyncunit

suite "SCTP":
teardown:
checkLeaks()

type
SctpStackForTest = object
localAddress: TransportAddress
udp: UdpTransport
stun: Stun
dtls: Dtls
sctp: Sctp

proc initSctpStack(localAddress: TransportAddress): SctpStackForTest =
result.localAddress = localAddress
result.udp = UdpTransport.new(result.localAddress)
result.stun = Stun.new(result.udp)
result.dtls = Dtls.new(result.stun)
result.sctp = Sctp.new(result.dtls)
result.sctp.listen()

proc closeSctpStack(self: SctpStackForTest) {.async: (raises: [CancelledError]).} =
await self.sctp.stop()
await self.dtls.stop()
await self.stun.stop()
await self.udp.close()

asyncTest "Two SCTP nodes connecting to each other, then sending/receiving data":
var
sctpServer = initSctpStack(initTAddress("127.0.0.1:4444"))
sctpClient = initSctpStack(initTAddress("127.0.0.1:5555"))
echo "Before Accept"
let serverConnFut = sctpServer.sctp.accept()
echo "Before Connect"
let clientConn = await sctpClient.sctp.connect(sctpServer.localAddress)
echo "Before await accept"
let serverConn = await serverConnFut
echo "Connected :tada:"

await clientConn.write(@[1'u8, 2, 3, 4])
check (await serverConn.read()).data == @[1'u8, 2, 3, 4]

await serverConn.write(@[5'u8, 6, 7, 8])
check (await clientConn.read()).data == @[5'u8, 6, 7, 8]

await clientConn.write(@[10'u8, 11, 12, 13])
await serverConn.write(@[14'u8, 15, 16, 17])
check (await clientConn.read()).data == @[14'u8, 15, 16, 17]
check (await serverConn.read()).data == @[10'u8, 11, 12, 13]

await allFutures(clientConn.close(), serverConn.close())
await allFutures(sctpClient.closeSctpStack(), sctpServer.closeSctpStack())

# asyncTest "Two DTLS nodes connecting to the same DTLS server, sending/receiving data":
# var
# sctpServer = initSctpStack(initTAddress("127.0.0.1:4444"))
# sctpClient1 = initSctpStack(initTAddress("127.0.0.1:5555"))
# sctpClient2 = initSctpStack(initTAddress("127.0.0.1:6666"))
# let
# serverConn1Fut = sctpServer.sctp.accept()
# serverConn2Fut = sctpServer.sctp.accept()
# clientConn1 = await sctpClient1.sctp.connect(sctpServer.localAddress)
# clientConn2 = await sctpClient2.sctp.connect(sctpServer.localAddress)
# serverConn1 = await serverConn1Fut
# serverConn2 = await serverConn2Fut
#
# await serverConn1.write(@[1'u8, 2, 3, 4])
# await serverConn2.write(@[5'u8, 6, 7, 8])
# await clientConn1.write(@[9'u8, 10, 11, 12])
# await clientConn2.write(@[13'u8, 14, 15, 16])
# check:
# (await clientConn1.read()).data == @[1'u8, 2, 3, 4]
# (await clientConn2.read()).data == @[5'u8, 6, 7, 8]
# (await serverConn1.read()).data == @[9'u8, 10, 11, 12]
# (await serverConn2.read()).data == @[13'u8, 14, 15, 16]
# await allFutures(clientConn1.close(), serverConn1.close())
#
# await serverConn2.write(@[5'u8, 6, 7, 8])
# await clientConn2.write(@[13'u8, 14, 15, 16])
# check:
# (await clientConn2.read()).data == @[5'u8, 6, 7, 8]
# (await serverConn2.read()).data == @[13'u8, 14, 15, 16]
# await allFutures(clientConn2.close(), serverConn2.close())
#
# await allFutures(sctpClient1.closeSctpStack(),
# sctpClient2.closeSctpStack(),
# sctpServer.closeSctpStack())
20 changes: 17 additions & 3 deletions webrtc.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ var cfg =
" --styleCheck:usages --styleCheck:error" &
(if verbose: "" else: " --verbosity:0 --hints:off") &
" --skipParentCfg --skipUserCfg -f" &
" --threads:on --opt:speed"
" --threads:on --opt:speed" &
" --d:chronicles_enabled_topics=sctp:TRACE,dtls:TRACE"

when defined(windows):
cfg = cfg & " --clib:ws2_32"
cfg = cfg & " --clib:ws2_32 --clib:iphlpapi"

import hashes

proc buildExample(filename: string, run = false, extraFlags = "") =
var excstr = nimc & " " & lang & " " & flags & " -p:. " & extraFlags
excstr.add(" examples/" & filename)
exec excstr
if run:
exec "./examples/" & filename.toExe
rmFile "examples/" & filename.toExe

proc runTest(filename: string) =
var excstr = nimc & " " & lang & " -d:debug " & cfg & " " & flags
excstr.add(" -d:nimOldCaseObjects") # TODO: fix this in binary-serialization
Expand All @@ -36,5 +45,10 @@ proc runTest(filename: string) =
exec excstr & " -r " & " tests/" & filename
rmFile "tests/" & filename.toExe

task test, "Run test":
task test, "Run the test suite":
runTest("runalltests")
exec "nimble build_example"

task build_example, "Build the examples":
buildExample("ping")
buildExample("pong")
2 changes: 1 addition & 1 deletion webrtc/dtls/dtls_connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import
import ../errors, ../stun/[stun_connection], ./dtls_utils

logScope:
topics = "webrtc dtls_conn"
topics = "webrtc dtls dtls_conn"

const DtlsConnTracker* = "webrtc.dtls.conn"

Expand Down
2 changes: 1 addition & 1 deletion webrtc/dtls/dtls_transport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import
./[dtls_utils, dtls_connection], ../errors, ../stun/[stun_connection, stun_transport]

logScope:
topics = "webrtc dtls"
topics = "webrtc dtls dtls_transport"

# Implementation of a DTLS client and a DTLS Server by using the Mbed-TLS library.
# Multiple things here are unintuitive partly because of the callbacks
Expand Down
Loading
Loading