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

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: . 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
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();
156 void OnAllocate(); 166 void OnAllocate();
157 void DoAllocate(); 167 void DoAllocate();
158 void OnNetworksChanged(); 168 void OnNetworksChanged();
159 void OnAllocationSequenceObjectsCreated(); 169 void OnAllocationSequenceObjectsCreated();
160 void DisableEquivalentPhases(rtc::Network* network, 170 void DisableEquivalentPhases(rtc::Network* network,
161 PortConfiguration* config, 171 PortConfiguration* config,
162 uint32_t* flags); 172 uint32_t* flags);
163 void AddAllocatedPort(Port* port, AllocationSequence* seq, 173 void AddAllocatedPort(Port* port, AllocationSequence* seq,
164 bool prepare_address); 174 bool prepare_address);
165 void OnCandidateReady(Port* port, const Candidate& c); 175 void OnCandidateReady(Port* port, const Candidate& c);
176 bool IsPortInUse(const PortData& data) const;
166 void OnPortComplete(Port* port); 177 void OnPortComplete(Port* port);
167 void OnPortError(Port* port); 178 void OnPortError(Port* port);
168 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); 179 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
169 void OnPortDestroyed(PortInterface* port); 180 void OnPortDestroyed(PortInterface* port);
170 void MaybeSignalCandidatesAllocationDone(); 181 void MaybeSignalCandidatesAllocationDone();
171 void OnPortAllocationComplete(AllocationSequence* seq); 182 void OnPortAllocationComplete(AllocationSequence* seq);
172 PortData* FindPort(Port* port); 183 PortData* FindPort(Port* port);
173 void GetNetworks(std::vector<rtc::Network*>* networks); 184 void GetNetworks(std::vector<rtc::Network*>* networks);
174 185
175 bool CheckCandidateFilter(const Candidate& c) const; 186 bool CheckCandidateFilter(const Candidate& c) const;
176 bool CandidatePairable(const Candidate& c, const Port* port) const; 187 bool CandidatePairable(const Candidate& c, const Port* port) const;
177 // Clear the related address according to the flags and candidate filter 188 // Clear the related address according to the flags and candidate filter
178 // in order to avoid leaking any information. 189 // in order to avoid leaking any information.
179 Candidate SanitizeRelatedAddress(const Candidate& c) const; 190 Candidate SanitizeRelatedAddress(const Candidate& c) const;
180 191
192 Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
193 // Returns true if at least one TURN port is pruned.
194 bool PruneTurnPortsWith(Port* port);
195
181 BasicPortAllocator* allocator_; 196 BasicPortAllocator* allocator_;
182 rtc::Thread* network_thread_; 197 rtc::Thread* network_thread_;
183 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; 198 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
184 rtc::PacketSocketFactory* socket_factory_; 199 rtc::PacketSocketFactory* socket_factory_;
185 bool allocation_started_; 200 bool allocation_started_;
186 bool network_manager_started_; 201 bool network_manager_started_;
187 bool running_; // set when StartGetAllPorts is called 202 bool running_; // set when StartGetAllPorts is called
188 bool allocation_sequences_created_; 203 bool allocation_sequences_created_;
189 std::vector<PortConfiguration*> configs_; 204 std::vector<PortConfiguration*> configs_;
190 std::vector<AllocationSequence*> sequences_; 205 std::vector<AllocationSequence*> sequences_;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; 334 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
320 // There will be only one udp port per AllocationSequence. 335 // There will be only one udp port per AllocationSequence.
321 UDPPort* udp_port_; 336 UDPPort* udp_port_;
322 std::vector<TurnPort*> turn_ports_; 337 std::vector<TurnPort*> turn_ports_;
323 int phase_; 338 int phase_;
324 }; 339 };
325 340
326 } // namespace cricket 341 } // namespace cricket
327 342
328 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ 343 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698