[WebRTC] Add support for libwebrtc TCP incoming connections
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Feb 2017 01:10:39 +0000 (01:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Feb 2017 01:10:39 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168748

Patch by Youenn Fablet <youenn@apple.com> on 2017-02-27
Reviewed by Alex Christensen.

Source/WebKit2:

Covered by added layout tests.

When a libwebrtc server socket is signalling a new connnection through SignalNewConnection, we do:
- Wrap the incoming socket into a LibWebRTCSocketClient
- Store it into a pending socket map with an identifier
- Send a message to the web process of a new connection with the server socket identifier and new connection socket identifier.
The Web process then creates a WebRTCSocket wrapper around it by sendinig a WrapNewTCPConnection message.
It then propagates the SignalNewConnection to libwebrtc code path.

* NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:
(WebKit::LibWebRTCSocketClient::LibWebRTCSocketClient):
(WebKit::LibWebRTCSocketClient::signalReadPacket):
(WebKit::LibWebRTCSocketClient::signalSentPacket):
(WebKit::LibWebRTCSocketClient::signalNewConnection):
(WebKit::LibWebRTCSocketClient::signalAddressReady):
(WebKit::LibWebRTCSocketClient::signalConnect):
(WebKit::LibWebRTCSocketClient::signalClose):
* NetworkProcess/webrtc/LibWebRTCSocketClient.h:
* NetworkProcess/webrtc/NetworkRTCProvider.cpp:
(WebKit::NetworkRTCProvider::wrapNewTCPConnection):
(WebKit::NetworkRTCProvider::newConnection):
* NetworkProcess/webrtc/NetworkRTCProvider.h:
* NetworkProcess/webrtc/NetworkRTCProvider.messages.in:
* WebProcess/Network/webrtc/LibWebRTCSocket.cpp:
(WebKit::LibWebRTCSocket::signalNewConnection):
* WebProcess/Network/webrtc/LibWebRTCSocket.h:
* WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp:
(WebKit::LibWebRTCSocketFactory::createNewConnectionSocket):
* WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
* WebProcess/Network/webrtc/WebRTCSocket.cpp:
(WebKit::WebRTCSocket::signalNewConnection):
* WebProcess/Network/webrtc/WebRTCSocket.h:
* WebProcess/Network/webrtc/WebRTCSocket.messages.in:

LayoutTests:

* webrtc/datachannel/basic-expected.txt: Added.
* webrtc/datachannel/basic.html:
* webrtc/routines.js:
(createConnections):
(iceCallback1):
(iceCallback2):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213104 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
LayoutTests/ChangeLog
LayoutTests/webrtc/datachannel/basic-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/datachannel/basic.html
LayoutTests/webrtc/routines.js
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp
Source/WebKit2/NetworkProcess/webrtc/LibWebRTCSocketClient.h
Source/WebKit2/NetworkProcess/webrtc/NetworkRTCProvider.cpp
Source/WebKit2/NetworkProcess/webrtc/NetworkRTCProvider.h
Source/WebKit2/NetworkProcess/webrtc/NetworkRTCProvider.messages.in
Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.cpp
Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocket.h
Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp
Source/WebKit2/WebProcess/Network/webrtc/LibWebRTCSocketFactory.h
Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.cpp
Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.h
Source/WebKit2/WebProcess/Network/webrtc/WebRTCSocket.messages.in

index 82869ef..79704dc 100644 (file)
@@ -1,3 +1,17 @@
+2017-02-27  Youenn Fablet  <youenn@apple.com>
+
+        [WebRTC] Add support for libwebrtc TCP incoming connections
+        https://bugs.webkit.org/show_bug.cgi?id=168748
+
+        Reviewed by Alex Christensen.
+
+        * webrtc/datachannel/basic-expected.txt: Added.
+        * webrtc/datachannel/basic.html:
+        * webrtc/routines.js:
+        (createConnections):
+        (iceCallback1):
+        (iceCallback2):
+
 2017-02-27  Ryan Haddad  <ryanhaddad@apple.com>
 
         Mark fast/dom/timer-throttling-hidden-page.html as flaky.
diff --git a/LayoutTests/webrtc/datachannel/basic-expected.txt b/LayoutTests/webrtc/datachannel/basic-expected.txt
new file mode 100644 (file)
index 0000000..1422dd0
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS Basic data channel exchange from offerer to receiver 
+PASS Basic data channel exchange from receiver to offerer 
+PASS Basic data channel exchange from offerer to receiver using UDP only 
+PASS Basic data channel exchange from offerer to receiver using TCP only 
+
index e50cd5b..f6f81f0 100644 (file)
@@ -9,9 +9,6 @@
   <body>
     <script src ="../routines.js"></script>
     <script>
-if (window.internals)
-    internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
-
 var localChannel;
 var remoteChannel;
 
@@ -60,6 +57,9 @@ var finishTest;
 promise_test((test) => {
     counter = 0;
     return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
         finishTest = resolve;
         createConnections((localConnection) => {
             localChannel = localConnection.createDataChannel('sendDataChannel');
@@ -76,6 +76,9 @@ promise_test((test) => {
 promise_test((test) => {
     counter = 0;
     return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
         finishTest = resolve;
         createConnections((localConnection) => {
             localChannel = localConnection.createDataChannel('sendDataChannel');
@@ -88,6 +91,45 @@ promise_test((test) => {
         });
     });
 }, "Basic data channel exchange from receiver to offerer");
+
+promise_test((test) => {
+    counter = 0;
+    return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.onopen = () => { sendMessages(localChannel) };
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.onmessage = receiveMessages;
+            };
+        }, (candidate) => { return candidate.candidate.toLowerCase().indexOf("udp") == -1; });
+    });
+}, "Basic data channel exchange from offerer to receiver using UDP only");
+
+promise_test((test) => {
+    counter = 0;
+    return new Promise((resolve, reject) => {
+        if (window.internals)
+            internals.useMockRTCPeerConnectionFactory("TwoRealPeerConnections");
+
+        finishTest = resolve;
+        createConnections((localConnection) => {
+            localChannel = localConnection.createDataChannel('sendDataChannel');
+            localChannel.onopen = () => { sendMessages(localChannel) };
+        }, (remoteConnection) => {
+            remoteConnection.ondatachannel = (event) => {
+                remoteChannel = event.channel;
+                remoteChannel.onmessage = receiveMessages;
+            };
+        }, (candidate) => { return candidate.candidate.toLowerCase().indexOf("tcp") == -1; });
+    });
+}, "Basic data channel exchange from offerer to receiver using TCP only");
+
     </script>
   </body>
 </html>
index 4bc10d4..54ef33d 100644 (file)
@@ -2,13 +2,13 @@
 var localConnection;
 var remoteConnection;
 
-function createConnections(setupLocalConnection, setupRemoteConnection) {
+function createConnections(setupLocalConnection, setupRemoteConnection, filterOutICECandidate) {
     localConnection = new RTCPeerConnection();
-    localConnection.onicecandidate = iceCallback1;
+    localConnection.onicecandidate = (event) => { iceCallback1(event, filterOutICECandidate) };
     setupLocalConnection(localConnection);
 
     remoteConnection = new RTCPeerConnection();
-    remoteConnection.onicecandidate = iceCallback2;
+    remoteConnection.onicecandidate = (event) => { iceCallback2(event, filterOutICECandidate) };
     setupRemoteConnection(remoteConnection);
 
     localConnection.createOffer().then(gotDescription1, onCreateSessionDescriptionError);
@@ -40,14 +40,25 @@ function gotDescription2(desc)
     localConnection.setRemoteDescription(desc);
 }
 
-function iceCallback1(event)
+function iceCallback1(event, filterOutICECandidate)
 {
-    if (event.candidate)
-        remoteConnection.addIceCandidate(event.candidate).then(onAddIceCandidateSuccess, onAddIceCandidateError);
+    if (!event.candidate)
+        return;
+
+    if (filterOutICECandidate && filterOutICECandidate(event.candidate))
+        return;
+
+    remoteConnection.addIceCandidate(event.candidate).then(onAddIceCandidateSuccess, onAddIceCandidateError);
 }
 
-function iceCallback2(event)
+function iceCallback2(event, filterOutICECandidate)
 {
+    if (!event.candidate)
+        return;
+
+    if (filterOutICECandidate && filterOutICECandidate(event.candidate))
+        return;
+
     if (event.candidate)
         localConnection.addIceCandidate(event.candidate).then(onAddIceCandidateSuccess, onAddIceCandidateError);
 }
index c452158..981608d 100644 (file)
@@ -1,3 +1,44 @@
+2017-02-27  Youenn Fablet  <youenn@apple.com>
+
+        [WebRTC] Add support for libwebrtc TCP incoming connections
+        https://bugs.webkit.org/show_bug.cgi?id=168748
+
+        Reviewed by Alex Christensen.
+
+        Covered by added layout tests.
+
+        When a libwebrtc server socket is signalling a new connnection through SignalNewConnection, we do:
+        - Wrap the incoming socket into a LibWebRTCSocketClient
+        - Store it into a pending socket map with an identifier
+        - Send a message to the web process of a new connection with the server socket identifier and new connection socket identifier.
+        The Web process then creates a WebRTCSocket wrapper around it by sendinig a WrapNewTCPConnection message.
+        It then propagates the SignalNewConnection to libwebrtc code path.
+
+        * NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:
+        (WebKit::LibWebRTCSocketClient::LibWebRTCSocketClient):
+        (WebKit::LibWebRTCSocketClient::signalReadPacket):
+        (WebKit::LibWebRTCSocketClient::signalSentPacket):
+        (WebKit::LibWebRTCSocketClient::signalNewConnection):
+        (WebKit::LibWebRTCSocketClient::signalAddressReady):
+        (WebKit::LibWebRTCSocketClient::signalConnect):
+        (WebKit::LibWebRTCSocketClient::signalClose):
+        * NetworkProcess/webrtc/LibWebRTCSocketClient.h:
+        * NetworkProcess/webrtc/NetworkRTCProvider.cpp:
+        (WebKit::NetworkRTCProvider::wrapNewTCPConnection):
+        (WebKit::NetworkRTCProvider::newConnection):
+        * NetworkProcess/webrtc/NetworkRTCProvider.h:
+        * NetworkProcess/webrtc/NetworkRTCProvider.messages.in:
+        * WebProcess/Network/webrtc/LibWebRTCSocket.cpp:
+        (WebKit::LibWebRTCSocket::signalNewConnection):
+        * WebProcess/Network/webrtc/LibWebRTCSocket.h:
+        * WebProcess/Network/webrtc/LibWebRTCSocketFactory.cpp:
+        (WebKit::LibWebRTCSocketFactory::createNewConnectionSocket):
+        * WebProcess/Network/webrtc/LibWebRTCSocketFactory.h:
+        * WebProcess/Network/webrtc/WebRTCSocket.cpp:
+        (WebKit::WebRTCSocket::signalNewConnection):
+        * WebProcess/Network/webrtc/WebRTCSocket.h:
+        * WebProcess/Network/webrtc/WebRTCSocket.messages.in:
+
 2017-02-27  Brent Fulgham  <bfulgham@apple.com>
 
         [Mac] Don't use undefined sandbox rule on macOS 10.11 or earlier
index 33c6be5..4a96e84 100644 (file)
@@ -51,14 +51,25 @@ LibWebRTCSocketClient::LibWebRTCSocketClient(uint64_t identifier, NetworkRTCProv
 
     m_socket->SignalReadPacket.connect(this, &LibWebRTCSocketClient::signalReadPacket);
     m_socket->SignalSentPacket.connect(this, &LibWebRTCSocketClient::signalSentPacket);
-    m_socket->SignalConnect.connect(this, &LibWebRTCSocketClient::signalConnect);
     m_socket->SignalClose.connect(this, &LibWebRTCSocketClient::signalClose);
 
-    if (type == Type::ClientTCP) {
+    switch (type) {
+    case Type::ServerConnectionTCP:
+        return;
+    case Type::ClientTCP:
+        m_socket->SignalConnect.connect(this, &LibWebRTCSocketClient::signalConnect);
         m_socket->SignalAddressReady.connect(this, &LibWebRTCSocketClient::signalAddressReady);
         return;
+    case Type::ServerTCP:
+        m_socket->SignalConnect.connect(this, &LibWebRTCSocketClient::signalConnect);
+        m_socket->SignalNewConnection.connect(this, &LibWebRTCSocketClient::signalNewConnection);
+        signalAddressReady();
+        return;
+    case Type::UDP:
+        m_socket->SignalConnect.connect(this, &LibWebRTCSocketClient::signalConnect);
+        signalAddressReady();
+        return;
     }
-    signalAddressReady();
 }
 
 void LibWebRTCSocketClient::sendTo(const WebCore::SharedBuffer& buffer, const rtc::SocketAddress& socketAddress, const rtc::PacketOptions& options)
@@ -79,8 +90,9 @@ void LibWebRTCSocketClient::setOption(int option, int value)
     m_socket->SetOption(static_cast<rtc::Socket::Option>(option), value);
 }
 
-void LibWebRTCSocketClient::signalReadPacket(rtc::AsyncPacketSocket*, const char* value, size_t length, const rtc::SocketAddress& address, const rtc::PacketTime& packetTime)
+void LibWebRTCSocketClient::signalReadPacket(rtc::AsyncPacketSocket* socket, const char* value, size_t length, const rtc::SocketAddress& address, const rtc::PacketTime& packetTime)
 {
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
     auto buffer = WebCore::SharedBuffer::create(value, length);
     m_rtcProvider.sendFromMainThread([identifier = m_identifier, buffer = WTFMove(buffer), address = RTCNetwork::isolatedCopy(address), packetTime](IPC::Connection& connection) {
         IPC::DataReference data(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
@@ -88,15 +100,23 @@ void LibWebRTCSocketClient::signalReadPacket(rtc::AsyncPacketSocket*, const char
     });
 }
 
-void LibWebRTCSocketClient::signalSentPacket(rtc::AsyncPacketSocket*, const rtc::SentPacket& sentPacket)
+void LibWebRTCSocketClient::signalSentPacket(rtc::AsyncPacketSocket* socket, const rtc::SentPacket& sentPacket)
 {
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
     m_rtcProvider.sendFromMainThread([identifier = m_identifier, sentPacket](IPC::Connection& connection) {
         connection.send(Messages::WebRTCSocket::SignalSentPacket(sentPacket.packet_id, sentPacket.send_time_ms), identifier);
     });
 }
 
-void LibWebRTCSocketClient::signalAddressReady(rtc::AsyncPacketSocket*, const rtc::SocketAddress& address)
+void LibWebRTCSocketClient::signalNewConnection(rtc::AsyncPacketSocket* socket, rtc::AsyncPacketSocket* newSocket)
+{
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
+    m_rtcProvider.newConnection(*this, std::unique_ptr<rtc::AsyncPacketSocket>(newSocket));
+}
+
+void LibWebRTCSocketClient::signalAddressReady(rtc::AsyncPacketSocket* socket, const rtc::SocketAddress& address)
 {
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
     m_rtcProvider.sendFromMainThread([identifier = m_identifier, address = RTCNetwork::isolatedCopy(address)](IPC::Connection& connection) {
         connection.send(Messages::WebRTCSocket::SignalAddressReady(RTCNetwork::SocketAddress(address)), identifier);
     });
@@ -107,15 +127,17 @@ void LibWebRTCSocketClient::signalAddressReady()
     signalAddressReady(m_socket.get(), m_socket->GetLocalAddress());
 }
 
-void LibWebRTCSocketClient::signalConnect(rtc::AsyncPacketSocket*)
+void LibWebRTCSocketClient::signalConnect(rtc::AsyncPacketSocket* socket)
 {
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
     m_rtcProvider.sendFromMainThread([identifier = m_identifier](IPC::Connection& connection) {
         connection.send(Messages::WebRTCSocket::SignalConnect(), identifier);
     });
 }
 
-void LibWebRTCSocketClient::signalClose(rtc::AsyncPacketSocket*, int error)
+void LibWebRTCSocketClient::signalClose(rtc::AsyncPacketSocket* socket, int error)
 {
+    ASSERT_UNUSED(socket, m_socket.get() == socket);
     m_rtcProvider.sendFromMainThread([identifier = m_identifier, error](IPC::Connection& connection) {
         connection.send(Messages::WebRTCSocket::SignalClose(error), identifier);
     });
index 375cfdf..e4acb62 100644 (file)
@@ -49,10 +49,12 @@ class NetworkRTCProvider;
 
 class LibWebRTCSocketClient final : public sigslot::has_slots<> {
 public:
-    enum class Type { UDP, ServerTCP, ClientTCP };
+    enum class Type { UDP, ServerTCP, ClientTCP, ServerConnectionTCP };
 
     LibWebRTCSocketClient(uint64_t identifier, NetworkRTCProvider&, std::unique_ptr<rtc::AsyncPacketSocket>&&, Type);
 
+    uint64_t identifier() const { return m_identifier; }
+
 private:
     friend class NetworkRTCSocket;
 
@@ -65,6 +67,7 @@ private:
     void signalAddressReady(rtc::AsyncPacketSocket*, const rtc::SocketAddress&);
     void signalConnect(rtc::AsyncPacketSocket*);
     void signalClose(rtc::AsyncPacketSocket*, int);
+    void signalNewConnection(rtc::AsyncPacketSocket* socket, rtc::AsyncPacketSocket* newSocket);
 
     void signalAddressReady();
 
index cb2d00d..6ec1b53 100644 (file)
@@ -32,6 +32,7 @@
 #include "NetworkProcess.h"
 #include "NetworkRTCSocket.h"
 #include "WebRTCResolverMessages.h"
+#include "WebRTCSocketMessages.h"
 #include <WebCore/LibWebRTCMacros.h>
 #include <webrtc/base/asyncpacketsocket.h>
 #include <wtf/MainThread.h>
@@ -91,6 +92,14 @@ void NetworkRTCProvider::createClientTCPSocket(uint64_t identifier, const RTCNet
     });
 }
 
+void NetworkRTCProvider::wrapNewTCPConnection(uint64_t identifier, uint64_t newConnectionSocketIdentifier)
+{
+    callOnRTCNetworkThread([this, identifier, newConnectionSocketIdentifier]() {
+        std::unique_ptr<rtc::AsyncPacketSocket> socket = m_pendingIncomingSockets.take(newConnectionSocketIdentifier);
+        addSocket(identifier, std::make_unique<LibWebRTCSocketClient>(identifier, *this, WTFMove(socket), LibWebRTCSocketClient::Type::ServerConnectionTCP));
+    });
+}
+
 void NetworkRTCProvider::addSocket(uint64_t identifier, std::unique_ptr<LibWebRTCSocketClient>&& socket)
 {
     m_sockets.add(identifier, WTFMove(socket));
@@ -101,6 +110,14 @@ std::unique_ptr<LibWebRTCSocketClient> NetworkRTCProvider::takeSocket(uint64_t i
     return m_sockets.take(identifier);
 }
 
+void NetworkRTCProvider::newConnection(LibWebRTCSocketClient& serverSocket, std::unique_ptr<rtc::AsyncPacketSocket>&& newSocket)
+{
+    sendFromMainThread([identifier = serverSocket.identifier(), incomingSocketIdentifier = ++m_incomingSocketIdentifier, remoteAddress = RTCNetwork::isolatedCopy(newSocket->GetRemoteAddress())](IPC::Connection& connection) {
+        connection.send(Messages::WebRTCSocket::SignalNewConnection(incomingSocketIdentifier, RTCNetwork::SocketAddress(remoteAddress)), identifier);
+    });
+    m_pendingIncomingSockets.add(m_incomingSocketIdentifier, WTFMove(newSocket));
+}
+
 void NetworkRTCProvider::didReceiveNetworkRTCSocketMessage(IPC::Connection& connection, IPC::Decoder& decoder)
 {
     NetworkRTCSocket(decoder.destinationID(), *this).didReceiveMessage(connection, decoder);
index 6a72182..2e8806d 100644 (file)
@@ -66,12 +66,16 @@ public:
     void callOnRTCNetworkThread(Function<void()>&&);
     void sendFromMainThread(Function<void(IPC::Connection&)>&&);
 
+    void newConnection(LibWebRTCSocketClient&, std::unique_ptr<rtc::AsyncPacketSocket>&&);
+
 private:
     explicit NetworkRTCProvider(NetworkConnectionToWebProcess&);
 
     void createUDPSocket(uint64_t, const RTCNetwork::SocketAddress&, uint16_t, uint16_t);
     void createClientTCPSocket(uint64_t, const RTCNetwork::SocketAddress&, const RTCNetwork::SocketAddress&, int);
     void createServerTCPSocket(uint64_t, const RTCNetwork::SocketAddress&, uint16_t minPort, uint16_t maxPort, int);
+    void wrapNewTCPConnection(uint64_t identifier, uint64_t newConnectionSocketIdentifier);
+
     void createResolver(uint64_t, const String&);
     void stopResolver(uint64_t);
 
@@ -102,6 +106,9 @@ private:
 
     std::unique_ptr<rtc::Thread> m_rtcNetworkThread;
     UniqueRef<rtc::BasicPacketSocketFactory> m_packetSocketFactory;
+
+    HashMap<uint64_t, std::unique_ptr<rtc::AsyncPacketSocket>> m_pendingIncomingSockets;
+    uint64_t m_incomingSocketIdentifier { 0 };
 };
 
 } // namespace WebKit
index 9409521..48914c3 100644 (file)
@@ -28,6 +28,7 @@ messages -> NetworkRTCProvider {
     CreateClientTCPSocket(int identifier, WebKit::RTCNetwork::SocketAddress localAddress, WebKit::RTCNetwork::SocketAddress remoteAddress, int options)
     CreateResolver(uint64_t identifier, String address)
     StopResolver(uint64_t identifier)
+    WrapNewTCPConnection(uint64_t identifier, uint64_t newConnectionSocketIdentifier)
 }
 
 #endif // USE(LIBWEBRTC)
index c49b5d5..7713035 100644 (file)
@@ -106,6 +106,12 @@ void LibWebRTCSocket::signalClose(int error)
     SignalClose(this, error);
 }
 
+void LibWebRTCSocket::signalNewConnection(rtc::AsyncPacketSocket* newConnectionSocket)
+{
+    ASSERT(m_type == Type::ServerTCP);
+    SignalNewConnection(this, newConnectionSocket);
+}
+
 static inline String authKey(const rtc::PacketOptions& options)
 {
     if (options.packet_time_params.srtp_auth_key.size() <= 0)
index 957437f..13444df 100644 (file)
@@ -48,7 +48,7 @@ class LibWebRTCSocketFactory;
 
 class LibWebRTCSocket final : public rtc::AsyncPacketSocket {
 public:
-    enum class Type { UDP, ServerTCP, ClientTCP };
+    enum class Type { UDP, ServerTCP, ClientTCP, ServerConnectionTCP };
 
     LibWebRTCSocket(LibWebRTCSocketFactory&, uint64_t identifier, Type, const rtc::SocketAddress& localAddress, const rtc::SocketAddress& remoteAddress);
     ~LibWebRTCSocket();
@@ -69,6 +69,7 @@ private:
     void signalAddressReady(const rtc::SocketAddress&);
     void signalConnect();
     void signalClose(int);
+    void signalNewConnection(rtc::AsyncPacketSocket*);
 
     // AsyncPacketSocket API
     int GetError() const final { return m_error; }
index ccd8d60..a20ab9d 100644 (file)
@@ -86,6 +86,21 @@ rtc::AsyncPacketSocket* LibWebRTCSocketFactory::CreateClientTcpSocket(const rtc:
     return socket.release();
 }
 
+rtc::AsyncPacketSocket* LibWebRTCSocketFactory::createNewConnectionSocket(LibWebRTCSocket& serverSocket, uint64_t newConnectionSocketIdentifier, const rtc::SocketAddress& remoteAddress)
+{
+    auto socket = std::make_unique<LibWebRTCSocket>(*this, ++s_uniqueSocketIdentifier, LibWebRTCSocket::Type::ServerConnectionTCP, serverSocket.localAddress(), remoteAddress);
+    socket->setState(LibWebRTCSocket::STATE_CONNECTED);
+    m_sockets.set(socket->identifier(), socket.get());
+
+    callOnMainThread([identifier = socket->identifier(), newConnectionSocketIdentifier]() {
+        if (!WebProcess::singleton().networkConnection().connection().send(Messages::NetworkRTCProvider::WrapNewTCPConnection(identifier, newConnectionSocketIdentifier), 0)) {
+            // FIXME: Set error back to socket
+            return;
+        }
+    });
+    return socket.release();
+}
+
 void LibWebRTCSocketFactory::detach(LibWebRTCSocket& socket)
 {
     ASSERT(m_sockets.contains(socket.identifier()));
index 023f175..c131df2 100644 (file)
@@ -47,6 +47,8 @@ public:
 
     std::unique_ptr<LibWebRTCResolver> takeResolver(uint64_t identifier) { return m_resolvers.take(identifier); }
 
+    rtc::AsyncPacketSocket* createNewConnectionSocket(LibWebRTCSocket&, uint64_t newConnectionSocketIdentifier, const rtc::SocketAddress&);
+
 private:
     rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress&, uint16_t minPort, uint16_t maxPort) final;
     rtc::AsyncPacketSocket* CreateServerTcpSocket(const rtc::SocketAddress&, uint16_t min_port, uint16_t max_port, int options) final;
index d6dce48..ba35d7f 100644 (file)
@@ -90,6 +90,13 @@ void WebRTCSocket::signalClose(int error)
     });
 }
 
+void WebRTCSocket::signalNewConnection(uint64_t newSocketIdentifier, const RTCNetwork::SocketAddress& remoteAddress)
+{
+    signalOnNetworkThread(m_factory, m_identifier, [newSocketIdentifier, remoteAddress = RTCNetwork::isolatedCopy(remoteAddress.value)](LibWebRTCSocket& socket) {
+        socket.signalNewConnection(socket.m_factory.createNewConnectionSocket(socket, newSocketIdentifier, remoteAddress));
+    });
+}
+
 } // namespace WebKit
 
 #endif // USE(LIBWEBRTC)
index d26d60f..9f4cb78 100644 (file)
@@ -55,7 +55,8 @@ private:
     void signalAddressReady(const RTCNetwork::SocketAddress&);
     void signalConnect();
     void signalClose(int);
-    
+    void signalNewConnection(uint64_t newSocketIdentifier, const WebKit::RTCNetwork::SocketAddress&);
+
     LibWebRTCSocketFactory& m_factory;
     uint64_t m_identifier { 0 };
 };
index 426d6d1..f611285 100644 (file)
@@ -28,6 +28,7 @@ messages -> WebRTCSocket {
     SignalAddressReady(WebKit::RTCNetwork::SocketAddress address)
     SignalConnect()
     SignalClose(int error)
+    SignalNewConnection(uint64_t newSocketIdentifier, WebKit::RTCNetwork::SocketAddress remoteAddress)
 }
 
 #endif // USE(LIBWEBRTC)