| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void AddInternalSocket(rtc::AsyncPacketSocket* socket, | 192 void AddInternalSocket(rtc::AsyncPacketSocket* socket, |
| 193 ProtocolType proto); | 193 ProtocolType proto); |
| 194 // Starts listening for the connections on this socket. When someone tries | 194 // Starts listening for the connections on this socket. When someone tries |
| 195 // to connect, the connection will be accepted and a new internal socket | 195 // to connect, the connection will be accepted and a new internal socket |
| 196 // will be added. | 196 // will be added. |
| 197 void AddInternalServerSocket(rtc::AsyncSocket* socket, | 197 void AddInternalServerSocket(rtc::AsyncSocket* socket, |
| 198 ProtocolType proto); | 198 ProtocolType proto); |
| 199 // Specifies the factory to use for creating external sockets. | 199 // Specifies the factory to use for creating external sockets. |
| 200 void SetExternalSocketFactory(rtc::PacketSocketFactory* factory, | 200 void SetExternalSocketFactory(rtc::PacketSocketFactory* factory, |
| 201 const rtc::SocketAddress& address); | 201 const rtc::SocketAddress& address); |
| 202 // For testing only. |
| 203 std::string SetTimestampForNextNonce(uint32_t timestamp) { |
| 204 ts_for_next_nonce_ = timestamp; |
| 205 return GenerateNonce(timestamp); |
| 206 } |
| 202 | 207 |
| 203 private: | 208 private: |
| 209 std::string GenerateNonce(uint32_t now) const; |
| 204 void OnInternalPacket(rtc::AsyncPacketSocket* socket, const char* data, | 210 void OnInternalPacket(rtc::AsyncPacketSocket* socket, const char* data, |
| 205 size_t size, const rtc::SocketAddress& address, | 211 size_t size, const rtc::SocketAddress& address, |
| 206 const rtc::PacketTime& packet_time); | 212 const rtc::PacketTime& packet_time); |
| 207 | 213 |
| 208 void OnNewInternalConnection(rtc::AsyncSocket* socket); | 214 void OnNewInternalConnection(rtc::AsyncSocket* socket); |
| 209 | 215 |
| 210 // Accept connections on this server socket. | 216 // Accept connections on this server socket. |
| 211 void AcceptConnection(rtc::AsyncSocket* server_socket); | 217 void AcceptConnection(rtc::AsyncSocket* server_socket); |
| 212 void OnInternalSocketClose(rtc::AsyncPacketSocket* socket, int err); | 218 void OnInternalSocketClose(rtc::AsyncPacketSocket* socket, int err); |
| 213 | 219 |
| 214 void HandleStunMessage( | 220 void HandleStunMessage( |
| 215 TurnServerConnection* conn, const char* data, size_t size); | 221 TurnServerConnection* conn, const char* data, size_t size); |
| 216 void HandleBindingRequest(TurnServerConnection* conn, const StunMessage* msg); | 222 void HandleBindingRequest(TurnServerConnection* conn, const StunMessage* msg); |
| 217 void HandleAllocateRequest(TurnServerConnection* conn, const TurnMessage* msg, | 223 void HandleAllocateRequest(TurnServerConnection* conn, const TurnMessage* msg, |
| 218 const std::string& key); | 224 const std::string& key); |
| 219 | 225 |
| 220 bool GetKey(const StunMessage* msg, std::string* key); | 226 bool GetKey(const StunMessage* msg, std::string* key); |
| 221 bool CheckAuthorization(TurnServerConnection* conn, const StunMessage* msg, | 227 bool CheckAuthorization(TurnServerConnection* conn, const StunMessage* msg, |
| 222 const char* data, size_t size, | 228 const char* data, size_t size, |
| 223 const std::string& key); | 229 const std::string& key); |
| 224 std::string GenerateNonce() const; | |
| 225 bool ValidateNonce(const std::string& nonce) const; | 230 bool ValidateNonce(const std::string& nonce) const; |
| 226 | 231 |
| 227 TurnServerAllocation* FindAllocation(TurnServerConnection* conn); | 232 TurnServerAllocation* FindAllocation(TurnServerConnection* conn); |
| 228 TurnServerAllocation* CreateAllocation( | 233 TurnServerAllocation* CreateAllocation( |
| 229 TurnServerConnection* conn, int proto, const std::string& key); | 234 TurnServerConnection* conn, int proto, const std::string& key); |
| 230 | 235 |
| 231 void SendErrorResponse(TurnServerConnection* conn, const StunMessage* req, | 236 void SendErrorResponse(TurnServerConnection* conn, const StunMessage* req, |
| 232 int code, const std::string& reason); | 237 int code, const std::string& reason); |
| 233 | 238 |
| 234 void SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn, | 239 void SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 263 bool reject_private_addresses_ = false; | 268 bool reject_private_addresses_ = false; |
| 264 | 269 |
| 265 InternalSocketMap server_sockets_; | 270 InternalSocketMap server_sockets_; |
| 266 ServerSocketMap server_listen_sockets_; | 271 ServerSocketMap server_listen_sockets_; |
| 267 rtc::scoped_ptr<rtc::PacketSocketFactory> | 272 rtc::scoped_ptr<rtc::PacketSocketFactory> |
| 268 external_socket_factory_; | 273 external_socket_factory_; |
| 269 rtc::SocketAddress external_addr_; | 274 rtc::SocketAddress external_addr_; |
| 270 | 275 |
| 271 AllocationMap allocations_; | 276 AllocationMap allocations_; |
| 272 | 277 |
| 278 // For testing only. If this is non-zero, the next NONCE will be generated |
| 279 // from this value, and it will be reset to 0 after generating the NONCE. |
| 280 uint32_t ts_for_next_nonce_ = 0; |
| 281 |
| 273 friend class TurnServerAllocation; | 282 friend class TurnServerAllocation; |
| 274 }; | 283 }; |
| 275 | 284 |
| 276 } // namespace cricket | 285 } // namespace cricket |
| 277 | 286 |
| 278 #endif // WEBRTC_P2P_BASE_TURNSERVER_H_ | 287 #endif // WEBRTC_P2P_BASE_TURNSERVER_H_ |
| OLD | NEW |