blob: e951d089af252f684022963a4d820625cc55c0ba [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef P2P_BASE_TURN_SERVER_H_
12#define P2P_BASE_TURN_SERVER_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
14#include <list>
15#include <map>
kwiberg3ec46792016-04-27 07:22:53 -070016#include <memory>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000017#include <set>
18#include <string>
Steve Anton6c38cc72017-11-29 10:25:58 -080019#include <utility>
deadbeef824f5862016-08-24 15:06:53 -070020#include <vector>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000021
Ali Tofighde2ac5a2022-06-30 11:58:26 +020022#include "absl/strings/string_view.h"
Artem Titovd15a5752021-02-10 14:31:24 +010023#include "api/sequence_checker.h"
Danil Chapovalove51918f2022-08-16 19:41:38 +020024#include "api/task_queue/pending_task_safety_flag.h"
25#include "api/task_queue/task_queue_base.h"
26#include "api/units/time_delta.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "p2p/base/port_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "rtc_base/async_packet_socket.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "rtc_base/socket_address.h"
Niels Möllerac9a2882021-10-20 15:25:09 +020030#include "rtc_base/ssl_adapter.h"
Artem Titove41c4332018-07-25 15:04:28 +020031#include "rtc_base/third_party/sigslot/sigslot.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000032
33namespace rtc {
jbauchf1f87202016-03-30 06:43:37 -070034class ByteBufferWriter;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035class PacketSocketFactory;
Jonas Olssona4d87372019-07-05 19:08:33 +020036} // namespace rtc
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000037
38namespace cricket {
39
40class StunMessage;
41class TurnMessage;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000042class TurnServer;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043
44// The default server port for TURN, as specified in RFC5766.
45const int TURN_SERVER_PORT = 3478;
46
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000047// Encapsulates the client's connection to the server.
48class TurnServerConnection {
49 public:
50 TurnServerConnection() : proto_(PROTO_UDP), socket_(NULL) {}
51 TurnServerConnection(const rtc::SocketAddress& src,
52 ProtocolType proto,
53 rtc::AsyncPacketSocket* socket);
54 const rtc::SocketAddress& src() const { return src_; }
55 rtc::AsyncPacketSocket* socket() { return socket_; }
56 bool operator==(const TurnServerConnection& t) const;
57 bool operator<(const TurnServerConnection& t) const;
58 std::string ToString() const;
59
60 private:
61 rtc::SocketAddress src_;
62 rtc::SocketAddress dst_;
63 cricket::ProtocolType proto_;
64 rtc::AsyncPacketSocket* socket_;
65};
66
67// Encapsulates a TURN allocation.
68// The object is created when an allocation request is received, and then
69// handles TURN messages (via HandleTurnMessage) and channel data messages
70// (via HandleChannelData) for this allocation when received by the server.
Danil Chapovalove51918f2022-08-16 19:41:38 +020071// The object informs the server when its lifetime timer expires.
72class TurnServerAllocation : public sigslot::has_slots<> {
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000073 public:
74 TurnServerAllocation(TurnServer* server_,
Danil Chapovalove51918f2022-08-16 19:41:38 +020075 webrtc::TaskQueueBase* thread,
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000076 const TurnServerConnection& conn,
77 rtc::AsyncPacketSocket* server_socket,
Ali Tofighde2ac5a2022-06-30 11:58:26 +020078 absl::string_view key);
Steve Antonf2737d22017-10-31 16:27:34 -070079 ~TurnServerAllocation() override;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000080
81 TurnServerConnection* conn() { return &conn_; }
82 const std::string& key() const { return key_; }
83 const std::string& transaction_id() const { return transaction_id_; }
84 const std::string& username() const { return username_; }
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000085 const std::string& last_nonce() const { return last_nonce_; }
Tommie83500e2022-06-03 14:28:59 +020086 void set_last_nonce(absl::string_view nonce) {
87 last_nonce_ = std::string(nonce);
88 }
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000089
90 std::string ToString() const;
91
92 void HandleTurnMessage(const TurnMessage* msg);
93 void HandleChannelData(const char* data, size_t size);
94
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +000095 private:
Danil Chapovalove51918f2022-08-16 19:41:38 +020096 struct Channel {
97 webrtc::ScopedTaskSafety pending_delete;
98 int id;
99 rtc::SocketAddress peer;
100 };
101 struct Permission {
102 webrtc::ScopedTaskSafety pending_delete;
103 rtc::IPAddress peer;
104 };
105 using PermissionList = std::list<Permission>;
106 using ChannelList = std::list<Channel>;
107
108 void PostDeleteSelf(webrtc::TimeDelta delay);
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000109
110 void HandleAllocateRequest(const TurnMessage* msg);
111 void HandleRefreshRequest(const TurnMessage* msg);
112 void HandleSendIndication(const TurnMessage* msg);
113 void HandleCreatePermissionRequest(const TurnMessage* msg);
114 void HandleChannelBindRequest(const TurnMessage* msg);
115
116 void OnExternalPacket(rtc::AsyncPacketSocket* socket,
Niels Möllere6933812018-11-05 13:01:41 +0100117 const char* data,
118 size_t size,
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000119 const rtc::SocketAddress& addr,
Niels Möllere6933812018-11-05 13:01:41 +0100120 const int64_t& packet_time_us);
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000121
Danil Chapovalove51918f2022-08-16 19:41:38 +0200122 static webrtc::TimeDelta ComputeLifetime(const TurnMessage& msg);
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000123 bool HasPermission(const rtc::IPAddress& addr);
124 void AddPermission(const rtc::IPAddress& addr);
Danil Chapovalove51918f2022-08-16 19:41:38 +0200125 PermissionList::iterator FindPermission(const rtc::IPAddress& addr);
126 ChannelList::iterator FindChannel(int channel_id);
127 ChannelList::iterator FindChannel(const rtc::SocketAddress& addr);
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000128
129 void SendResponse(TurnMessage* msg);
130 void SendBadRequestResponse(const TurnMessage* req);
Jonas Olssona4d87372019-07-05 19:08:33 +0200131 void SendErrorResponse(const TurnMessage* req,
132 int code,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200133 absl::string_view reason);
Jonas Olssona4d87372019-07-05 19:08:33 +0200134 void SendExternal(const void* data,
135 size_t size,
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000136 const rtc::SocketAddress& peer);
137
Niels Möller76b51e22021-03-18 15:44:24 +0100138 TurnServer* const server_;
Danil Chapovalove51918f2022-08-16 19:41:38 +0200139 webrtc::TaskQueueBase* const thread_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000140 TurnServerConnection conn_;
kwiberg3ec46792016-04-27 07:22:53 -0700141 std::unique_ptr<rtc::AsyncPacketSocket> external_socket_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000142 std::string key_;
143 std::string transaction_id_;
144 std::string username_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000145 std::string last_nonce_;
146 PermissionList perms_;
147 ChannelList channels_;
Danil Chapovalove51918f2022-08-16 19:41:38 +0200148 webrtc::ScopedTaskSafety safety_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000149};
150
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000151// An interface through which the MD5 credential hash can be retrieved.
152class TurnAuthInterface {
153 public:
154 // Gets HA1 for the specified user and realm.
155 // HA1 = MD5(A1) = MD5(username:realm:password).
156 // Return true if the given username and realm are valid, or false if not.
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200157 virtual bool GetKey(absl::string_view username,
158 absl::string_view realm,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000159 std::string* key) = 0;
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200160 virtual ~TurnAuthInterface() = default;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000161};
162
163// An interface enables Turn Server to control redirection behavior.
164class TurnRedirectInterface {
165 public:
166 virtual bool ShouldRedirect(const rtc::SocketAddress& address,
167 rtc::SocketAddress* out) = 0;
168 virtual ~TurnRedirectInterface() {}
169};
170
Jonas Orelandbdcee282017-10-10 14:01:40 +0200171class StunMessageObserver {
172 public:
173 virtual void ReceivedMessage(const TurnMessage* msg) = 0;
174 virtual void ReceivedChannelData(const char* data, size_t size) = 0;
175 virtual ~StunMessageObserver() {}
176};
177
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000178// The core TURN server class. Give it a socket to listen on via
179// AddInternalServerSocket, and a factory to create external sockets via
180// SetExternalSocketFactory, and it's ready to go.
181// Not yet wired up: TCP support.
182class TurnServer : public sigslot::has_slots<> {
183 public:
deadbeef97943662016-07-12 11:04:50 -0700184 typedef std::map<TurnServerConnection, std::unique_ptr<TurnServerAllocation>>
185 AllocationMap;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000186
Danil Chapovalove51918f2022-08-16 19:41:38 +0200187 explicit TurnServer(webrtc::TaskQueueBase* thread);
Steve Antonf2737d22017-10-31 16:27:34 -0700188 ~TurnServer() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000189
190 // Gets/sets the realm value to use for the server.
Seth Hampsonaed71642018-06-11 07:41:32 -0700191 const std::string& realm() const {
Niels Möller76b51e22021-03-18 15:44:24 +0100192 RTC_DCHECK_RUN_ON(thread_);
Seth Hampsonaed71642018-06-11 07:41:32 -0700193 return realm_;
194 }
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200195 void set_realm(absl::string_view realm) {
Niels Möller76b51e22021-03-18 15:44:24 +0100196 RTC_DCHECK_RUN_ON(thread_);
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200197 realm_ = std::string(realm);
Seth Hampsonaed71642018-06-11 07:41:32 -0700198 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000199
200 // Gets/sets the value for the SOFTWARE attribute for TURN messages.
Seth Hampsonaed71642018-06-11 07:41:32 -0700201 const std::string& software() const {
Niels Möller76b51e22021-03-18 15:44:24 +0100202 RTC_DCHECK_RUN_ON(thread_);
Seth Hampsonaed71642018-06-11 07:41:32 -0700203 return software_;
204 }
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200205 void set_software(absl::string_view software) {
Niels Möller76b51e22021-03-18 15:44:24 +0100206 RTC_DCHECK_RUN_ON(thread_);
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200207 software_ = std::string(software);
Seth Hampsonaed71642018-06-11 07:41:32 -0700208 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000209
Seth Hampsonaed71642018-06-11 07:41:32 -0700210 const AllocationMap& allocations() const {
Niels Möller76b51e22021-03-18 15:44:24 +0100211 RTC_DCHECK_RUN_ON(thread_);
Seth Hampsonaed71642018-06-11 07:41:32 -0700212 return allocations_;
213 }
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000214
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000215 // Sets the authentication callback; does not take ownership.
Seth Hampsonaed71642018-06-11 07:41:32 -0700216 void set_auth_hook(TurnAuthInterface* auth_hook) {
Niels Möller76b51e22021-03-18 15:44:24 +0100217 RTC_DCHECK_RUN_ON(thread_);
Seth Hampsonaed71642018-06-11 07:41:32 -0700218 auth_hook_ = auth_hook;
219 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000220
221 void set_redirect_hook(TurnRedirectInterface* redirect_hook) {
Niels Möller76b51e22021-03-18 15:44:24 +0100222 RTC_DCHECK_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000223 redirect_hook_ = redirect_hook;
224 }
225
Seth Hampsonaed71642018-06-11 07:41:32 -0700226 void set_enable_otu_nonce(bool enable) {
Niels Möller76b51e22021-03-18 15:44:24 +0100227 RTC_DCHECK_RUN_ON(thread_);
Seth Hampsonaed71642018-06-11 07:41:32 -0700228 enable_otu_nonce_ = enable;
229 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000230
deadbeef376e1232015-11-25 09:00:08 -0800231 // If set to true, reject CreatePermission requests to RFC1918 addresses.
232 void set_reject_private_addresses(bool filter) {
Niels Möller76b51e22021-03-18 15:44:24 +0100233 RTC_DCHECK_RUN_ON(thread_);
deadbeef376e1232015-11-25 09:00:08 -0800234 reject_private_addresses_ = filter;
235 }
236
Taylor Brandstetteref184702016-06-23 17:35:47 -0700237 void set_enable_permission_checks(bool enable) {
Niels Möller76b51e22021-03-18 15:44:24 +0100238 RTC_DCHECK_RUN_ON(thread_);
Taylor Brandstetteref184702016-06-23 17:35:47 -0700239 enable_permission_checks_ = enable;
240 }
241
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000242 // Starts listening for packets from internal clients.
Jonas Olssona4d87372019-07-05 19:08:33 +0200243 void AddInternalSocket(rtc::AsyncPacketSocket* socket, ProtocolType proto);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000244 // Starts listening for the connections on this socket. When someone tries
245 // to connect, the connection will be accepted and a new internal socket
246 // will be added.
Niels Möllerac9a2882021-10-20 15:25:09 +0200247 void AddInternalServerSocket(
248 rtc::Socket* socket,
249 ProtocolType proto,
250 std::unique_ptr<rtc::SSLAdapterFactory> ssl_adapter_factory = nullptr);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000251 // Specifies the factory to use for creating external sockets.
252 void SetExternalSocketFactory(rtc::PacketSocketFactory* factory,
253 const rtc::SocketAddress& address);
honghaizc463e202016-02-01 15:19:08 -0800254 // For testing only.
honghaiz34b11eb2016-03-16 08:55:44 -0700255 std::string SetTimestampForNextNonce(int64_t timestamp) {
Niels Möller76b51e22021-03-18 15:44:24 +0100256 RTC_DCHECK_RUN_ON(thread_);
honghaizc463e202016-02-01 15:19:08 -0800257 ts_for_next_nonce_ = timestamp;
258 return GenerateNonce(timestamp);
259 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000260
Jonas Olssona4d87372019-07-05 19:08:33 +0200261 void SetStunMessageObserver(std::unique_ptr<StunMessageObserver> observer) {
Niels Möller76b51e22021-03-18 15:44:24 +0100262 RTC_DCHECK_RUN_ON(thread_);
Jonas Orelandbdcee282017-10-10 14:01:40 +0200263 stun_message_observer_ = std::move(observer);
264 }
265
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000266 private:
Niels Möller76b51e22021-03-18 15:44:24 +0100267 // All private member functions and variables should have access restricted to
268 // thread_. But compile-time annotations are missing for members access from
269 // TurnServerAllocation (via friend declaration), and the On* methods, which
270 // are called via sigslot.
271 std::string GenerateNonce(int64_t now) const RTC_RUN_ON(thread_);
Niels Möllere6933812018-11-05 13:01:41 +0100272 void OnInternalPacket(rtc::AsyncPacketSocket* socket,
273 const char* data,
274 size_t size,
275 const rtc::SocketAddress& address,
276 const int64_t& packet_time_us);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000277
Niels Möllerd0b88792021-08-12 10:32:30 +0200278 void OnNewInternalConnection(rtc::Socket* socket);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000279
280 // Accept connections on this server socket.
Niels Möllerd0b88792021-08-12 10:32:30 +0200281 void AcceptConnection(rtc::Socket* server_socket) RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000282 void OnInternalSocketClose(rtc::AsyncPacketSocket* socket, int err);
283
Jonas Olssona4d87372019-07-05 19:08:33 +0200284 void HandleStunMessage(TurnServerConnection* conn,
285 const char* data,
Niels Möller76b51e22021-03-18 15:44:24 +0100286 size_t size) RTC_RUN_ON(thread_);
287 void HandleBindingRequest(TurnServerConnection* conn, const StunMessage* msg)
288 RTC_RUN_ON(thread_);
Jonas Olssona4d87372019-07-05 19:08:33 +0200289 void HandleAllocateRequest(TurnServerConnection* conn,
290 const TurnMessage* msg,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200291 absl::string_view key) RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000292
Niels Möller76b51e22021-03-18 15:44:24 +0100293 bool GetKey(const StunMessage* msg, std::string* key) RTC_RUN_ON(thread_);
Jonas Olssona4d87372019-07-05 19:08:33 +0200294 bool CheckAuthorization(TurnServerConnection* conn,
Harald Alvestrand07d83c82021-03-02 08:09:53 +0000295 StunMessage* msg,
Jonas Olssona4d87372019-07-05 19:08:33 +0200296 const char* data,
297 size_t size,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200298 absl::string_view key) RTC_RUN_ON(thread_);
Tommie83500e2022-06-03 14:28:59 +0200299 bool ValidateNonce(absl::string_view nonce) const RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000300
Niels Möller76b51e22021-03-18 15:44:24 +0100301 TurnServerAllocation* FindAllocation(TurnServerConnection* conn)
302 RTC_RUN_ON(thread_);
Jonas Olssona4d87372019-07-05 19:08:33 +0200303 TurnServerAllocation* CreateAllocation(TurnServerConnection* conn,
304 int proto,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200305 absl::string_view key)
Niels Möller76b51e22021-03-18 15:44:24 +0100306 RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000307
Jonas Olssona4d87372019-07-05 19:08:33 +0200308 void SendErrorResponse(TurnServerConnection* conn,
309 const StunMessage* req,
310 int code,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200311 absl::string_view reason);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000312
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000313 void SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000314 const StunMessage* req,
315 int code,
Ali Tofighde2ac5a2022-06-30 11:58:26 +0200316 absl::string_view reason)
Niels Möller76b51e22021-03-18 15:44:24 +0100317 RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000318
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000319 void SendErrorResponseWithAlternateServer(TurnServerConnection* conn,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000320 const StunMessage* req,
Niels Möller76b51e22021-03-18 15:44:24 +0100321 const rtc::SocketAddress& addr)
322 RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000323
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000324 void SendStun(TurnServerConnection* conn, StunMessage* msg);
jbauchf1f87202016-03-30 06:43:37 -0700325 void Send(TurnServerConnection* conn, const rtc::ByteBufferWriter& buf);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000326
Danil Chapovalove51918f2022-08-16 19:41:38 +0200327 void DestroyAllocation(TurnServerAllocation* allocation) RTC_RUN_ON(thread_);
Niels Möller76b51e22021-03-18 15:44:24 +0100328 void DestroyInternalSocket(rtc::AsyncPacketSocket* socket)
329 RTC_RUN_ON(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000330
Jonas Olssona4d87372019-07-05 19:08:33 +0200331 typedef std::map<rtc::AsyncPacketSocket*, ProtocolType> InternalSocketMap;
Niels Möllerac9a2882021-10-20 15:25:09 +0200332 struct ServerSocketInfo {
333 ProtocolType proto;
334 // If non-null, used to wrap accepted sockets.
335 std::unique_ptr<rtc::SSLAdapterFactory> ssl_adapter_factory;
336 };
337 typedef std::map<rtc::Socket*, ServerSocketInfo> ServerSocketMap;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000338
Danil Chapovalove51918f2022-08-16 19:41:38 +0200339 webrtc::TaskQueueBase* const thread_;
Niels Möller76b51e22021-03-18 15:44:24 +0100340 const std::string nonce_key_;
341 std::string realm_ RTC_GUARDED_BY(thread_);
342 std::string software_ RTC_GUARDED_BY(thread_);
343 TurnAuthInterface* auth_hook_ RTC_GUARDED_BY(thread_);
344 TurnRedirectInterface* redirect_hook_ RTC_GUARDED_BY(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000345 // otu - one-time-use. Server will respond with 438 if it's
346 // sees the same nonce in next transaction.
Niels Möller76b51e22021-03-18 15:44:24 +0100347 bool enable_otu_nonce_ RTC_GUARDED_BY(thread_);
deadbeef376e1232015-11-25 09:00:08 -0800348 bool reject_private_addresses_ = false;
Taylor Brandstetteref184702016-06-23 17:35:47 -0700349 // Check for permission when receiving an external packet.
350 bool enable_permission_checks_ = true;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000351
Niels Möller76b51e22021-03-18 15:44:24 +0100352 InternalSocketMap server_sockets_ RTC_GUARDED_BY(thread_);
353 ServerSocketMap server_listen_sockets_ RTC_GUARDED_BY(thread_);
Niels Möller76b51e22021-03-18 15:44:24 +0100354 std::unique_ptr<rtc::PacketSocketFactory> external_socket_factory_
355 RTC_GUARDED_BY(thread_);
356 rtc::SocketAddress external_addr_ RTC_GUARDED_BY(thread_);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000357
Niels Möller76b51e22021-03-18 15:44:24 +0100358 AllocationMap allocations_ RTC_GUARDED_BY(thread_);
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000359
honghaizc463e202016-02-01 15:19:08 -0800360 // For testing only. If this is non-zero, the next NONCE will be generated
361 // from this value, and it will be reset to 0 after generating the NONCE.
Niels Möller76b51e22021-03-18 15:44:24 +0100362 int64_t ts_for_next_nonce_ RTC_GUARDED_BY(thread_) = 0;
honghaizc463e202016-02-01 15:19:08 -0800363
Jonas Orelandbdcee282017-10-10 14:01:40 +0200364 // For testing only. Used to observe STUN messages received.
Niels Möller76b51e22021-03-18 15:44:24 +0100365 std::unique_ptr<StunMessageObserver> stun_message_observer_
366 RTC_GUARDED_BY(thread_);
Jonas Orelandbdcee282017-10-10 14:01:40 +0200367
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000368 friend class TurnServerAllocation;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000369};
370
371} // namespace cricket
372
Steve Anton10542f22019-01-11 09:11:00 -0800373#endif // P2P_BASE_TURN_SERVER_H_