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