| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // For testing only. | 126 // For testing only. |
| 127 rtc::AsyncInvoker* invoker() { return &invoker_; } | 127 rtc::AsyncInvoker* invoker() { return &invoker_; } |
| 128 | 128 |
| 129 // Signal with resolved server address. | 129 // Signal with resolved server address. |
| 130 // Parameters are port, server address and resolved server address. | 130 // Parameters are port, server address and resolved server address. |
| 131 // This signal will be sent only if server address is resolved successfully. | 131 // This signal will be sent only if server address is resolved successfully. |
| 132 sigslot::signal3<TurnPort*, | 132 sigslot::signal3<TurnPort*, |
| 133 const rtc::SocketAddress&, | 133 const rtc::SocketAddress&, |
| 134 const rtc::SocketAddress&> SignalResolvedServerAddress; | 134 const rtc::SocketAddress&> SignalResolvedServerAddress; |
| 135 | 135 |
| 136 // All public methods/signals below are for testing only. |
| 137 sigslot::signal2<TurnPort*, int> SignalTurnRefreshResult; |
| 136 sigslot::signal3<TurnPort*, const rtc::SocketAddress&, int> | 138 sigslot::signal3<TurnPort*, const rtc::SocketAddress&, int> |
| 137 SignalCreatePermissionResult; | 139 SignalCreatePermissionResult; |
| 138 // For testing only. | |
| 139 void FlushRequests() { request_manager_.Flush(); } | 140 void FlushRequests() { request_manager_.Flush(); } |
| 141 void set_credentials(RelayCredentials& credentials) { |
| 142 credentials_ = credentials; |
| 143 } |
| 144 // Finds the turn entry with |address| and sets its channel id. |
| 145 // Returns true if the entry is found. |
| 146 bool SetEntryChannelId(const rtc::SocketAddress& address, int channel_id); |
| 140 | 147 |
| 141 protected: | 148 protected: |
| 142 TurnPort(rtc::Thread* thread, | 149 TurnPort(rtc::Thread* thread, |
| 143 rtc::PacketSocketFactory* factory, | 150 rtc::PacketSocketFactory* factory, |
| 144 rtc::Network* network, | 151 rtc::Network* network, |
| 145 rtc::AsyncPacketSocket* socket, | 152 rtc::AsyncPacketSocket* socket, |
| 146 const std::string& username, | 153 const std::string& username, |
| 147 const std::string& password, | 154 const std::string& password, |
| 148 const ProtocolAddress& server_address, | 155 const ProtocolAddress& server_address, |
| 149 const RelayCredentials& credentials, | 156 const RelayCredentials& credentials, |
| 150 int server_priority, | 157 int server_priority, |
| 151 const std::string& origin); | 158 const std::string& origin); |
| 152 | 159 |
| 153 TurnPort(rtc::Thread* thread, | 160 TurnPort(rtc::Thread* thread, |
| 154 rtc::PacketSocketFactory* factory, | 161 rtc::PacketSocketFactory* factory, |
| 155 rtc::Network* network, | 162 rtc::Network* network, |
| 156 const rtc::IPAddress& ip, | 163 const rtc::IPAddress& ip, |
| 157 uint16_t min_port, | 164 uint16_t min_port, |
| 158 uint16_t max_port, | 165 uint16_t max_port, |
| 159 const std::string& username, | 166 const std::string& username, |
| 160 const std::string& password, | 167 const std::string& password, |
| 161 const ProtocolAddress& server_address, | 168 const ProtocolAddress& server_address, |
| 162 const RelayCredentials& credentials, | 169 const RelayCredentials& credentials, |
| 163 int server_priority, | 170 int server_priority, |
| 164 const std::string& origin); | 171 const std::string& origin); |
| 165 | 172 |
| 166 private: | 173 private: |
| 167 enum { | 174 enum { |
| 168 MSG_ERROR = MSG_FIRST_AVAILABLE, | 175 MSG_ALLOCATE_ERROR = MSG_FIRST_AVAILABLE, |
| 169 MSG_ALLOCATE_MISMATCH, | 176 MSG_ALLOCATE_MISMATCH, |
| 170 MSG_TRY_ALTERNATE_SERVER | 177 MSG_TRY_ALTERNATE_SERVER |
| 171 }; | 178 }; |
| 172 | 179 |
| 173 typedef std::list<TurnEntry*> EntryList; | 180 typedef std::list<TurnEntry*> EntryList; |
| 174 typedef std::map<rtc::Socket::Option, int> SocketOptionsMap; | 181 typedef std::map<rtc::Socket::Option, int> SocketOptionsMap; |
| 175 typedef std::set<rtc::SocketAddress> AttemptedServerSet; | 182 typedef std::set<rtc::SocketAddress> AttemptedServerSet; |
| 176 | 183 |
| 177 virtual void OnMessage(rtc::Message* pmsg); | 184 virtual void OnMessage(rtc::Message* pmsg); |
| 178 | 185 |
| 179 bool CreateTurnClientSocket(); | 186 bool CreateTurnClientSocket(); |
| 180 | 187 |
| 181 void set_nonce(const std::string& nonce) { nonce_ = nonce; } | 188 void set_nonce(const std::string& nonce) { nonce_ = nonce; } |
| 182 void set_realm(const std::string& realm) { | 189 void set_realm(const std::string& realm) { |
| 183 if (realm != realm_) { | 190 if (realm != realm_) { |
| 184 realm_ = realm; | 191 realm_ = realm; |
| 185 UpdateHash(); | 192 UpdateHash(); |
| 186 } | 193 } |
| 187 } | 194 } |
| 188 | 195 |
| 196 // Shuts down the turn port, usually because of some fatal errors. |
| 197 void Close(); |
| 198 void OnTurnRefreshError() { Close(); } |
| 189 bool SetAlternateServer(const rtc::SocketAddress& address); | 199 bool SetAlternateServer(const rtc::SocketAddress& address); |
| 190 void ResolveTurnAddress(const rtc::SocketAddress& address); | 200 void ResolveTurnAddress(const rtc::SocketAddress& address); |
| 191 void OnResolveResult(rtc::AsyncResolverInterface* resolver); | 201 void OnResolveResult(rtc::AsyncResolverInterface* resolver); |
| 192 | 202 |
| 193 void AddRequestAuthInfo(StunMessage* msg); | 203 void AddRequestAuthInfo(StunMessage* msg); |
| 194 void OnSendStunPacket(const void* data, size_t size, StunRequest* request); | 204 void OnSendStunPacket(const void* data, size_t size, StunRequest* request); |
| 195 // Stun address from allocate success response. | 205 // Stun address from allocate success response. |
| 196 // Currently used only for testing. | 206 // Currently used only for testing. |
| 197 void OnStunAddress(const rtc::SocketAddress& address); | 207 void OnStunAddress(const rtc::SocketAddress& address); |
| 198 void OnAllocateSuccess(const rtc::SocketAddress& address, | 208 void OnAllocateSuccess(const rtc::SocketAddress& address, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 221 bool EntryExists(TurnEntry* e); | 231 bool EntryExists(TurnEntry* e); |
| 222 void CreateOrRefreshEntry(const rtc::SocketAddress& address); | 232 void CreateOrRefreshEntry(const rtc::SocketAddress& address); |
| 223 void DestroyEntry(TurnEntry* entry); | 233 void DestroyEntry(TurnEntry* entry); |
| 224 // Destroys the entry only if |timestamp| matches the destruction timestamp | 234 // Destroys the entry only if |timestamp| matches the destruction timestamp |
| 225 // in |entry|. | 235 // in |entry|. |
| 226 void DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp); | 236 void DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp); |
| 227 void ScheduleEntryDestruction(TurnEntry* entry); | 237 void ScheduleEntryDestruction(TurnEntry* entry); |
| 228 void CancelEntryDestruction(TurnEntry* entry); | 238 void CancelEntryDestruction(TurnEntry* entry); |
| 229 void OnConnectionDestroyed(Connection* conn); | 239 void OnConnectionDestroyed(Connection* conn); |
| 230 | 240 |
| 241 // Destroys the connection with remote address |address|. Returns true if |
| 242 // a connection is found and destroyed. |
| 243 bool DestroyConnection(const rtc::SocketAddress& address); |
| 244 |
| 231 ProtocolAddress server_address_; | 245 ProtocolAddress server_address_; |
| 232 RelayCredentials credentials_; | 246 RelayCredentials credentials_; |
| 233 AttemptedServerSet attempted_server_addresses_; | 247 AttemptedServerSet attempted_server_addresses_; |
| 234 | 248 |
| 235 rtc::AsyncPacketSocket* socket_; | 249 rtc::AsyncPacketSocket* socket_; |
| 236 SocketOptionsMap socket_options_; | 250 SocketOptionsMap socket_options_; |
| 237 rtc::AsyncResolverInterface* resolver_; | 251 rtc::AsyncResolverInterface* resolver_; |
| 238 int error_; | 252 int error_; |
| 239 | 253 |
| 240 StunRequestManager request_manager_; | 254 StunRequestManager request_manager_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 258 friend class TurnEntry; | 272 friend class TurnEntry; |
| 259 friend class TurnAllocateRequest; | 273 friend class TurnAllocateRequest; |
| 260 friend class TurnRefreshRequest; | 274 friend class TurnRefreshRequest; |
| 261 friend class TurnCreatePermissionRequest; | 275 friend class TurnCreatePermissionRequest; |
| 262 friend class TurnChannelBindRequest; | 276 friend class TurnChannelBindRequest; |
| 263 }; | 277 }; |
| 264 | 278 |
| 265 } // namespace cricket | 279 } // namespace cricket |
| 266 | 280 |
| 267 #endif // WEBRTC_P2P_BASE_TURNPORT_H_ | 281 #endif // WEBRTC_P2P_BASE_TURNPORT_H_ |
| OLD | NEW |