Remove cricket::UdpTransport.

This code is never built by GN, and the header is never included.

Bug: webrtc:9855
Change-Id: I7f79c2b16e4a833fa7788be87dbdf9b41247c9e4
Reviewed-on: https://webrtc-review.googlesource.com/c/111755
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25754}
This commit is contained in:
Mirko Bonadei 2018-11-22 14:35:05 +01:00 committed by Commit Bot
parent 94c94205f7
commit 8e668633c7
3 changed files with 0 additions and 410 deletions

View File

@ -1,133 +0,0 @@
/*
* 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.
*/
#include "p2p/base/udptransport.h"
#include <string>
#include <utility> // For std::move.
#include "rtc_base/asyncpacketsocket.h"
#include "rtc_base/asyncudpsocket.h"
#include "rtc_base/logging.h"
#include "rtc_base/nethelper.h"
#include "rtc_base/socketaddress.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_checker.h"
namespace cricket {
UdpTransport::UdpTransport(const std::string& transport_name,
std::unique_ptr<rtc::AsyncPacketSocket> socket)
: transport_name_(transport_name), socket_(std::move(socket)) {
RTC_DCHECK(socket_);
socket_->SignalReadPacket.connect(this, &UdpTransport::OnSocketReadPacket);
socket_->SignalSentPacket.connect(this, &UdpTransport::OnSocketSentPacket);
}
UdpTransport::~UdpTransport() {
RTC_DCHECK_RUN_ON(&network_thread_checker_);
}
rtc::SocketAddress UdpTransport::GetLocalAddress() const {
RTC_DCHECK_RUN_ON(&network_thread_checker_);
return socket_->GetLocalAddress();
}
bool UdpTransport::SetRemoteAddress(const rtc::SocketAddress& addr) {
RTC_DCHECK_RUN_ON(&network_thread_checker_);
if (!addr.IsComplete()) {
RTC_LOG(LS_WARNING) << "Remote address not complete.";
return false;
}
// TODO(johan): check for ipv4, other settings.
bool prev_destination_nil = remote_address_.IsNil();
remote_address_ = addr;
// Going from "didn't have destination" to "have destination" or vice versa.
if (prev_destination_nil != remote_address_.IsNil()) {
SignalWritableState(this);
if (prev_destination_nil) {
SignalReadyToSend(this);
}
}
return true;
}
rtc::SocketAddress UdpTransport::GetRemoteAddress() const {
RTC_DCHECK_RUN_ON(&network_thread_checker_);
return remote_address_;
}
const std::string& UdpTransport::transport_name() const {
return transport_name_;
}
bool UdpTransport::receiving() const {
// TODO(johan): Implement method and signal.
return true;
}
bool UdpTransport::writable() const {
RTC_DCHECK_RUN_ON(&network_thread_checker_);
return !remote_address_.IsNil();
}
int UdpTransport::SendPacket(const char* data,
size_t len,
const rtc::PacketOptions& options,
int flags) {
// No thread_checker in high frequency network function.
if (remote_address_.IsNil()) {
RTC_LOG(LS_WARNING) << "Remote address not set.";
send_error_ = ENOTCONN;
return -1;
}
int result =
socket_->SendTo((const void*)data, len, remote_address_, options);
if (result <= 0) {
RTC_LOG(LS_VERBOSE) << "SendPacket() " << result;
}
return result;
}
absl::optional<rtc::NetworkRoute> UdpTransport::network_route() const {
rtc::NetworkRoute network_route;
network_route.packet_overhead =
/*kUdpOverhead=*/8 + GetIpOverhead(GetLocalAddress().family());
return absl::optional<rtc::NetworkRoute>(network_route);
}
int UdpTransport::SetOption(rtc::Socket::Option opt, int value) {
return 0;
}
int UdpTransport::GetError() {
return send_error_;
}
rtc::PacketTransportInternal* UdpTransport::GetInternal() {
return this;
}
void UdpTransport::OnSocketReadPacket(rtc::AsyncPacketSocket* socket,
const char* data,
size_t len,
const rtc::SocketAddress& remote_addr,
const int64_t& packet_time_us) {
// No thread_checker in high frequency network function.
SignalReadPacket(this, data, len, packet_time_us, 0);
}
void UdpTransport::OnSocketSentPacket(rtc::AsyncPacketSocket* socket,
const rtc::SentPacket& packet) {
RTC_DCHECK_EQ(socket_.get(), socket);
SignalSentPacket(this, packet);
}
} // namespace cricket

View File

@ -1,88 +0,0 @@
/*
* 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.
*/
#ifndef P2P_BASE_UDPTRANSPORT_H_
#define P2P_BASE_UDPTRANSPORT_H_
#include <memory>
#include <string>
#include "absl/types/optional.h"
#include "api/ortc/udptransportinterface.h"
#include "p2p/base/packettransportinternal.h"
#include "rtc_base/asyncpacketsocket.h" // For PacketOptions.
#include "rtc_base/thread_checker.h"
namespace rtc {
class AsyncPacketSocket;
struct SentPacket;
class SocketAddress;
} // namespace rtc
namespace cricket {
// Implementation of UdpTransportInterface.
// Used by OrtcFactory.
class UdpTransport : public rtc::PacketTransportInternal,
public webrtc::UdpTransportInterface {
public:
// |transport_name| is only used for identification/logging.
// |socket| must be non-null.
UdpTransport(const std::string& transport_name,
std::unique_ptr<rtc::AsyncPacketSocket> socket);
~UdpTransport() override;
// Overrides of UdpTransportInterface, used by the API consumer.
rtc::SocketAddress GetLocalAddress() const override;
bool SetRemoteAddress(const rtc::SocketAddress& addr) override;
rtc::SocketAddress GetRemoteAddress() const override;
// Overrides of PacketTransportInternal, used by webrtc internally.
const std::string& transport_name() const override;
bool receiving() const override;
bool writable() const override;
int SendPacket(const char* data,
size_t len,
const rtc::PacketOptions& options,
int flags) override;
int SetOption(rtc::Socket::Option opt, int value) override;
int GetError() override;
absl::optional<rtc::NetworkRoute> network_route() const override;
protected:
PacketTransportInternal* GetInternal() override;
private:
void OnSocketReadPacket(rtc::AsyncPacketSocket* socket,
const char* data,
size_t len,
const rtc::SocketAddress& remote_addr,
const int64_t& packet_time_us);
void OnSocketSentPacket(rtc::AsyncPacketSocket* socket,
const rtc::SentPacket& packet);
bool IsLocalConsistent();
std::string transport_name_;
int send_error_ = 0;
std::unique_ptr<rtc::AsyncPacketSocket> socket_;
// If not set, will be an "nil" address ("IsNil" returns true).
rtc::SocketAddress remote_address_;
rtc::ThreadChecker network_thread_checker_;
};
} // namespace cricket
#endif // P2P_BASE_UDPTRANSPORT_H_

View File

@ -1,189 +0,0 @@
/*
* 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.
*/
#include <algorithm>
#include <list>
#include <memory>
#include <utility>
#include <vector>
#include "p2p/base/basicpacketsocketfactory.h"
#include "p2p/base/packettransportinternal.h"
#include "p2p/base/udptransport.h"
#include "rtc_base/asyncpacketsocket.h"
#include "rtc_base/gunit.h"
#include "rtc_base/ipaddress.h"
#include "rtc_base/socketaddress.h"
#include "rtc_base/socketserver.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtualsocketserver.h"
namespace cricket {
constexpr int kTimeoutMs = 10000;
static const rtc::IPAddress kIPv4LocalHostAddress =
rtc::IPAddress(0x7F000001); // 127.0.0.1
class UdpTransportTest : public testing::Test, public sigslot::has_slots<> {
public:
UdpTransportTest()
: virtual_socket_server_(new rtc::VirtualSocketServer()),
network_thread_(virtual_socket_server_.get()),
ep1_("Name1",
std::unique_ptr<rtc::AsyncPacketSocket>(
socket_factory_.CreateUdpSocket(
rtc::SocketAddress(rtc::GetAnyIP(AF_INET), 0),
0,
0))),
ep2_("Name2",
std::unique_ptr<rtc::AsyncPacketSocket>(
socket_factory_.CreateUdpSocket(
rtc::SocketAddress(rtc::GetAnyIP(AF_INET), 0),
0,
0))) {
// Setup IP Address for outgoing packets from sockets bound to IPV4
// INADDR_ANY ("0.0.0.0."), as used above when creating the virtual
// sockets. The virtual socket server sends these packets only if the
// default address is explicit set. With a physical socket, the actual
// network stack / operating system would set the IP address for outgoing
// packets.
virtual_socket_server_->SetDefaultRoute(kIPv4LocalHostAddress);
}
struct Endpoint : public sigslot::has_slots<> {
explicit Endpoint(std::string tch_name,
std::unique_ptr<rtc::AsyncPacketSocket> socket) {
ch_.reset(new UdpTransport(std::move(tch_name), std::move(socket)));
ch_->SignalReadPacket.connect(this, &Endpoint::OnReadPacket);
ch_->SignalSentPacket.connect(this, &Endpoint::OnSentPacket);
ch_->SignalReadyToSend.connect(this, &Endpoint::OnReadyToSend);
ch_->SignalWritableState.connect(this, &Endpoint::OnWritableState);
}
bool CheckData(const char* data, int len) {
bool ret = false;
if (!ch_packets_.empty()) {
std::string packet = ch_packets_.front();
ret = (packet == std::string(data, len));
ch_packets_.pop_front();
}
return ret;
}
void OnWritableState(rtc::PacketTransportInternal* transport) {
num_sig_writable_++;
}
void OnReadyToSend(rtc::PacketTransportInternal* transport) {
num_sig_ready_to_send_++;
}
void OnReadPacket(rtc::PacketTransportInternal* transport,
const char* data,
size_t len,
const int64_t& /* packet_time_us */,
int flags) {
num_received_packets_++;
RTC_LOG(LS_VERBOSE) << "OnReadPacket (unittest)";
ch_packets_.push_front(std::string(data, len));
}
void OnSentPacket(rtc::PacketTransportInternal* transport,
const rtc::SentPacket&) {
num_sig_sent_packets_++;
}
int SendData(const char* data, size_t len) {
rtc::PacketOptions options;
return ch_->SendPacket(data, len, options, 0);
}
void GetLocalPort(uint16_t* local_port) {
*local_port = ch_->GetLocalAddress().port();
}
std::list<std::string> ch_packets_;
std::unique_ptr<UdpTransport> ch_;
uint32_t num_received_packets_ = 0; // Increases on SignalReadPacket.
uint32_t num_sig_sent_packets_ = 0; // Increases on SignalSentPacket.
uint32_t num_sig_writable_ = 0; // Increases on SignalWritable.
uint32_t num_sig_ready_to_send_ = 0; // Increases on SignalReadyToSend.
};
std::unique_ptr<rtc::VirtualSocketServer> virtual_socket_server_;
rtc::AutoSocketServerThread network_thread_;
// Uses current thread's socket server, which will be set by ss_scope_.
rtc::BasicPacketSocketFactory socket_factory_;
Endpoint ep1_;
Endpoint ep2_;
void TestSendRecv() {
for (uint32_t i = 0; i < 5; ++i) {
static const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
int len = static_cast<int>(strlen(data));
// local_channel <==> remote_channel
EXPECT_EQ_WAIT(len, ep1_.SendData(data, len), kTimeoutMs);
EXPECT_TRUE_WAIT(ep2_.CheckData(data, len), kTimeoutMs);
EXPECT_EQ_WAIT(i + 1u, ep2_.num_received_packets_, kTimeoutMs);
EXPECT_EQ_WAIT(len, ep2_.SendData(data, len), kTimeoutMs);
EXPECT_TRUE_WAIT(ep1_.CheckData(data, len), kTimeoutMs);
EXPECT_EQ_WAIT(i + 1u, ep1_.num_received_packets_, kTimeoutMs);
}
}
};
TEST_F(UdpTransportTest, AddressGetters) {
// Initially, remote address should be nil but local address shouldn't be.
EXPECT_FALSE(ep1_.ch_->GetLocalAddress().IsNil());
EXPECT_TRUE(ep1_.ch_->GetRemoteAddress().IsNil());
rtc::SocketAddress destination("127.0.0.1", 1337);
ASSERT_TRUE(ep1_.ch_->SetRemoteAddress(destination));
EXPECT_EQ(destination, ep1_.ch_->GetRemoteAddress());
}
// Setting an invalid address should fail and have no effect.
TEST_F(UdpTransportTest, SettingIncompleteRemoteAddressFails) {
EXPECT_FALSE(ep1_.ch_->SetRemoteAddress(rtc::SocketAddress("127.0.0.1", 0)));
EXPECT_TRUE(ep1_.ch_->GetRemoteAddress().IsNil());
}
TEST_F(UdpTransportTest, SendRecvBasic) {
uint16_t port;
ep2_.GetLocalPort(&port);
rtc::SocketAddress addr2 = rtc::SocketAddress("127.0.0.1", port);
EXPECT_TRUE(ep1_.ch_->SetRemoteAddress(addr2));
ep1_.GetLocalPort(&port);
rtc::SocketAddress addr1 = rtc::SocketAddress("127.0.0.1", port);
EXPECT_TRUE(ep2_.ch_->SetRemoteAddress(addr1));
TestSendRecv();
}
// Test the signals and state methods used internally by causing a UdpTransport
// to send a packet to itself.
TEST_F(UdpTransportTest, StatusAndSignals) {
EXPECT_EQ(0u, ep1_.num_sig_writable_);
EXPECT_EQ(0u, ep1_.num_sig_ready_to_send_);
// Loopback
EXPECT_TRUE(!ep1_.ch_->writable());
rtc::SocketAddress addr = ep1_.ch_->GetLocalAddress();
// Keep port, but explicitly set IP.
addr.SetIP("127.0.0.1");
ep1_.ch_->SetRemoteAddress(addr);
EXPECT_TRUE(ep1_.ch_->writable());
EXPECT_EQ(1u, ep1_.num_sig_writable_);
EXPECT_EQ(1u, ep1_.num_sig_ready_to_send_);
const char data[] = "abc";
ep1_.SendData(data, sizeof(data));
EXPECT_EQ_WAIT(1u, ep1_.ch_packets_.size(), kTimeoutMs);
EXPECT_EQ_WAIT(1u, ep1_.num_sig_sent_packets_, kTimeoutMs);
}
} // namespace cricket