// Fake DTLS transport which is implemented by wrapping a fake ICE transport. // Doesn't interact directly with fake ICE transport for anything other than // sending packets. class FakeDtlsTransport : public DtlsTransportInternal {
public: explicit FakeDtlsTransport(scoped_refptr<IceTransportInterface> ice_transport)
: ice_transport_ref_(std::move(ice_transport)),
ice_transport_(static_cast<FakeIceTransportInternal*>(
ice_transport_ref_->internal())),
transport_name_(ice_transport_->transport_name()),
component_(ice_transport_->component()),
dtls_fingerprint_("", std::span<const uint8_t>()) {
RTC_DCHECK(ice_transport_);
ice_transport_->RegisterReceivedPacketCallback(
this, [&](PacketTransportInternal* transport, const ReceivedIpPacket& packet) {
OnIceTransportReadPacket(transport, packet);
});
ice_transport_->SubscribeNetworkRouteChanged(
this, [this](std::optional<NetworkRoute> network_route) {
OnNetworkRouteChanged(network_route);
});
} explicit FakeDtlsTransport(std::unique_ptr<FakeIceTransportInternal> ice)
: DtlsTransportInternal(ice->network_thread()),
owned_ice_transport_(std::move(ice)),
transport_name_(owned_ice_transport_->transport_name()),
component_(owned_ice_transport_->component()),
dtls_fingerprint_("", std::span<const uint8_t>()) {
ice_transport_ = owned_ice_transport_.get();
ice_transport_->RegisterReceivedPacketCallback(
this, [&](PacketTransportInternal* transport, const ReceivedIpPacket& packet) {
OnIceTransportReadPacket(transport, packet);
});
ice_transport_->SubscribeNetworkRouteChanged(
this, [this](std::optional<NetworkRoute> network_route) {
OnNetworkRouteChanged(network_route);
});
}
// If this constructor is called, a new fake ICE transport will be created, // and this FakeDtlsTransport will take the ownership.
FakeDtlsTransport(const std::string& name, int component)
: FakeDtlsTransport(
std::make_unique<FakeIceTransportInternal>(name, component)) {}
FakeDtlsTransport(const std::string& name, int component,
Thread* network_thread)
: FakeDtlsTransport(
std::make_unique<FakeIceTransportInternal>(name,
component,
network_thread)) {}
// If async, will send packets by "Post"-ing to message queue instead of // synchronously "Send"-ing. void SetAsync(bool async) { ice_transport_->SetAsync(async); } void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(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) {
ice_transport_->SetWritable(writable);
set_writable(writable);
} void SetReceiving(bool receiving) {
ice_transport_->SetReceiving(receiving);
set_receiving(receiving);
} void SetDtlsState(DtlsTransportState state) {
dtls_state_ = state;
SendDtlsState(this, dtls_state_);
}
// Simulates the two DTLS transports connecting to each other. // If `asymmetric` is true this method only affects this FakeDtlsTransport. // If false, it affects `dest` as well. void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) { if (dest == dest_) { return;
}
RTC_DCHECK(!dest || !dest_)
<< "Changing fake destination from one to another is not supported."; if (dest && !dest_) { // This simulates the DTLS handshake.
dest_ = dest; if (local_cert_ && dest_->local_cert_) {
do_dtls_ = true;
RTC_LOG(LS_INFO) << "FakeDtlsTransport is doing DTLS";
} else {
do_dtls_ = false;
RTC_LOG(LS_INFO) << "FakeDtlsTransport is not doing DTLS";
} // If the `dtls_role_` is unset, set it to SSL_CLIENT by default. if (!dtls_role_) {
dtls_role_ = std::move(SSL_CLIENT);
}
SetDtlsState(DtlsTransportState::kConnected); // Now mark as writable. This triggers callbacks that might check the // dtls state and/or role, so do this after setting that state.
SetWritable(true); if (!asymmetric) {
dest->SetDestination(this, true);
}
ice_transport_->SetDestination(
static_cast<FakeIceTransportInternal*>(dest->ice_transport()),
asymmetric);
} else { // Simulates loss of connectivity, by asymmetrically forgetting dest_.
dest_ = nullptr;
SetWritable(false);
ice_transport_->SetDestination(nullptr, asymmetric);
}
}
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.