[Cocoa] Migrate WebRTC UDP socket handling to NW API
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jun 2021 08:46:38 +0000 (08:46 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jun 2021 08:46:38 +0000 (08:46 +0000)
commit94f31e8bfa57b5f69a8be638ba7560008a9b7757
treef2d06c3a791ec7b320f59b7dda4b5fca1523eafb
parent520fddc561aca5bcfd4790938b323e82cf15d2f1
[Cocoa] Migrate WebRTC UDP socket handling to NW API
https://bugs.webkit.org/show_bug.cgi?id=227210
LayoutTests/imported/w3c:

Reviewed by Eric Carlson.

Rebasing tests as timing changes a bit.
This aligns with Chrome and Firefox behavior.

* web-platform-tests/webrtc/no-media-call-expected.txt:
* web-platform-tests/webrtc/promises-call-expected.txt:

Source/ThirdParty/libwebrtc:

Reviewed by Eric Carlson.

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:

Source/WebCore:

Reviewed by Eric Carlson.

Add infrastructure to new experimental feature flag for NW backed UDP sockets.

* page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::webRTCPlatformTCPSocketsEnabled const):
(WebCore::RuntimeEnabledFeatures::setWebRTCPlatformTCPSocketsEnabled):
(WebCore::RuntimeEnabledFeatures::webRTCPlatformUDPSocketsEnabled const):
(WebCore::RuntimeEnabledFeatures::setWebRTCPlatformUDPSocketsEnabled):

Source/WebKit:

Reviewed by Eric Carlson.

Migrate UDP socket handling from WebRTC physical socket server to nw API for Cocoa ports.

For each UDP socket opened, we open a nw_listener that will listen to inbound connections.
On inbound connection, we receive a nw_connection that we store in a address -> connection map.

Whenever sending a packet, we look at the remote address.
If needed, we create a nw_connection to that particular remote address and store it in the address -> connection map.
We then use the pre-existing or newly created nw_connection to send the packet.

Make sure to cancel NW connection in case of failure before releasing the socket.

Covered by existing tests

* NetworkProcess/webrtc/NetworkRTCProvider.cpp:
(WebKit::NetworkRTCProvider::createUDPSocket):
(WebKit::NetworkRTCProvider::createClientTCPSocket):
* NetworkProcess/webrtc/NetworkRTCProvider.h:
(WebKit::NetworkRTCProvider::setPlatformTCPSocketsEnabled):
(WebKit::NetworkRTCProvider::setPlatformUDPSocketsEnabled):
* NetworkProcess/webrtc/NetworkRTCProvider.messages.in:
* NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.h: Copied from Source/WebKit/NetworkProcess/webrtc/NetworkRTCSocketCocoa.h.
* NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm: Renamed from Source/WebKit/NetworkProcess/webrtc/NetworkRTCSocketCocoa.mm.
(WebKit::tcpSocketQueue):
(WebKit::NetworkRTCTCPSocketCocoa::createClientTCPSocket):
(WebKit::NetworkRTCTCPSocketCocoa::NetworkRTCTCPSocketCocoa):
(WebKit::NetworkRTCTCPSocketCocoa::close):
(WebKit::NetworkRTCTCPSocketCocoa::setOption):
(WebKit::NetworkRTCTCPSocketCocoa::createMessageBuffer):
(WebKit::NetworkRTCTCPSocketCocoa::sendTo):
* NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.h: Added.
(WTF::DefaultHash<rtc::SocketAddress>::hash):
(WTF::DefaultHash<rtc::SocketAddress>::equal):
(WTF::HashTraits<rtc::SocketAddress>::emptyValue):
(WTF::HashTraits<rtc::SocketAddress>::constructDeletedValue):
(WTF::HashTraits<rtc::SocketAddress>::isDeletedValue):
* NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm: Added.
(WebKit::NetworkRTCUDPSocketCocoaConnections::create):
(WebKit::NetworkRTCUDPSocketCocoaConnections::WTF_GUARDED_BY_LOCK):
(WebKit::udpSocketQueue):
(WebKit::NetworkRTCUDPSocketCocoa::createUDPSocket):
(WebKit::NetworkRTCUDPSocketCocoa::NetworkRTCUDPSocketCocoa):
(WebKit::NetworkRTCUDPSocketCocoa::~NetworkRTCUDPSocketCocoa):
(WebKit::NetworkRTCUDPSocketCocoa::close):
(WebKit::NetworkRTCUDPSocketCocoa::setOption):
(WebKit::NetworkRTCUDPSocketCocoa::sendTo):
(WebKit::NetworkRTCUDPSocketCocoaConnections::NetworkRTCUDPSocketCocoaConnections):
(WebKit::NetworkRTCUDPSocketCocoaConnections::close):
(WebKit::NetworkRTCUDPSocketCocoaConnections::setOption):
(WebKit::processUDPData):
(WebKit::NetworkRTCUDPSocketCocoaConnections::createNWConnection):
(WebKit::NetworkRTCUDPSocketCocoaConnections::setupNWConnection):
(WebKit::NetworkRTCUDPSocketCocoaConnections::sendTo):
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp:
(WebKit::LibWebRTCSocketFactory::setConnection):

Source/WTF:

Reviewed by Eric Carlson.

Add a new experimental flag for NW backed UDP sockets.

* Scripts/Preferences/WebPreferencesExperimental.yaml:

LayoutTests:

<rdar://problem/79859045>

Reviewed by Eric Carlson.

* platform/ios-simulator-wk2/TestExpectations:
Mark test as failed, as this test is using unsupported API (transport).

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@279405 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/no-media-call-expected.txt
LayoutTests/imported/w3c/web-platform-tests/webrtc/promises-call-expected.txt
LayoutTests/platform/ios-simulator-wk2/TestExpectations
Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp
Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp
Source/WTF/ChangeLog
Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml
Source/WebCore/ChangeLog
Source/WebCore/page/RuntimeEnabledFeatures.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp
Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.h
Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.messages.in
Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.h [moved from Source/WebKit/NetworkProcess/webrtc/NetworkRTCSocketCocoa.h with 89% similarity]
Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm [moved from Source/WebKit/NetworkProcess/webrtc/NetworkRTCSocketCocoa.mm with 83% similarity]
Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm [new file with mode: 0644]
Source/WebKit/SourcesCocoa.txt
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp