2016-05-14 03:19:31 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/tcp_port.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2025-01-17 13:22:54 +00:00
|
|
|
#include <cstdint>
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
#include <list>
|
2016-05-14 19:44:11 -07:00
|
|
|
#include <memory>
|
2025-01-17 13:22:54 +00:00
|
|
|
#include <string>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <vector>
|
2016-05-14 19:44:11 -07:00
|
|
|
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "api/candidate.h"
|
|
|
|
|
#include "api/test/rtc_error_matchers.h"
|
|
|
|
|
#include "api/units/time_delta.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/basic_packet_socket_factory.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "p2p/base/connection.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/p2p_constants.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "p2p/base/port.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/transport_description.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "rtc_base/async_packet_socket.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2024-06-06 07:31:07 -07:00
|
|
|
#include "rtc_base/crypto_random.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ip_address.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "rtc_base/network.h"
|
|
|
|
|
#include "rtc_base/network/sent_packet.h"
|
|
|
|
|
#include "rtc_base/socket.h"
|
2024-08-27 11:00:02 +00:00
|
|
|
#include "rtc_base/socket_address.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
|
|
|
|
#include "rtc_base/virtual_socket_server.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "test/gmock.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2022-03-28 14:58:26 +02:00
|
|
|
#include "test/scoped_key_value_config.h"
|
2025-01-17 13:22:54 +00:00
|
|
|
#include "test/wait_until.h"
|
2016-05-14 03:19:31 -07:00
|
|
|
|
|
|
|
|
using cricket::Connection;
|
|
|
|
|
using cricket::ICE_PWD_LENGTH;
|
|
|
|
|
using cricket::ICE_UFRAG_LENGTH;
|
|
|
|
|
using cricket::Port;
|
|
|
|
|
using cricket::TCPPort;
|
|
|
|
|
using rtc::SocketAddress;
|
2025-01-17 13:22:54 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
|
using ::testing::IsTrue;
|
2016-05-14 03:19:31 -07:00
|
|
|
|
|
|
|
|
static int kTimeout = 1000;
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
static const SocketAddress kLocalAddr("11.11.11.11", 0);
|
2018-03-07 15:49:32 -08:00
|
|
|
static const SocketAddress kLocalIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3",
|
|
|
|
|
0);
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
static const SocketAddress kAlternateLocalAddr("1.2.3.4", 0);
|
|
|
|
|
static const SocketAddress kRemoteAddr("22.22.22.22", 0);
|
2018-03-07 15:49:32 -08:00
|
|
|
static const SocketAddress kRemoteIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c4",
|
|
|
|
|
0);
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
|
2022-10-27 20:08:23 +02:00
|
|
|
constexpr uint64_t kTiebreakerDefault = 44444;
|
|
|
|
|
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
class ConnectionObserver : public sigslot::has_slots<> {
|
|
|
|
|
public:
|
2022-01-31 11:20:41 +01:00
|
|
|
explicit ConnectionObserver(Connection* conn) : conn_(conn) {
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
conn->SignalDestroyed.connect(this, &ConnectionObserver::OnDestroyed);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 11:20:41 +01:00
|
|
|
~ConnectionObserver() {
|
|
|
|
|
if (!connection_destroyed_) {
|
|
|
|
|
RTC_DCHECK(conn_);
|
|
|
|
|
conn_->SignalDestroyed.disconnect(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
bool connection_destroyed() { return connection_destroyed_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void OnDestroyed(Connection*) { connection_destroyed_ = true; }
|
|
|
|
|
|
2022-01-31 11:20:41 +01:00
|
|
|
Connection* const conn_;
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
bool connection_destroyed_ = false;
|
|
|
|
|
};
|
2016-05-14 03:19:31 -07:00
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
class TCPPortTest : public ::testing::Test, public sigslot::has_slots<> {
|
2016-05-14 03:19:31 -07:00
|
|
|
public:
|
|
|
|
|
TCPPortTest()
|
2017-05-16 18:00:06 -07:00
|
|
|
: ss_(new rtc::VirtualSocketServer()),
|
2017-05-08 05:25:41 -07:00
|
|
|
main_(ss_.get()),
|
2021-09-07 09:16:49 +02:00
|
|
|
socket_factory_(ss_.get()),
|
2016-05-14 03:19:31 -07:00
|
|
|
username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)),
|
|
|
|
|
password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) {}
|
|
|
|
|
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
rtc::Network* MakeNetwork(const SocketAddress& addr) {
|
|
|
|
|
networks_.emplace_back("unittest", "unittest", addr.ipaddr(), 32);
|
|
|
|
|
networks_.back().AddIP(addr.ipaddr());
|
|
|
|
|
return &networks_.back();
|
2016-05-14 03:19:31 -07:00
|
|
|
}
|
|
|
|
|
|
2024-08-27 11:00:02 +00:00
|
|
|
std::unique_ptr<TCPPort> CreateTCPPort(const SocketAddress& addr,
|
|
|
|
|
bool allow_listen = true,
|
|
|
|
|
int port_number = 0) {
|
2024-05-31 09:28:48 +00:00
|
|
|
auto port = std::unique_ptr<TCPPort>(
|
|
|
|
|
TCPPort::Create({.network_thread = &main_,
|
|
|
|
|
.socket_factory = &socket_factory_,
|
|
|
|
|
.network = MakeNetwork(addr),
|
|
|
|
|
.ice_username_fragment = username_,
|
|
|
|
|
.ice_password = password_,
|
|
|
|
|
.field_trials = &field_trials_},
|
2024-08-27 11:00:02 +00:00
|
|
|
port_number, port_number, allow_listen));
|
2024-05-31 09:28:48 +00:00
|
|
|
port->SetIceTiebreaker(kTiebreakerDefault);
|
|
|
|
|
return port;
|
2016-05-14 03:19:31 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-24 15:18:02 +01:00
|
|
|
std::unique_ptr<TCPPort> CreateTCPPort(const rtc::Network* network) {
|
2024-05-31 09:28:48 +00:00
|
|
|
auto port = std::unique_ptr<TCPPort>(
|
|
|
|
|
TCPPort::Create({.network_thread = &main_,
|
|
|
|
|
.socket_factory = &socket_factory_,
|
|
|
|
|
.network = network,
|
|
|
|
|
.ice_username_fragment = username_,
|
|
|
|
|
.ice_password = password_,
|
|
|
|
|
.field_trials = &field_trials_},
|
|
|
|
|
0, 0, true));
|
|
|
|
|
port->SetIceTiebreaker(kTiebreakerDefault);
|
|
|
|
|
return port;
|
2016-05-14 03:19:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
// When a "create port" helper method is called with an IP, we create a
|
|
|
|
|
// Network with that IP and add it to this list. Using a list instead of a
|
|
|
|
|
// vector so that when it grows, pointers aren't invalidated.
|
|
|
|
|
std::list<rtc::Network> networks_;
|
2016-05-14 19:44:11 -07:00
|
|
|
std::unique_ptr<rtc::VirtualSocketServer> ss_;
|
2017-05-08 05:25:41 -07:00
|
|
|
rtc::AutoSocketServerThread main_;
|
2016-05-14 03:19:31 -07:00
|
|
|
rtc::BasicPacketSocketFactory socket_factory_;
|
|
|
|
|
std::string username_;
|
|
|
|
|
std::string password_;
|
2022-03-28 14:58:26 +02:00
|
|
|
webrtc::test::ScopedKeyValueConfig field_trials_;
|
2016-05-14 03:19:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
SocketAddress local_address("127.0.0.1", 0);
|
|
|
|
|
// After calling this, when TCPPort attempts to get a socket bound to
|
|
|
|
|
// kLocalAddr, it will end up using localhost instead.
|
|
|
|
|
ss_->SetAlternativeLocalAddress(kLocalAddr.ipaddr(), local_address.ipaddr());
|
|
|
|
|
auto local_port = CreateTCPPort(kLocalAddr);
|
|
|
|
|
auto remote_port = CreateTCPPort(kRemoteAddr);
|
|
|
|
|
local_port->PrepareAddress();
|
|
|
|
|
remote_port->PrepareAddress();
|
|
|
|
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
|
|
|
|
Port::ORIGIN_MESSAGE);
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
// Verify that the socket actually used localhost, otherwise this test isn't
|
|
|
|
|
// doing what it meant to.
|
|
|
|
|
ASSERT_EQ(local_address.ipaddr(),
|
|
|
|
|
local_port->Candidates()[0].address().ipaddr());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the address the socket ends up bound to does not match any address of the
|
|
|
|
|
// TCPPort's Network, then the socket should be discarded and no candidates
|
|
|
|
|
// should be signaled. In the context of ICE, where one TCPPort is created for
|
|
|
|
|
// each Network, when this happens it's likely that the unexpected address is
|
|
|
|
|
// associated with some other Network, which another TCPPort is already
|
|
|
|
|
// covering.
|
|
|
|
|
TEST_F(TCPPortTest, TCPPortDiscardedIfBoundAddressDoesNotMatchNetwork) {
|
|
|
|
|
// Sockets bound to kLocalAddr will actually end up with kAlternateLocalAddr.
|
|
|
|
|
ss_->SetAlternativeLocalAddress(kLocalAddr.ipaddr(),
|
|
|
|
|
kAlternateLocalAddr.ipaddr());
|
|
|
|
|
|
|
|
|
|
// Create ports (local_port is the one whose IP will end up reassigned).
|
|
|
|
|
auto local_port = CreateTCPPort(kLocalAddr);
|
|
|
|
|
auto remote_port = CreateTCPPort(kRemoteAddr);
|
|
|
|
|
local_port->PrepareAddress();
|
|
|
|
|
remote_port->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
// Tell port to create a connection; it should be destroyed when it's
|
|
|
|
|
// realized that it's using an unexpected address.
|
|
|
|
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
|
|
|
|
Port::ORIGIN_MESSAGE);
|
|
|
|
|
ConnectionObserver observer(conn);
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(webrtc::WaitUntil(
|
|
|
|
|
[&] { return observer.connection_destroyed(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A caveat for the above logic: if the socket ends up bound to one of the IPs
|
|
|
|
|
// associated with the Network, just not the "best" one, this is ok.
|
|
|
|
|
TEST_F(TCPPortTest, TCPPortNotDiscardedIfNotBoundToBestIP) {
|
|
|
|
|
// Sockets bound to kLocalAddr will actually end up with kAlternateLocalAddr.
|
|
|
|
|
ss_->SetAlternativeLocalAddress(kLocalAddr.ipaddr(),
|
|
|
|
|
kAlternateLocalAddr.ipaddr());
|
|
|
|
|
|
|
|
|
|
// Set up a network with kLocalAddr1 as the "best" IP, and kAlternateLocalAddr
|
|
|
|
|
// as an alternate.
|
|
|
|
|
rtc::Network* network = MakeNetwork(kLocalAddr);
|
|
|
|
|
network->AddIP(kAlternateLocalAddr.ipaddr());
|
|
|
|
|
ASSERT_EQ(kLocalAddr.ipaddr(), network->GetBestIP());
|
|
|
|
|
|
|
|
|
|
// Create ports (using our special 2-IP Network for local_port).
|
|
|
|
|
auto local_port = CreateTCPPort(network);
|
|
|
|
|
auto remote_port = CreateTCPPort(kRemoteAddr);
|
|
|
|
|
local_port->PrepareAddress();
|
|
|
|
|
remote_port->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
// Expect connection to succeed.
|
|
|
|
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
|
|
|
|
Port::ORIGIN_MESSAGE);
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
Make Port (and subclasses) fully "Network"-based, instead of IP-based.
For ICE, we want sockets that are bound to specific network interfaces,
rather than to specific IP addresses. So, a while ago, we added a
"Network" class that gets passed into the Port constructor, in
addition to the IP address as before.
But we never finished the job of removing the IP address field, such that
a Port only guarantees something about the network interface it's
associated with, and not the specific IP address it ends up with.
This CL does that, and as a consequence, if a port ends up bound to
an IP address other than the "best" one (returned by Network::GetBestIP),
this *won't* be treated as an error.
This is relevant to Android, where even though we pass an IP address
into "Bind" as a way of identifying the network, the socket actually
gets bound using "android_setsocknetwork", which doesn't provide any
guarantees about the IP address. So, if a network interface has multiple
IPv6 addresses (for instance), we may not correctly predict the one
the OS will choose, and that's ok.
This CL also moves "SetAlternateLocalAddress" from VirtualSocket to
VirtualSocketServer, which makes for much more readable test code.
The next step, if there is one, is to pass along the Network class all
the way to SocketServer::Bind. Then the socket server could do smart
things with the network information. We could even stick a platform-
specific network handle in the Network object, such that the socket
server could use it for the binding, or for "sendmsg", for example.
See bug 7026 for more context about the sendmsg idea.
BUG=webrtc:7715
Review-Url: https://codereview.webrtc.org/2989303002
Cr-Commit-Position: refs/heads/master@{#19251}
2017-08-04 15:01:57 -07:00
|
|
|
|
|
|
|
|
// Verify that the socket actually used the alternate address, otherwise this
|
|
|
|
|
// test isn't doing what it meant to.
|
|
|
|
|
ASSERT_EQ(kAlternateLocalAddr.ipaddr(),
|
|
|
|
|
local_port->Candidates()[0].address().ipaddr());
|
2016-05-14 03:19:31 -07:00
|
|
|
}
|
2017-04-21 14:22:23 -07:00
|
|
|
|
2018-03-07 15:49:32 -08:00
|
|
|
// Regression test for crbug.com/webrtc/8972, caused by buggy comparison
|
|
|
|
|
// between rtc::IPAddress and rtc::InterfaceAddress.
|
|
|
|
|
TEST_F(TCPPortTest, TCPPortNotDiscardedIfBoundToTemporaryIP) {
|
|
|
|
|
networks_.emplace_back("unittest", "unittest", kLocalIPv6Addr.ipaddr(), 32);
|
|
|
|
|
networks_.back().AddIP(rtc::InterfaceAddress(
|
|
|
|
|
kLocalIPv6Addr.ipaddr(), rtc::IPV6_ADDRESS_FLAG_TEMPORARY));
|
|
|
|
|
|
|
|
|
|
auto local_port = CreateTCPPort(&networks_.back());
|
|
|
|
|
auto remote_port = CreateTCPPort(kRemoteIPv6Addr);
|
|
|
|
|
local_port->PrepareAddress();
|
|
|
|
|
remote_port->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
// Connection should succeed if the port isn't discarded.
|
|
|
|
|
Connection* conn = local_port->CreateConnection(remote_port->Candidates()[0],
|
|
|
|
|
Port::ORIGIN_MESSAGE);
|
|
|
|
|
ASSERT_NE(nullptr, conn);
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2018-03-07 15:49:32 -08:00
|
|
|
}
|
|
|
|
|
|
2017-04-21 14:22:23 -07:00
|
|
|
class SentPacketCounter : public sigslot::has_slots<> {
|
|
|
|
|
public:
|
2017-11-29 10:25:58 -08:00
|
|
|
explicit SentPacketCounter(TCPPort* p) {
|
2017-04-21 14:22:23 -07:00
|
|
|
p->SignalSentPacket.connect(this, &SentPacketCounter::OnSentPacket);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sent_packets() const { return sent_packets_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void OnSentPacket(const rtc::SentPacket&) { ++sent_packets_; }
|
|
|
|
|
|
|
|
|
|
int sent_packets_ = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Test that SignalSentPacket is fired when a packet is successfully sent, for
|
|
|
|
|
// both TCP client and server sockets.
|
|
|
|
|
TEST_F(TCPPortTest, SignalSentPacket) {
|
|
|
|
|
std::unique_ptr<TCPPort> client(CreateTCPPort(kLocalAddr));
|
|
|
|
|
std::unique_ptr<TCPPort> server(CreateTCPPort(kRemoteAddr));
|
|
|
|
|
client->SetIceRole(cricket::ICEROLE_CONTROLLING);
|
|
|
|
|
server->SetIceRole(cricket::ICEROLE_CONTROLLED);
|
|
|
|
|
client->PrepareAddress();
|
|
|
|
|
server->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
Connection* client_conn =
|
|
|
|
|
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
|
|
|
|
ASSERT_NE(nullptr, client_conn);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2017-04-21 14:22:23 -07:00
|
|
|
|
|
|
|
|
// Need to get the port of the actual outgoing socket, not the server socket..
|
|
|
|
|
cricket::Candidate client_candidate = client->Candidates()[0];
|
|
|
|
|
client_candidate.set_address(static_cast<cricket::TCPConnection*>(client_conn)
|
|
|
|
|
->socket()
|
|
|
|
|
->GetLocalAddress());
|
|
|
|
|
Connection* server_conn =
|
|
|
|
|
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
|
|
|
|
ASSERT_NE(nullptr, server_conn);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2017-04-21 14:22:23 -07:00
|
|
|
|
|
|
|
|
client_conn->Ping(rtc::TimeMillis());
|
|
|
|
|
server_conn->Ping(rtc::TimeMillis());
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
|
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return server_conn->writable(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2017-04-21 14:22:23 -07:00
|
|
|
|
|
|
|
|
SentPacketCounter client_counter(client.get());
|
|
|
|
|
SentPacketCounter server_counter(server.get());
|
|
|
|
|
static const char kData[] = "hello";
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
|
|
|
|
server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
|
|
|
|
}
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(10),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
|
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return server_counter.sent_packets(); }, Eq(10),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2017-04-21 14:22:23 -07:00
|
|
|
}
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
// Test that SignalSentPacket is fired when a packet is successfully sent, even
|
|
|
|
|
// after a remote server has been restarted.
|
|
|
|
|
TEST_F(TCPPortTest, SignalSentPacketAfterReconnect) {
|
|
|
|
|
std::unique_ptr<TCPPort> client(
|
|
|
|
|
CreateTCPPort(kLocalAddr, /*allow_listen=*/false));
|
|
|
|
|
constexpr int kServerPort = 123;
|
|
|
|
|
std::unique_ptr<TCPPort> server(
|
|
|
|
|
CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort));
|
|
|
|
|
client->SetIceRole(cricket::ICEROLE_CONTROLLING);
|
|
|
|
|
server->SetIceRole(cricket::ICEROLE_CONTROLLED);
|
|
|
|
|
client->PrepareAddress();
|
|
|
|
|
server->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
Connection* client_conn =
|
|
|
|
|
client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
|
|
|
|
|
ASSERT_NE(nullptr, client_conn);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
// Need to get the port of the actual outgoing socket.
|
|
|
|
|
cricket::Candidate client_candidate = client->Candidates()[0];
|
|
|
|
|
client_candidate.set_address(static_cast<cricket::TCPConnection*>(client_conn)
|
|
|
|
|
->socket()
|
|
|
|
|
->GetLocalAddress());
|
|
|
|
|
client_candidate.set_tcptype("");
|
|
|
|
|
Connection* server_conn =
|
|
|
|
|
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
EXPECT_FALSE(client_conn->writable());
|
|
|
|
|
client_conn->Ping(rtc::TimeMillis());
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_conn->writable(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
SentPacketCounter client_counter(client.get());
|
|
|
|
|
static const char kData[] = "hello";
|
|
|
|
|
int result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
|
|
|
|
EXPECT_EQ(result, 6);
|
|
|
|
|
|
|
|
|
|
// Deleting the server port should break the current connection.
|
|
|
|
|
server = nullptr;
|
|
|
|
|
server_conn = nullptr;
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return !client_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
// Recreate the server port with the same port number.
|
|
|
|
|
server = CreateTCPPort(kRemoteAddr, /*allow_listen=*/true, kServerPort);
|
|
|
|
|
server->SetIceRole(cricket::ICEROLE_CONTROLLED);
|
|
|
|
|
server->PrepareAddress();
|
|
|
|
|
|
|
|
|
|
// Sending a packet from the client will trigger a reconnect attempt but the
|
|
|
|
|
// packet will be discarded.
|
|
|
|
|
result = client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
|
|
|
|
|
EXPECT_EQ(result, SOCKET_ERROR);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
// For unknown reasons, connection is still supposed to be writable....
|
|
|
|
|
EXPECT_TRUE(client_conn->writable());
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
// All sent packets still fail to send.
|
|
|
|
|
EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()),
|
|
|
|
|
SOCKET_ERROR);
|
|
|
|
|
}
|
|
|
|
|
// And are not reported as sent.
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
// Create the server connection again so server can reply to STUN pings.
|
|
|
|
|
// Client outgoing socket port will have changed since the client create a new
|
|
|
|
|
// socket when it reconnect.
|
|
|
|
|
client_candidate = client->Candidates()[0];
|
|
|
|
|
client_candidate.set_address(static_cast<cricket::TCPConnection*>(client_conn)
|
|
|
|
|
->socket()
|
|
|
|
|
->GetLocalAddress());
|
|
|
|
|
client_candidate.set_tcptype("");
|
|
|
|
|
server_conn =
|
|
|
|
|
server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
|
2025-01-17 13:22:54 +00:00
|
|
|
ASSERT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return server_conn->connected(); }, IsTrue(),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
|
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(1),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
|
|
|
|
|
// Send Stun Binding request.
|
|
|
|
|
client_conn->Ping(rtc::TimeMillis());
|
|
|
|
|
// The Stun Binding request is reported as sent.
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
|
webrtc::WaitUntil([&] { return client_counter.sent_packets(); }, Eq(2),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
// Wait a bit for the Stun response to be received.
|
|
|
|
|
rtc::Thread::Current()->ProcessMessages(100);
|
|
|
|
|
|
|
|
|
|
// After the Stun Ping response has been received, packets can be sent again
|
|
|
|
|
// and SignalSentPacket should be invoked.
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
EXPECT_EQ(client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()),
|
|
|
|
|
6);
|
|
|
|
|
}
|
2025-01-17 13:22:54 +00:00
|
|
|
EXPECT_THAT(webrtc::WaitUntil(
|
|
|
|
|
[&] { return client_counter.sent_packets(); }, Eq(2 + 5),
|
|
|
|
|
{.timeout = webrtc::TimeDelta::Millis(kTimeout)}),
|
|
|
|
|
webrtc::IsRtcOk());
|
2024-08-27 11:00:02 +00:00
|
|
|
}
|