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

ice: add candidate sdp mdns support #917

Merged
merged 12 commits into from
Aug 29, 2023
Merged

ice: add candidate sdp mdns support #917

merged 12 commits into from
Aug 29, 2023

Conversation

sreimers
Copy link
Member

@sreimers sreimers commented Aug 27, 2023

Some browsers anonymize local webrtc sdp candidate ip addresses with mDNS [UUID].local (like "1bbabc05-80d2-4386-8e39-9666b53900d0.local"), this PR uses getaddrinfo to resolve these if needed.

TODO:

  • a callback notification is needed (rcand is ready)
  • Tested with Safari iOS (16.6), Firefox (116.0.3) and Chromium (116.0.5845.110)

refs baresip/baresip#2137

https://datatracker.ietf.org/doc/html/draft-ietf-mmusic-mdns-ice-candidates-03

Manual Testing:

  • Start baresip-webrtc -v
  • Open URL in Browser (private browser mode) Check recvonly (no microphone/camera permission) and connect
  • You should see mDNS remote candidates:
{      audio. } mDNS remote cand: 4e712009-4a6c-40df-87a5-55bda80e6257.local
{      audio. } conncheck_start: waiting mDNS for remote candidate...
{      video. } mDNS remote cand: 4e712009-4a6c-40df-87a5-55bda80e6257.local
{      video. } conncheck_start: waiting mDNS for remote candidate...

@paresy
Copy link
Contributor

paresy commented Aug 27, 2023

Wow, thanks for the PR! I was eager and patched it on-top of version 3.4.0. It seems to work very good, with the WebRTC demo without any ICE servers set. When i define ICE-Servers on WebRTC-Demo (Backend) and in the JS part of the demo and if i use Firefox (which sends all candidates; Chrome/Safari seem to skip sending external candidates on a loopback connection) then the demo crashes.

See the attached log:

Local network addresses:
        en0:  192.168.1.89
        en0:  fd4b:a493:d8a7:4a5e:1823:55e6:2bdc:2ae7
medianat: ice
dtls_srtp: use prime256v1 for elliptic curve cryptography
mediaenc: dtls_srtp
DTLS-SRTP ready with profiles SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32:SRTP_AEAD_AES_128_GCM:SRTP_AEAD_AES_256_GCM
vidcodec: H264
vidcodec: H264
avcodec: using H.264 encoder 'libopenh264' -- OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
avcodec: using H.264 decoder 'h264' -- H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
ausrc: avformat
vidsrc: avformat
demo: using ICE server: turn:a.relay.metered.ca:80
demo: listening on:
    http://127.0.0.1:9000/
demo: request: met=GET, path=/, prm=
demo: loaded file '/Users/paresy/baresip/webrtc/src/../www/index.html', 1058 bytes (text/html)
demo: request: met=GET, path=/js/main.js, prm=
demo: loaded file '/Users/paresy/baresip/webrtc/src/../www/js/main.js', 5516 bytes (text/javascript)
demo: request: met=POST, path=/connect, prm=
demo: create session
peerconnection: new: sdp=Offerer
peerconnection: using mnat 'ice'
ice: new session with TURN-server at a.relay.metered.ca (username=4c3e49b5d658489d3b14ec0e)
peerconnection: using menc 'dtls_srtp'
peerconnection: add video (codecs=2)
ice: policy = all
stream: video: starting mediaenc 'dtls_srtp' (wait_secure=1)
ice: resolved TURN-server to address 216.39.253.22:80
video: added interface: en0:192.168.1.89 (local pref 65534)
video: added interface: en0:fd4b:a493:d8a7:4a5e:1823:55e6:2bdc:2ae7 (local pref 65535)
ice: relay gathered for comp 1 (0 OK)
ice: all components gathered.
video: comp1 setting local: 216.39.253.22:45636
ice: video: Default local candidates: 216.39.253.22:45636 / ?
peerconnection: medianat gathered (stable)
demo: session gathered -- send sdp 'offer'
peerconnection: create offer
- - offer - -
- - - - - - -
descr: encode: type='offer'
demo: request: met=PUT, path=/sdp, prm=
demo: handle PUT sdp: content is 'application/json'
descr: decode: type='answer'
peerconnection: set remote description. type=answer
- - answer - -
- - - - - - -
stream: update 'video'
stream: receive: setting SSRC: 7e688c3c
video: RTP/RTCP multiplexing enabled
peerconnection: start ice
demo: request: met=PATCH, path=/candidate, prm=
demo: request: met=PATCH, path=/candidate, prm=
demo: request: met=PATCH, path=/candidate, prm=
demo: request: met=PATCH, path=/candidate, prm=
{      video.1} added PeerReflexive remote candidate with priority 1853751551 (192.168.1.89:63253)
ice: form: 'video' no remote candidates
ice: form: 'video' no remote candidates
ice: form: 'video' no remote candidates
ice: form: 'video' no remote candidates
stunsrv: {video.1} local candidate not found (checklist=0) (src=192.168.1.89:63253)
demo: request: met=PATCH, path=/candidate, prm=
{      video. } starting connectivity checks with 4 candidate pairs
{      video.1}  host <---> prflx  FSM:      Frozen ===> InProgress
{      video.1} Tx en0:host:192.168.1.89:25328 ---> prflx:192.168.1.89:63253 (InProgress)  
{      video.1} Rx en0:host:192.168.1.89:25328 <--- prflx:192.168.1.89:63253 '0 OK'
{      video.1}  host <---> prflx  FSM:  InProgress ===> Succeeded 
{      video.1}  host <---> srflx  FSM:      Frozen ===> InProgress
{      video.1} Tx en0:host:192.168.1.89:25328 ---> srflx:31.16.224.154:63253 (InProgress)  
demo: request: met=PATCH, path=/candidate, prm=
{      video. } starting connectivity checks with 4 candidate pairs
{      video.1} srflx <---> prflx  FSM:      Frozen ===> InProgress
{      video.1} Tx en0:srflx:31.16.224.154:25328 ---> prflx:192.168.1.89:63253 (InProgress)  
{      video.1} Rx en0:srflx:31.16.224.154:25328 <--- prflx:192.168.1.89:63253 '0 OK'
{      video.1} New local candidate for mapped 192.168.1.89:25328
{      video.1} srflx <---> prflx  FSM:  InProgress ===> Succeeded 
{      video.1} relay <---> prflx  FSM:      Frozen ===> InProgress
{      video.1} Tx relay:216.39.253.22:45636 ---> prflx:192.168.1.89:63253 (InProgress)  
{      video. } starting connectivity checks with 3 candidate pairs
{      video.1} relay <---> srflx  FSM:      Frozen ===> InProgress
{      video.1} Tx relay:216.39.253.22:45636 ---> srflx:31.16.224.154:63253 (InProgress)  
{1} TURN Client error: 403 Forbidden IP
ice: gathering srflx for comp 1 ..
{      video. } starting connectivity checks with 3 candidate pairs
{      video. } starting connectivity checks with 3 candidate pairs
{      video.1} Rx relay:216.39.253.22:45636 <--- prflx:192.168.1.89:63253 '0 OK'
{      video.1} New local candidate for mapped 192.168.1.89:25328
{      video.1} relay <---> prflx  FSM:  InProgress ===> Succeeded 
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
{      video. } starting connectivity checks with 2 candidate pairs
mem: mem_deref: magic check failed 0x00000200 (0x1386049a8)

Process finished with exit code 138 (interrupted by signal 10: SIGBUS)  

I tracked down the issue to this line:
mem_deref(rcand->domain); in rcand_dealloc

Maybe a race condition?

@sreimers
Copy link
Member Author

sreimers commented Aug 27, 2023

Thanks for testing, yes the mem_deref(rcand->domain); is useless/fatal since pl_strcpy does not allocate, should be fixed now.

@sreimers sreimers marked this pull request as ready for review August 28, 2023 12:06
@sreimers sreimers merged commit 6b8ec69 into main Aug 29, 2023
@sreimers sreimers deleted the icesdp_getaddr branch August 29, 2023 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants