/* * Copyright 2017 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.
*/
namespace cricket { using ::webrtc::SafeTask; using ::webrtc::TimeDelta;
// All methods must be called on the network thread (which is either the thread // calling the constructor, or the separate thread explicitly passed to the // constructor). class FakeIceTransport : public IceTransportInternal { public: explicit FakeIceTransport(absl::string_view name, int component,
rtc::Thread* network_thread = nullptr)
: name_(name),
component_(component),
network_thread_(network_thread ? network_thread
: rtc::Thread::Current()) {
RTC_DCHECK(network_thread_);
} // Must be called either on the network thread, or after the network thread // has been shut down.
~FakeIceTransport() override { if (dest_ && dest_->dest_ == this) {
dest_->dest_ = nullptr;
}
}
// If async, will send packets by "Post"-ing to message queue instead of // synchronously "Send"-ing. void SetAsync(bool async) {
RTC_DCHECK_RUN_ON(network_thread_);
async_ = async;
} void SetAsyncDelay(int delay_ms) {
RTC_DCHECK_RUN_ON(network_thread_);
async_delay_ms_ = delay_ms;
}
// SetWritable, SetReceiving and SetDestination are the main methods that can // be used for testing, to simulate connectivity or lack thereof. void SetWritable(bool writable) {
RTC_DCHECK_RUN_ON(network_thread_);
set_writable(writable);
} void SetReceiving(bool receiving) {
RTC_DCHECK_RUN_ON(network_thread_);
set_receiving(receiving);
}
// Simulates the two transports connecting to each other. // If `asymmetric` is true this method only affects this FakeIceTransport. // If false, it affects `dest` as well. void SetDestination(FakeIceTransport* dest, bool asymmetric = false) {
RTC_DCHECK_RUN_ON(network_thread_); if (dest == dest_) { return;
}
RTC_DCHECK(!dest || !dest_)
<< "Changing fake destination from one to another is not supported."; if (dest) { // This simulates the delivery of candidates.
dest_ = dest;
set_writable(true); if (!asymmetric) {
dest->SetDestination(this, true);
}
} else { // Simulates loss of connectivity, by asymmetrically forgetting dest_.
dest_ = nullptr;
set_writable(false);
}
}
// Fake PacketTransportInternal implementation. bool writable() const override {
RTC_DCHECK_RUN_ON(network_thread_); return writable_;
} bool receiving() const override {
RTC_DCHECK_RUN_ON(network_thread_); return receiving_;
} // If combine is enabled, every two consecutive packets to be sent with // "SendPacket" will be combined into one outgoing packet. void combine_outgoing_packets(bool combine) {
RTC_DCHECK_RUN_ON(network_thread_);
combine_outgoing_packets_ = combine;
} int SendPacket(constchar* data,
size_t len, const rtc::PacketOptions& options, int flags) override {
RTC_DCHECK_RUN_ON(network_thread_); if (!dest_) { return -1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.