void AddInternalSocket(const 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 == PROTO_UDP) {
std::unique_ptr<AsyncUDPSocket> socket =
AsyncUDPSocket::Create(env_, int_addr, *socket_factory_);
socket->SetOption(Socket::OPT_RECV_ECN, 1);
server_.AddInternalSocket(std::move(socket), proto);
} elseif (proto == PROTO_TCP || proto == PROTO_TLS) { // For TCP we need to create a server socket which can listen for incoming // new connections.
std::unique_ptr<Socket> socket =
socket_factory_->Create(AF_INET, SOCK_STREAM);
socket->Bind(int_addr);
socket->Listen(5); if (proto == 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<SSLAdapterFactory> ssl_adapter_factory =
SSLAdapterFactory::Create();
ssl_adapter_factory->SetRole(SSL_SERVER);
ssl_adapter_factory->SetIdentity(
SSLIdentity::Create(common_name, KeyParams()));
ssl_adapter_factory->SetIgnoreBadCert(ignore_bad_cert);
server_.AddInternalServerSocket(std::move(socket), proto,
std::move(ssl_adapter_factory));
} else {
server_.AddInternalServerSocket(std::move(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 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. bool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) override {
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.