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

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

Issue 2093623004: Add config to prune TURN ports (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Partially disable the test TestEachInterfaceHasItsOwnTurnPorts Created 4 years, 5 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
« no previous file with comments | « webrtc/p2p/base/turnport.h ('k') | webrtc/p2p/client/basicportallocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 public: 116 public:
117 PortData() {} 117 PortData() {}
118 PortData(Port* port, AllocationSequence* seq) 118 PortData(Port* port, AllocationSequence* seq)
119 : port_(port), sequence_(seq) {} 119 : port_(port), sequence_(seq) {}
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 has_pairable_candidate() const { return has_pairable_candidate_; } 123 bool has_pairable_candidate() const { return has_pairable_candidate_; }
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 bool pruned() const { return state_ == STATE_PRUNED; }
127 bool inprogress() const { return state_ == STATE_INPROGRESS; }
128 // Returns true if this port is ready to be used.
129 bool ready() const {
130 return has_pairable_candidate_ && state_ != STATE_ERROR &&
131 state_ != STATE_PRUNED;
132 }
126 133
134 void set_pruned() { state_ = STATE_PRUNED; }
127 void set_has_pairable_candidate(bool has_pairable_candidate) { 135 void set_has_pairable_candidate(bool has_pairable_candidate) {
128 if (has_pairable_candidate) { 136 if (has_pairable_candidate) {
129 ASSERT(state_ == STATE_INPROGRESS); 137 ASSERT(state_ == STATE_INPROGRESS);
130 } 138 }
131 has_pairable_candidate_ = has_pairable_candidate; 139 has_pairable_candidate_ = has_pairable_candidate;
132 } 140 }
133 void set_complete() { 141 void set_complete() {
134 state_ = STATE_COMPLETE; 142 state_ = STATE_COMPLETE;
135 } 143 }
136 void set_error() { 144 void set_error() {
137 ASSERT(state_ == STATE_INPROGRESS); 145 ASSERT(state_ == STATE_INPROGRESS);
138 state_ = STATE_ERROR; 146 state_ = STATE_ERROR;
139 } 147 }
140 148
141 private: 149 private:
142 enum State { 150 enum State {
143 STATE_INPROGRESS, // Still gathering candidates. 151 STATE_INPROGRESS, // Still gathering candidates.
144 STATE_COMPLETE, // All candidates allocated and ready for process. 152 STATE_COMPLETE, // All candidates allocated and ready for process.
145 STATE_ERROR // Error in gathering candidates. 153 STATE_ERROR, // Error in gathering candidates.
154 STATE_PRUNED // Pruned by higher priority ports on the same network
155 // interface. Only TURN ports may be pruned.
146 }; 156 };
147 Port* port_ = nullptr; 157 Port* port_ = nullptr;
148 AllocationSequence* sequence_ = nullptr; 158 AllocationSequence* sequence_ = nullptr;
149 State state_ = STATE_INPROGRESS; 159 State state_ = STATE_INPROGRESS;
150 bool has_pairable_candidate_ = false; 160 bool has_pairable_candidate_ = false;
151 }; 161 };
152 162
153 void OnConfigReady(PortConfiguration* config); 163 void OnConfigReady(PortConfiguration* config);
154 void OnConfigStop(); 164 void OnConfigStop();
155 void AllocatePorts(); 165 void AllocatePorts();
(...skipping 15 matching lines...) Expand all
171 void OnPortAllocationComplete(AllocationSequence* seq); 181 void OnPortAllocationComplete(AllocationSequence* seq);
172 PortData* FindPort(Port* port); 182 PortData* FindPort(Port* port);
173 void GetNetworks(std::vector<rtc::Network*>* networks); 183 void GetNetworks(std::vector<rtc::Network*>* networks);
174 184
175 bool CheckCandidateFilter(const Candidate& c) const; 185 bool CheckCandidateFilter(const Candidate& c) const;
176 bool CandidatePairable(const Candidate& c, const Port* port) const; 186 bool CandidatePairable(const Candidate& c, const Port* port) const;
177 // Clear the related address according to the flags and candidate filter 187 // Clear the related address according to the flags and candidate filter
178 // in order to avoid leaking any information. 188 // in order to avoid leaking any information.
179 Candidate SanitizeRelatedAddress(const Candidate& c) const; 189 Candidate SanitizeRelatedAddress(const Candidate& c) const;
180 190
191 Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
192 // Returns true if at least one TURN port is pruned.
193 bool PruneTurnPorts(Port* newly_pairable_turn_port);
194
181 BasicPortAllocator* allocator_; 195 BasicPortAllocator* allocator_;
182 rtc::Thread* network_thread_; 196 rtc::Thread* network_thread_;
183 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; 197 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
184 rtc::PacketSocketFactory* socket_factory_; 198 rtc::PacketSocketFactory* socket_factory_;
185 bool allocation_started_; 199 bool allocation_started_;
186 bool network_manager_started_; 200 bool network_manager_started_;
187 bool running_; // set when StartGetAllPorts is called 201 bool running_; // set when StartGetAllPorts is called
188 bool allocation_sequences_created_; 202 bool allocation_sequences_created_;
189 std::vector<PortConfiguration*> configs_; 203 std::vector<PortConfiguration*> configs_;
190 std::vector<AllocationSequence*> sequences_; 204 std::vector<AllocationSequence*> sequences_;
191 std::vector<PortData> ports_; 205 std::vector<PortData> ports_;
192 uint32_t candidate_filter_ = CF_ALL; 206 uint32_t candidate_filter_ = CF_ALL;
207 // Whether to prune low-priority ports, taken from the port allocator.
208 bool prune_turn_ports_;
193 209
194 friend class AllocationSequence; 210 friend class AllocationSequence;
195 }; 211 };
196 212
197 // Records configuration information useful in creating ports. 213 // Records configuration information useful in creating ports.
198 // TODO(deadbeef): Rename "relay" to "turn_server" in this struct. 214 // TODO(deadbeef): Rename "relay" to "turn_server" in this struct.
199 struct PortConfiguration : public rtc::MessageData { 215 struct PortConfiguration : public rtc::MessageData {
200 // TODO(jiayl): remove |stun_address| when Chrome is updated. 216 // TODO(jiayl): remove |stun_address| when Chrome is updated.
201 rtc::SocketAddress stun_address; 217 rtc::SocketAddress stun_address;
202 ServerAddresses stun_servers; 218 ServerAddresses stun_servers;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; 335 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
320 // There will be only one udp port per AllocationSequence. 336 // There will be only one udp port per AllocationSequence.
321 UDPPort* udp_port_; 337 UDPPort* udp_port_;
322 std::vector<TurnPort*> turn_ports_; 338 std::vector<TurnPort*> turn_ports_;
323 int phase_; 339 int phase_;
324 }; 340 };
325 341
326 } // namespace cricket 342 } // namespace cricket
327 343
328 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ 344 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport.h ('k') | webrtc/p2p/client/basicportallocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698