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 // A terminated state is one of COMPLETE, ERROR or PRUNED state. | |
128 bool terminated() const { return state_ != STATE_INPROGRESS; } | |
pthatcher1
2016/06/28 21:01:41
Why not have bool gathering() cosnt { return state
honghaiz3
2016/06/28 23:36:00
Done. I used the name inprogress to match the vari
| |
126 | 129 |
130 void set_pruned() { state_ = STATE_PRUNED; } | |
127 void set_has_pairable_candidate(bool has_pairable_candidate) { | 131 void set_has_pairable_candidate(bool has_pairable_candidate) { |
128 if (has_pairable_candidate) { | 132 if (has_pairable_candidate) { |
129 ASSERT(state_ == STATE_INPROGRESS); | 133 ASSERT(state_ == STATE_INPROGRESS); |
130 } | 134 } |
131 has_pairable_candidate_ = has_pairable_candidate; | 135 has_pairable_candidate_ = has_pairable_candidate; |
132 } | 136 } |
133 void set_complete() { | 137 void set_complete() { |
134 state_ = STATE_COMPLETE; | 138 state_ = STATE_COMPLETE; |
135 } | 139 } |
136 void set_error() { | 140 void set_error() { |
137 ASSERT(state_ == STATE_INPROGRESS); | 141 ASSERT(state_ == STATE_INPROGRESS); |
138 state_ = STATE_ERROR; | 142 state_ = STATE_ERROR; |
139 } | 143 } |
140 | 144 |
141 private: | 145 private: |
142 enum State { | 146 enum State { |
143 STATE_INPROGRESS, // Still gathering candidates. | 147 STATE_INPROGRESS, // Still gathering candidates. |
144 STATE_COMPLETE, // All candidates allocated and ready for process. | 148 STATE_COMPLETE, // All candidates allocated and ready for process. |
145 STATE_ERROR // Error in gathering candidates. | 149 STATE_ERROR, // Error in gathering candidates. |
150 STATE_PRUNED // Pruned by higher priority ports on the same network | |
151 // interface. Only TURN ports may be pruned. | |
146 }; | 152 }; |
147 Port* port_ = nullptr; | 153 Port* port_ = nullptr; |
148 AllocationSequence* sequence_ = nullptr; | 154 AllocationSequence* sequence_ = nullptr; |
149 State state_ = STATE_INPROGRESS; | 155 State state_ = STATE_INPROGRESS; |
150 bool has_pairable_candidate_ = false; | 156 bool has_pairable_candidate_ = false; |
151 }; | 157 }; |
152 | 158 |
153 void OnConfigReady(PortConfiguration* config); | 159 void OnConfigReady(PortConfiguration* config); |
154 void OnConfigStop(); | 160 void OnConfigStop(); |
155 void AllocatePorts(); | 161 void AllocatePorts(); |
156 void OnAllocate(); | 162 void OnAllocate(); |
157 void DoAllocate(); | 163 void DoAllocate(); |
158 void OnNetworksChanged(); | 164 void OnNetworksChanged(); |
159 void OnAllocationSequenceObjectsCreated(); | 165 void OnAllocationSequenceObjectsCreated(); |
160 void DisableEquivalentPhases(rtc::Network* network, | 166 void DisableEquivalentPhases(rtc::Network* network, |
161 PortConfiguration* config, | 167 PortConfiguration* config, |
162 uint32_t* flags); | 168 uint32_t* flags); |
163 void AddAllocatedPort(Port* port, AllocationSequence* seq, | 169 void AddAllocatedPort(Port* port, AllocationSequence* seq, |
164 bool prepare_address); | 170 bool prepare_address); |
165 void OnCandidateReady(Port* port, const Candidate& c); | 171 void OnCandidateReady(Port* port, const Candidate& c); |
172 void OnPortPairable(PortData* port_data); | |
173 bool IsPortInUse(const PortData& data) const; | |
166 void OnPortComplete(Port* port); | 174 void OnPortComplete(Port* port); |
167 void OnPortError(Port* port); | 175 void OnPortError(Port* port); |
168 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); | 176 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); |
169 void OnPortDestroyed(PortInterface* port); | 177 void OnPortDestroyed(PortInterface* port); |
170 void MaybeSignalCandidatesAllocationDone(); | 178 void MaybeSignalCandidatesAllocationDone(); |
171 void OnPortAllocationComplete(AllocationSequence* seq); | 179 void OnPortAllocationComplete(AllocationSequence* seq); |
172 PortData* FindPort(Port* port); | 180 PortData* FindPort(Port* port); |
173 void GetNetworks(std::vector<rtc::Network*>* networks); | 181 void GetNetworks(std::vector<rtc::Network*>* networks); |
174 | 182 |
175 bool CheckCandidateFilter(const Candidate& c) const; | 183 bool CheckCandidateFilter(const Candidate& c) const; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; | 327 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; |
320 // There will be only one udp port per AllocationSequence. | 328 // There will be only one udp port per AllocationSequence. |
321 UDPPort* udp_port_; | 329 UDPPort* udp_port_; |
322 std::vector<TurnPort*> turn_ports_; | 330 std::vector<TurnPort*> turn_ports_; |
323 int phase_; | 331 int phase_; |
324 }; | 332 }; |
325 | 333 |
326 } // namespace cricket | 334 } // namespace cricket |
327 | 335 |
328 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 336 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
OLD | NEW |