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

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

Issue 1998813002: Fixing the behavior of the candidate filter with pooled candidates. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Revising a comment and changing order of member variable declaration Created 4 years, 7 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const std::string& content_name, 81 const std::string& content_name,
82 int component, 82 int component,
83 const std::string& ice_ufrag, 83 const std::string& ice_ufrag,
84 const std::string& ice_pwd); 84 const std::string& ice_pwd);
85 ~BasicPortAllocatorSession(); 85 ~BasicPortAllocatorSession();
86 86
87 virtual BasicPortAllocator* allocator() { return allocator_; } 87 virtual BasicPortAllocator* allocator() { return allocator_; }
88 rtc::Thread* network_thread() { return network_thread_; } 88 rtc::Thread* network_thread() { return network_thread_; }
89 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } 89 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
90 90
91 void SetCandidateFilter(uint32_t filter) override;
91 void StartGettingPorts() override; 92 void StartGettingPorts() override;
92 void StopGettingPorts() override; 93 void StopGettingPorts() override;
93 void ClearGettingPorts() override; 94 void ClearGettingPorts() override;
94 bool IsGettingPorts() override { return running_; } 95 bool IsGettingPorts() override { return running_; }
95 // These will all be cricket::Ports. 96 // These will all be cricket::Ports.
96 std::vector<PortInterface*> ReadyPorts() const override; 97 std::vector<PortInterface*> ReadyPorts() const override;
97 std::vector<Candidate> ReadyCandidates() const override; 98 std::vector<Candidate> ReadyCandidates() const override;
98 bool CandidatesAllocationDone() const override; 99 bool CandidatesAllocationDone() const override;
99 100
100 protected: 101 protected:
101 void UpdateIceParametersInternal() override; 102 void UpdateIceParametersInternal() override;
102 103
103 // Starts the process of getting the port configurations. 104 // Starts the process of getting the port configurations.
104 virtual void GetPortConfigurations(); 105 virtual void GetPortConfigurations();
105 106
106 // Adds a port configuration that is now ready. Once we have one for each 107 // Adds a port configuration that is now ready. Once we have one for each
107 // network (or a timeout occurs), we will start allocating ports. 108 // network (or a timeout occurs), we will start allocating ports.
108 virtual void ConfigReady(PortConfiguration* config); 109 virtual void ConfigReady(PortConfiguration* config);
109 110
110 // MessageHandler. Can be overriden if message IDs do not conflict. 111 // MessageHandler. Can be overriden if message IDs do not conflict.
111 void OnMessage(rtc::Message* message) override; 112 void OnMessage(rtc::Message* message) override;
112 113
113 private: 114 private:
114 class PortData { 115 class PortData {
115 public: 116 public:
116 PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {} 117 PortData() {}
117 PortData(Port* port, AllocationSequence* seq) 118 PortData(Port* port, AllocationSequence* seq)
118 : port_(port), sequence_(seq), state_(STATE_INIT) { 119 : port_(port), sequence_(seq) {}
119 }
120 120
121 Port* port() const { return port_; } 121 Port* port() const { return port_; }
122 AllocationSequence* sequence() const { return sequence_; } 122 AllocationSequence* sequence() const { return sequence_; }
123 bool ready() const { return state_ == STATE_READY; } 123 bool ready() const { return ready_; }
124 bool complete() const { return state_ == STATE_COMPLETE; } 124 bool complete() const { return state_ == STATE_COMPLETE; }
125 bool error() const { return state_ == STATE_ERROR; } 125 bool error() const { return state_ == STATE_ERROR; }
126 126
127 void set_ready() { ASSERT(state_ == STATE_INIT); state_ = STATE_READY; } 127 void set_ready(bool ready) {
128 if (ready) {
129 ASSERT(state_ == STATE_INPROGRESS);
130 }
131 ready_ = ready;
132 }
128 void set_complete() { 133 void set_complete() {
129 state_ = STATE_COMPLETE; 134 state_ = STATE_COMPLETE;
130 } 135 }
131 void set_error() { 136 void set_error() {
132 ASSERT(state_ == STATE_INIT || state_ == STATE_READY); 137 ASSERT(state_ == STATE_INPROGRESS);
133 state_ = STATE_ERROR; 138 state_ = STATE_ERROR;
134 } 139 }
135 140
136 private: 141 private:
137 enum State { 142 enum State {
138 STATE_INIT, // No candidates allocated yet. 143 STATE_INPROGRESS, // Still gathering candidates.
139 STATE_READY, // At least one candidate is ready for process. 144 STATE_COMPLETE, // All candidates allocated and ready for process.
140 STATE_COMPLETE, // All candidates allocated and ready for process. 145 STATE_ERROR // Error in gathering candidates.
141 STATE_ERROR // Error in gathering candidates.
142 }; 146 };
143 Port* port_; 147 Port* port_ = nullptr;
144 AllocationSequence* sequence_; 148 AllocationSequence* sequence_ = nullptr;
145 State state_; 149 State state_ = STATE_INPROGRESS;
150 // True if a pairable candidate has been gathered.
151 bool ready_ = false;
pthatcher1 2016/05/20 01:23:54 I think it would be more clear to call this has_pa
Taylor Brandstetter 2016/05/20 21:03:37 Done.
146 }; 152 };
147 153
148 void OnConfigReady(PortConfiguration* config); 154 void OnConfigReady(PortConfiguration* config);
149 void OnConfigStop(); 155 void OnConfigStop();
150 void AllocatePorts(); 156 void AllocatePorts();
151 void OnAllocate(); 157 void OnAllocate();
152 void DoAllocate(); 158 void DoAllocate();
153 void OnNetworksChanged(); 159 void OnNetworksChanged();
154 void OnAllocationSequenceObjectsCreated(); 160 void OnAllocationSequenceObjectsCreated();
155 void DisableEquivalentPhases(rtc::Network* network, 161 void DisableEquivalentPhases(rtc::Network* network,
156 PortConfiguration* config, 162 PortConfiguration* config,
157 uint32_t* flags); 163 uint32_t* flags);
158 void AddAllocatedPort(Port* port, AllocationSequence* seq, 164 void AddAllocatedPort(Port* port, AllocationSequence* seq,
159 bool prepare_address); 165 bool prepare_address);
160 void OnCandidateReady(Port* port, const Candidate& c); 166 void OnCandidateReady(Port* port, const Candidate& c);
161 void OnPortComplete(Port* port); 167 void OnPortComplete(Port* port);
162 void OnPortError(Port* port); 168 void OnPortError(Port* port);
163 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); 169 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
164 void OnPortDestroyed(PortInterface* port); 170 void OnPortDestroyed(PortInterface* port);
165 void OnShake(); 171 void OnShake();
166 void MaybeSignalCandidatesAllocationDone(); 172 void MaybeSignalCandidatesAllocationDone();
167 void OnPortAllocationComplete(AllocationSequence* seq); 173 void OnPortAllocationComplete(AllocationSequence* seq);
168 PortData* FindPort(Port* port); 174 PortData* FindPort(Port* port);
169 void GetNetworks(std::vector<rtc::Network*>* networks); 175 void GetNetworks(std::vector<rtc::Network*>* networks);
170 176
171 bool CheckCandidateFilter(const Candidate& c) const; 177 bool CheckCandidateFilter(const Candidate& c) const;
178 bool CandidatePairable(const Candidate& c, const Port* port) const;
179 // Clear the related address according to the flags and candidate filter
180 // in order to avoid leaking any information.
181 Candidate SanitizeRelatedAddress(const Candidate& c) const;
172 182
173 BasicPortAllocator* allocator_; 183 BasicPortAllocator* allocator_;
174 rtc::Thread* network_thread_; 184 rtc::Thread* network_thread_;
175 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; 185 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
176 rtc::PacketSocketFactory* socket_factory_; 186 rtc::PacketSocketFactory* socket_factory_;
177 bool allocation_started_; 187 bool allocation_started_;
178 bool network_manager_started_; 188 bool network_manager_started_;
179 bool running_; // set when StartGetAllPorts is called 189 bool running_; // set when StartGetAllPorts is called
180 bool allocation_sequences_created_; 190 bool allocation_sequences_created_;
181 std::vector<PortConfiguration*> configs_; 191 std::vector<PortConfiguration*> configs_;
182 std::vector<AllocationSequence*> sequences_; 192 std::vector<AllocationSequence*> sequences_;
183 std::vector<PortData> ports_; 193 std::vector<PortData> ports_;
194 uint32_t candidate_filter_ = CF_ALL;
184 195
185 friend class AllocationSequence; 196 friend class AllocationSequence;
186 }; 197 };
187 198
188 // Records configuration information useful in creating ports. 199 // Records configuration information useful in creating ports.
189 // TODO(deadbeef): Rename "relay" to "turn_server" in this struct. 200 // TODO(deadbeef): Rename "relay" to "turn_server" in this struct.
190 struct PortConfiguration : public rtc::MessageData { 201 struct PortConfiguration : public rtc::MessageData {
191 // TODO(jiayl): remove |stun_address| when Chrome is updated. 202 // TODO(jiayl): remove |stun_address| when Chrome is updated.
192 rtc::SocketAddress stun_address; 203 rtc::SocketAddress stun_address;
193 ServerAddresses stun_servers; 204 ServerAddresses stun_servers;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; 321 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
311 // There will be only one udp port per AllocationSequence. 322 // There will be only one udp port per AllocationSequence.
312 UDPPort* udp_port_; 323 UDPPort* udp_port_;
313 std::vector<TurnPort*> turn_ports_; 324 std::vector<TurnPort*> turn_ports_;
314 int phase_; 325 int phase_;
315 }; 326 };
316 327
317 } // namespace cricket 328 } // namespace cricket
318 329
319 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ 330 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698