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 // This signal is only for testing purpose. | 136 // All public methods/signals below are for testing only. |
| 137 sigslot::signal2<TurnPort*, int> SignalTurnRefreshResult; |
137 sigslot::signal3<TurnPort*, const rtc::SocketAddress&, int> | 138 sigslot::signal3<TurnPort*, const rtc::SocketAddress&, int> |
138 SignalCreatePermissionResult; | 139 SignalCreatePermissionResult; |
139 // For testing only. | |
140 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); |
141 | 147 |
142 protected: | 148 protected: |
143 TurnPort(rtc::Thread* thread, | 149 TurnPort(rtc::Thread* thread, |
144 rtc::PacketSocketFactory* factory, | 150 rtc::PacketSocketFactory* factory, |
145 rtc::Network* network, | 151 rtc::Network* network, |
146 rtc::AsyncPacketSocket* socket, | 152 rtc::AsyncPacketSocket* socket, |
147 const std::string& username, | 153 const std::string& username, |
148 const std::string& password, | 154 const std::string& password, |
149 const ProtocolAddress& server_address, | 155 const ProtocolAddress& server_address, |
150 const RelayCredentials& credentials, | 156 const RelayCredentials& credentials, |
151 int server_priority, | 157 int server_priority, |
152 const std::string& origin); | 158 const std::string& origin); |
153 | 159 |
154 TurnPort(rtc::Thread* thread, | 160 TurnPort(rtc::Thread* thread, |
155 rtc::PacketSocketFactory* factory, | 161 rtc::PacketSocketFactory* factory, |
156 rtc::Network* network, | 162 rtc::Network* network, |
157 const rtc::IPAddress& ip, | 163 const rtc::IPAddress& ip, |
158 uint16_t min_port, | 164 uint16_t min_port, |
159 uint16_t max_port, | 165 uint16_t max_port, |
160 const std::string& username, | 166 const std::string& username, |
161 const std::string& password, | 167 const std::string& password, |
162 const ProtocolAddress& server_address, | 168 const ProtocolAddress& server_address, |
163 const RelayCredentials& credentials, | 169 const RelayCredentials& credentials, |
164 int server_priority, | 170 int server_priority, |
165 const std::string& origin); | 171 const std::string& origin); |
166 | 172 |
167 private: | 173 private: |
168 enum { | 174 enum { |
169 MSG_ERROR = MSG_FIRST_AVAILABLE, | 175 MSG_ALLOCATE_ERROR = MSG_FIRST_AVAILABLE, |
170 MSG_ALLOCATE_MISMATCH, | 176 MSG_ALLOCATE_MISMATCH, |
171 MSG_TRY_ALTERNATE_SERVER | 177 MSG_TRY_ALTERNATE_SERVER |
172 }; | 178 }; |
173 | 179 |
174 typedef std::list<TurnEntry*> EntryList; | 180 typedef std::list<TurnEntry*> EntryList; |
175 typedef std::map<rtc::Socket::Option, int> SocketOptionsMap; | 181 typedef std::map<rtc::Socket::Option, int> SocketOptionsMap; |
176 typedef std::set<rtc::SocketAddress> AttemptedServerSet; | 182 typedef std::set<rtc::SocketAddress> AttemptedServerSet; |
177 | 183 |
178 virtual void OnMessage(rtc::Message* pmsg); | 184 virtual void OnMessage(rtc::Message* pmsg); |
179 | 185 |
180 bool CreateTurnClientSocket(); | 186 bool CreateTurnClientSocket(); |
181 | 187 |
182 void set_nonce(const std::string& nonce) { nonce_ = nonce; } | 188 void set_nonce(const std::string& nonce) { nonce_ = nonce; } |
183 void set_realm(const std::string& realm) { | 189 void set_realm(const std::string& realm) { |
184 if (realm != realm_) { | 190 if (realm != realm_) { |
185 realm_ = realm; | 191 realm_ = realm; |
186 UpdateHash(); | 192 UpdateHash(); |
187 } | 193 } |
188 } | 194 } |
189 | 195 |
| 196 void OnTurnRefreshError(); |
190 bool SetAlternateServer(const rtc::SocketAddress& address); | 197 bool SetAlternateServer(const rtc::SocketAddress& address); |
191 void ResolveTurnAddress(const rtc::SocketAddress& address); | 198 void ResolveTurnAddress(const rtc::SocketAddress& address); |
192 void OnResolveResult(rtc::AsyncResolverInterface* resolver); | 199 void OnResolveResult(rtc::AsyncResolverInterface* resolver); |
193 | 200 |
194 void AddRequestAuthInfo(StunMessage* msg); | 201 void AddRequestAuthInfo(StunMessage* msg); |
195 void OnSendStunPacket(const void* data, size_t size, StunRequest* request); | 202 void OnSendStunPacket(const void* data, size_t size, StunRequest* request); |
196 // Stun address from allocate success response. | 203 // Stun address from allocate success response. |
197 // Currently used only for testing. | 204 // Currently used only for testing. |
198 void OnStunAddress(const rtc::SocketAddress& address); | 205 void OnStunAddress(const rtc::SocketAddress& address); |
199 void OnAllocateSuccess(const rtc::SocketAddress& address, | 206 void OnAllocateSuccess(const rtc::SocketAddress& address, |
(...skipping 21 matching lines...) Expand all Loading... |
221 TurnEntry* FindEntry(int channel_id) const; | 228 TurnEntry* FindEntry(int channel_id) const; |
222 void CreateOrRefreshEntry(const rtc::SocketAddress& address); | 229 void CreateOrRefreshEntry(const rtc::SocketAddress& address); |
223 void DestroyEntry(TurnEntry* entry); | 230 void DestroyEntry(TurnEntry* entry); |
224 // Destroys the entry only if |timestamp| matches the destruction timestamp | 231 // Destroys the entry only if |timestamp| matches the destruction timestamp |
225 // in |entry|. | 232 // in |entry|. |
226 void DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp); | 233 void DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp); |
227 void ScheduleEntryDestruction(TurnEntry* entry); | 234 void ScheduleEntryDestruction(TurnEntry* entry); |
228 void CancelEntryDestruction(TurnEntry* entry); | 235 void CancelEntryDestruction(TurnEntry* entry); |
229 void OnConnectionDestroyed(Connection* conn); | 236 void OnConnectionDestroyed(Connection* conn); |
230 | 237 |
| 238 // Destroys the connection with remote address |address|. |
| 239 void DestroyConnection(const rtc::SocketAddress& address); |
| 240 |
231 ProtocolAddress server_address_; | 241 ProtocolAddress server_address_; |
232 RelayCredentials credentials_; | 242 RelayCredentials credentials_; |
233 AttemptedServerSet attempted_server_addresses_; | 243 AttemptedServerSet attempted_server_addresses_; |
234 | 244 |
235 rtc::AsyncPacketSocket* socket_; | 245 rtc::AsyncPacketSocket* socket_; |
236 SocketOptionsMap socket_options_; | 246 SocketOptionsMap socket_options_; |
237 rtc::AsyncResolverInterface* resolver_; | 247 rtc::AsyncResolverInterface* resolver_; |
238 int error_; | 248 int error_; |
239 | 249 |
240 StunRequestManager request_manager_; | 250 StunRequestManager request_manager_; |
(...skipping 17 matching lines...) Expand all Loading... |
258 friend class TurnEntry; | 268 friend class TurnEntry; |
259 friend class TurnAllocateRequest; | 269 friend class TurnAllocateRequest; |
260 friend class TurnRefreshRequest; | 270 friend class TurnRefreshRequest; |
261 friend class TurnCreatePermissionRequest; | 271 friend class TurnCreatePermissionRequest; |
262 friend class TurnChannelBindRequest; | 272 friend class TurnChannelBindRequest; |
263 }; | 273 }; |
264 | 274 |
265 } // namespace cricket | 275 } // namespace cricket |
266 | 276 |
267 #endif // WEBRTC_P2P_BASE_TURNPORT_H_ | 277 #endif // WEBRTC_P2P_BASE_TURNPORT_H_ |
OLD | NEW |