Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: webrtc/p2p/client/basicportallocator.h

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 29 matching lines...) Expand all
40 // Set to kDefaultNetworkIgnoreMask by default. 40 // Set to kDefaultNetworkIgnoreMask by default.
41 void SetNetworkIgnoreMask(int network_ignore_mask) override { 41 void SetNetworkIgnoreMask(int network_ignore_mask) override {
42 // TODO(phoglund): implement support for other types than loopback. 42 // TODO(phoglund): implement support for other types than loopback.
43 // See https://code.google.com/p/webrtc/issues/detail?id=4288. 43 // See https://code.google.com/p/webrtc/issues/detail?id=4288.
44 // Then remove set_network_ignore_list from NetworkManager. 44 // Then remove set_network_ignore_list from NetworkManager.
45 network_ignore_mask_ = network_ignore_mask; 45 network_ignore_mask_ = network_ignore_mask;
46 } 46 }
47 47
48 int network_ignore_mask() const { return network_ignore_mask_; } 48 int network_ignore_mask() const { return network_ignore_mask_; }
49 49
50 rtc::NetworkManager* network_manager() { return network_manager_; } 50 rtc::NetworkManager* network_manager() const override {
51 return network_manager_;
52 }
51 53
52 // If socket_factory() is set to NULL each PortAllocatorSession 54 // If socket_factory() is set to NULL each PortAllocatorSession
53 // creates its own socket factory. 55 // creates its own socket factory.
54 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } 56 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
55 57
56 PortAllocatorSession* CreateSessionInternal( 58 PortAllocatorSession* CreateSessionInternal(
57 const std::string& content_name, 59 const std::string& content_name,
58 int component, 60 int component,
59 const std::string& ice_ufrag, 61 const std::string& ice_ufrag,
60 const std::string& ice_pwd) override; 62 const std::string& ice_pwd) override;
(...skipping 16 matching lines...) Expand all
77 class BasicPortAllocatorSession : public PortAllocatorSession, 79 class BasicPortAllocatorSession : public PortAllocatorSession,
78 public rtc::MessageHandler { 80 public rtc::MessageHandler {
79 public: 81 public:
80 BasicPortAllocatorSession(BasicPortAllocator* allocator, 82 BasicPortAllocatorSession(BasicPortAllocator* allocator,
81 const std::string& content_name, 83 const std::string& content_name,
82 int component, 84 int component,
83 const std::string& ice_ufrag, 85 const std::string& ice_ufrag,
84 const std::string& ice_pwd); 86 const std::string& ice_pwd);
85 ~BasicPortAllocatorSession(); 87 ~BasicPortAllocatorSession();
86 88
89 // TODO(honghaiz): When continual gathering is fully enabled, we don't need
90 // the state STATE_STOPPED. A session can always start new allocation
91 // sequences.
92 enum State {
93 STATE_RUNNING, // Current allocation sequence is running, can start new
94 // allocation sequences.
95 STATE_CLEARED, // Current allocation sequence is complete, can start new
96 // allocation sequences.
97 STATE_STOPPED // Current allocation sequence is complete, cannot start
98 // new allocation sequences.
99 };
100
87 virtual BasicPortAllocator* allocator() { return allocator_; } 101 virtual BasicPortAllocator* allocator() { return allocator_; }
88 rtc::Thread* network_thread() { return network_thread_; } 102 rtc::Thread* network_thread() { return network_thread_; }
89 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } 103 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
90 104
91 void SetCandidateFilter(uint32_t filter) override; 105 void SetCandidateFilter(uint32_t filter) override;
106
92 void StartGettingPorts() override; 107 void StartGettingPorts() override;
93 void StopGettingPorts() override; 108 void StopGettingPorts() override;
94 void ClearGettingPorts() override; 109 void ClearGettingPorts() override;
95 bool IsGettingPorts() override { return running_; } 110 bool IsGettingPorts() override { return state_ == STATE_RUNNING; }
111 bool CanGetPorts() override { return state_ != STATE_STOPPED; }
112
96 // These will all be cricket::Ports. 113 // These will all be cricket::Ports.
97 std::vector<PortInterface*> ReadyPorts() const override; 114 std::vector<PortInterface*> ReadyPorts() const override;
98 std::vector<Candidate> ReadyCandidates() const override; 115 std::vector<Candidate> ReadyCandidates() const override;
116 std::vector<Candidate> ReadyCandidates(PortInterface* port) const override;
99 bool CandidatesAllocationDone() const override; 117 bool CandidatesAllocationDone() const override;
118 bool RegatherOnFailedNetworks() override;
100 119
101 protected: 120 protected:
102 void UpdateIceParametersInternal() override; 121 void UpdateIceParametersInternal() override;
103 122
104 // Starts the process of getting the port configurations. 123 // Starts the process of getting the port configurations.
105 virtual void GetPortConfigurations(); 124 virtual void GetPortConfigurations();
106 125
107 // Adds a port configuration that is now ready. Once we have one for each 126 // Adds a port configuration that is now ready. Once we have one for each
108 // network (or a timeout occurs), we will start allocating ports. 127 // network (or a timeout occurs), we will start allocating ports.
109 virtual void ConfigReady(PortConfiguration* config); 128 virtual void ConfigReady(PortConfiguration* config);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 void AddAllocatedPort(Port* port, AllocationSequence* seq, 182 void AddAllocatedPort(Port* port, AllocationSequence* seq,
164 bool prepare_address); 183 bool prepare_address);
165 void OnCandidateReady(Port* port, const Candidate& c); 184 void OnCandidateReady(Port* port, const Candidate& c);
166 void OnPortComplete(Port* port); 185 void OnPortComplete(Port* port);
167 void OnPortError(Port* port); 186 void OnPortError(Port* port);
168 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); 187 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
169 void OnPortDestroyed(PortInterface* port); 188 void OnPortDestroyed(PortInterface* port);
170 void MaybeSignalCandidatesAllocationDone(); 189 void MaybeSignalCandidatesAllocationDone();
171 void OnPortAllocationComplete(AllocationSequence* seq); 190 void OnPortAllocationComplete(AllocationSequence* seq);
172 PortData* FindPort(Port* port); 191 PortData* FindPort(Port* port);
173 void GetNetworks(std::vector<rtc::Network*>* networks); 192 std::vector<rtc::Network*> GetNetworks() const;
193 std::vector<rtc::Network*> GetFailedNetworks() const;
174 194
175 bool CheckCandidateFilter(const Candidate& c) const; 195 bool CheckCandidateFilter(const Candidate& c) const;
176 bool CandidatePairable(const Candidate& c, const Port* port) const; 196 bool CandidatePairable(const Candidate& c, const Port* port) const;
177 // Clear the related address according to the flags and candidate filter 197 // Clear the related address according to the flags and candidate filter
178 // in order to avoid leaking any information. 198 // in order to avoid leaking any information.
179 Candidate SanitizeRelatedAddress(const Candidate& c) const; 199 Candidate SanitizeRelatedAddress(const Candidate& c) const;
180 200
181 BasicPortAllocator* allocator_; 201 BasicPortAllocator* allocator_;
182 rtc::Thread* network_thread_; 202 rtc::Thread* network_thread_;
183 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; 203 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
184 rtc::PacketSocketFactory* socket_factory_; 204 rtc::PacketSocketFactory* socket_factory_;
185 bool allocation_started_; 205 bool allocation_started_;
186 bool network_manager_started_; 206 bool network_manager_started_;
187 bool running_; // set when StartGetAllPorts is called 207 State state_ = STATE_RUNNING;
188 bool allocation_sequences_created_; 208 bool allocation_sequences_created_;
189 std::vector<PortConfiguration*> configs_; 209 std::vector<PortConfiguration*> configs_;
190 std::vector<AllocationSequence*> sequences_; 210 std::vector<AllocationSequence*> sequences_;
191 std::vector<PortData> ports_; 211 std::vector<PortData> ports_;
192 uint32_t candidate_filter_ = CF_ALL; 212 uint32_t candidate_filter_ = CF_ALL;
193 213
194 friend class AllocationSequence; 214 friend class AllocationSequence;
195 }; 215 };
196 216
197 // Records configuration information useful in creating ports. 217 // Records configuration information useful in creating ports.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 268
249 // kInit --> kRunning --> {kCompleted|kStopped} 269 // kInit --> kRunning --> {kCompleted|kStopped}
250 }; 270 };
251 AllocationSequence(BasicPortAllocatorSession* session, 271 AllocationSequence(BasicPortAllocatorSession* session,
252 rtc::Network* network, 272 rtc::Network* network,
253 PortConfiguration* config, 273 PortConfiguration* config,
254 uint32_t flags); 274 uint32_t flags);
255 ~AllocationSequence(); 275 ~AllocationSequence();
256 bool Init(); 276 bool Init();
257 void Clear(); 277 void Clear();
258 void OnNetworkRemoved(); 278 void OnNetworkInactivated();
259 279
260 State state() const { return state_; } 280 State state() const { return state_; }
261 const rtc::Network* network() const { return network_; } 281 const rtc::Network* network() const { return network_; }
262 bool network_removed() const { return network_removed_; } 282
283 bool network_inactive() const { return network_inactive_; }
284 void set_network_inactive(bool network_inactive) {
285 network_inactive_ = network_inactive;
286 }
263 287
264 // Disables the phases for a new sequence that this one already covers for an 288 // Disables the phases for a new sequence that this one already covers for an
265 // equivalent network setup. 289 // equivalent network setup.
266 void DisableEquivalentPhases(rtc::Network* network, 290 void DisableEquivalentPhases(rtc::Network* network,
267 PortConfiguration* config, 291 PortConfiguration* config,
268 uint32_t* flags); 292 uint32_t* flags);
269 293
270 // Starts and stops the sequence. When started, it will continue allocating 294 // Starts and stops the sequence. When started, it will continue allocating
271 // new ports on its own timed schedule. 295 // new ports on its own timed schedule.
272 void Start(); 296 void Start();
(...skipping 29 matching lines...) Expand all
302 326
303 void OnReadPacket(rtc::AsyncPacketSocket* socket, 327 void OnReadPacket(rtc::AsyncPacketSocket* socket,
304 const char* data, 328 const char* data,
305 size_t size, 329 size_t size,
306 const rtc::SocketAddress& remote_addr, 330 const rtc::SocketAddress& remote_addr,
307 const rtc::PacketTime& packet_time); 331 const rtc::PacketTime& packet_time);
308 332
309 void OnPortDestroyed(PortInterface* port); 333 void OnPortDestroyed(PortInterface* port);
310 334
311 BasicPortAllocatorSession* session_; 335 BasicPortAllocatorSession* session_;
312 bool network_removed_ = false; 336 bool network_inactive_ = false;
313 rtc::Network* network_; 337 rtc::Network* network_;
314 rtc::IPAddress ip_; 338 rtc::IPAddress ip_;
315 PortConfiguration* config_; 339 PortConfiguration* config_;
316 State state_; 340 State state_;
317 uint32_t flags_; 341 uint32_t flags_;
318 ProtocolList protocols_; 342 ProtocolList protocols_;
319 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; 343 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
320 // There will be only one udp port per AllocationSequence. 344 // There will be only one udp port per AllocationSequence.
321 UDPPort* udp_port_; 345 UDPPort* udp_port_;
322 std::vector<TurnPort*> turn_ports_; 346 std::vector<TurnPort*> turn_ports_;
323 int phase_; 347 int phase_;
324 }; 348 };
325 349
326 } // namespace cricket 350 } // namespace cricket
327 351
328 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ 352 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698