/* * 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.
*/
// Encapsulates a TURN allocation. // The object is created when an allocation request is received, and then // handles TURN messages (via HandleTurnMessage) and channel data messages // (via HandleChannelData) for this allocation when received by the server. // The object informs the server when its lifetime timer expires. class TurnServerAllocation { public:
TurnServerAllocation(TurnServer* server_,
webrtc::TaskQueueBase* thread, const TurnServerConnection& conn,
rtc::AsyncPacketSocket* server_socket,
absl::string_view key); virtual ~TurnServerAllocation();
// An interface through which the MD5 credential hash can be retrieved. class TurnAuthInterface { public: // Gets HA1 for the specified user and realm. // HA1 = MD5(A1) = MD5(username:realm:password). // Return true if the given username and realm are valid, or false if not. virtualbool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) = 0; virtual ~TurnAuthInterface() = default;
};
// An interface enables Turn Server to control redirection behavior. class TurnRedirectInterface { public: virtualbool ShouldRedirect(const rtc::SocketAddress& address,
rtc::SocketAddress* out) = 0; virtual ~TurnRedirectInterface() {}
};
// The core TURN server class. Give it a socket to listen on via // AddInternalServerSocket, and a factory to create external sockets via // SetExternalSocketFactory, and it's ready to go. // Not yet wired up: TCP support. class TurnServer : public sigslot::has_slots<> { public: typedef std::map<TurnServerConnection, std::unique_ptr<TurnServerAllocation>>
AllocationMap;
// Gets/sets the realm value to use for the server. const std::string& realm() const {
RTC_DCHECK_RUN_ON(thread_); return realm_;
} void set_realm(absl::string_view realm) {
RTC_DCHECK_RUN_ON(thread_);
realm_ = std::string(realm);
}
// Gets/sets the value for the SOFTWARE attribute for TURN messages. const std::string& software() const {
RTC_DCHECK_RUN_ON(thread_); return software_;
} void set_software(absl::string_view software) {
RTC_DCHECK_RUN_ON(thread_);
software_ = std::string(software);
}
// Sets the authentication callback; does not take ownership. void set_auth_hook(TurnAuthInterface* auth_hook) {
RTC_DCHECK_RUN_ON(thread_);
auth_hook_ = auth_hook;
}
// If set to true, reject CreatePermission requests to RFC1918 addresses. void set_reject_private_addresses(bool filter) {
RTC_DCHECK_RUN_ON(thread_);
reject_private_addresses_ = filter;
}
// Starts listening for packets from internal clients. void AddInternalSocket(rtc::AsyncPacketSocket* socket, ProtocolType proto); // Starts listening for the connections on this socket. When someone tries // to connect, the connection will be accepted and a new internal socket // will be added. void AddInternalServerSocket(
rtc::Socket* socket,
ProtocolType proto,
std::unique_ptr<rtc::SSLAdapterFactory> ssl_adapter_factory = nullptr); // Specifies the factory to use for creating external sockets. void SetExternalSocketFactory(rtc::PacketSocketFactory* factory, const rtc::SocketAddress& address); // For testing only.
std::string SetTimestampForNextNonce(int64_t timestamp) {
RTC_DCHECK_RUN_ON(thread_);
ts_for_next_nonce_ = timestamp; return GenerateNonce(timestamp);
}
private: // All private member functions and variables should have access restricted to // thread_. But compile-time annotations are missing for members access from // TurnServerAllocation (via friend declaration).
// Accept connections on this server socket. void AcceptConnection(rtc::Socket* server_socket) RTC_RUN_ON(thread_); void OnInternalSocketClose(rtc::AsyncPacketSocket* socket, int err);
typedef std::map<rtc::AsyncPacketSocket*, ProtocolType> InternalSocketMap; struct ServerSocketInfo {
ProtocolType proto; // If non-null, used to wrap accepted sockets.
std::unique_ptr<rtc::SSLAdapterFactory> ssl_adapter_factory;
}; typedef std::map<rtc::Socket*, ServerSocketInfo> ServerSocketMap;
webrtc::TaskQueueBase* const thread_; const std::string nonce_key_;
std::string realm_ RTC_GUARDED_BY(thread_);
std::string software_ RTC_GUARDED_BY(thread_);
TurnAuthInterface* auth_hook_ RTC_GUARDED_BY(thread_);
TurnRedirectInterface* redirect_hook_ RTC_GUARDED_BY(thread_); // otu - one-time-use. Server will respond with 438 if it's // sees the same nonce in next transaction. bool enable_otu_nonce_ RTC_GUARDED_BY(thread_); bool reject_private_addresses_ = false; // Check for permission when receiving an external packet. bool enable_permission_checks_ = true;
// For testing only. If this is non-zero, the next NONCE will be generated // from this value, and it will be reset to 0 after generating the NONCE.
int64_t ts_for_next_nonce_ RTC_GUARDED_BY(thread_) = 0;
// For testing only. Used to observe STUN messages received.
std::unique_ptr<StunMessageObserver> stun_message_observer_
RTC_GUARDED_BY(thread_);
friendclass TurnServerAllocation;
};
} // namespace cricket
#endif// P2P_BASE_TURN_SERVER_H_
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
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.