/* * Copyright 2012 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.
*/
void AddInternalSocket(const rtc::SocketAddress& int_addr,
ProtocolType proto, bool ignore_bad_cert = true,
absl::string_view common_name = "test turn server") {
RTC_DCHECK(thread_checker_.IsCurrent()); if (proto == cricket::PROTO_UDP) {
server_.AddInternalSocket(
rtc::AsyncUDPSocket::Create(socket_factory_, int_addr), proto);
} elseif (proto == cricket::PROTO_TCP || proto == cricket::PROTO_TLS) { // For TCP we need to create a server socket which can listen for incoming // new connections.
rtc::Socket* socket = socket_factory_->CreateSocket(AF_INET, SOCK_STREAM);
socket->Bind(int_addr);
socket->Listen(5); if (proto == cricket::PROTO_TLS) { // For TLS, wrap the TCP socket with an SSL adapter. The adapter must // be configured with a self-signed certificate for testing. // Additionally, the client will not present a valid certificate, so we // must not fail when checking the peer's identity.
std::unique_ptr<rtc::SSLAdapterFactory> ssl_adapter_factory =
rtc::SSLAdapterFactory::Create();
ssl_adapter_factory->SetRole(rtc::SSL_SERVER);
ssl_adapter_factory->SetIdentity(
rtc::SSLIdentity::Create(common_name, rtc::KeyParams()));
ssl_adapter_factory->SetIgnoreBadCert(ignore_bad_cert);
server_.AddInternalServerSocket(socket, proto,
std::move(ssl_adapter_factory));
} else {
server_.AddInternalServerSocket(socket, proto);
}
} else {
RTC_DCHECK_NOTREACHED() << "Unknown protocol type: " << proto;
}
}
// Finds the first allocation in the server allocation map with a source // ip and port matching the socket address provided.
TurnServerAllocation* FindAllocation(const rtc::SocketAddress& src) {
RTC_DCHECK(thread_checker_.IsCurrent()); const TurnServer::AllocationMap& map = server_.allocations(); for (TurnServer::AllocationMap::const_iterator it = map.begin();
it != map.end(); ++it) { if (src == it->first.src()) { return it->second.get();
}
} return NULL;
}
private: // For this test server, succeed if the password is the same as the username. // Obviously, do not use this in a production environment. virtualbool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) {
RTC_DCHECK(thread_checker_.IsCurrent()); return ComputeStunCredentialHash(std::string(username), std::string(realm),
std::string(username), key);
}
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.