OLD | NEW |
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 Loading... |
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 void OnPortPairable(PortData* port_data); |
| 177 bool IsPortInUse(const PortData& data) const; |
166 void OnPortComplete(Port* port); | 178 void OnPortComplete(Port* port); |
167 void OnPortError(Port* port); | 179 void OnPortError(Port* port); |
168 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); | 180 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); |
169 void OnPortDestroyed(PortInterface* port); | 181 void OnPortDestroyed(PortInterface* port); |
170 void MaybeSignalCandidatesAllocationDone(); | 182 void MaybeSignalCandidatesAllocationDone(); |
171 void OnPortAllocationComplete(AllocationSequence* seq); | 183 void OnPortAllocationComplete(AllocationSequence* seq); |
172 PortData* FindPort(Port* port); | 184 PortData* FindPort(Port* port); |
173 void GetNetworks(std::vector<rtc::Network*>* networks); | 185 void GetNetworks(std::vector<rtc::Network*>* networks); |
174 | 186 |
175 bool CheckCandidateFilter(const Candidate& c) const; | 187 bool CheckCandidateFilter(const Candidate& c) const; |
176 bool CandidatePairable(const Candidate& c, const Port* port) const; | 188 bool CandidatePairable(const Candidate& c, const Port* port) const; |
177 // Clear the related address according to the flags and candidate filter | 189 // Clear the related address according to the flags and candidate filter |
178 // in order to avoid leaking any information. | 190 // in order to avoid leaking any information. |
179 Candidate SanitizeRelatedAddress(const Candidate& c) const; | 191 Candidate SanitizeRelatedAddress(const Candidate& c) const; |
180 | 192 |
| 193 Port* GetBestTurnPortForNetwork(const std::string& network_name) const; |
| 194 // Returns true if at least one TURN port is pruned. |
| 195 bool PruneTurnPortsWorseThan(Port* best_turn_port); |
| 196 |
181 BasicPortAllocator* allocator_; | 197 BasicPortAllocator* allocator_; |
182 rtc::Thread* network_thread_; | 198 rtc::Thread* network_thread_; |
183 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; | 199 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
184 rtc::PacketSocketFactory* socket_factory_; | 200 rtc::PacketSocketFactory* socket_factory_; |
185 bool allocation_started_; | 201 bool allocation_started_; |
186 bool network_manager_started_; | 202 bool network_manager_started_; |
187 bool running_; // set when StartGetAllPorts is called | 203 bool running_; // set when StartGetAllPorts is called |
188 bool allocation_sequences_created_; | 204 bool allocation_sequences_created_; |
189 std::vector<PortConfiguration*> configs_; | 205 std::vector<PortConfiguration*> configs_; |
190 std::vector<AllocationSequence*> sequences_; | 206 std::vector<AllocationSequence*> sequences_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_ |
OLD | NEW |