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 20 matching lines...) Expand all Loading... | |
31 BasicPortAllocator(rtc::NetworkManager* network_manager, | 31 BasicPortAllocator(rtc::NetworkManager* network_manager, |
32 rtc::PacketSocketFactory* socket_factory, | 32 rtc::PacketSocketFactory* socket_factory, |
33 const ServerAddresses& stun_servers); | 33 const ServerAddresses& stun_servers); |
34 BasicPortAllocator(rtc::NetworkManager* network_manager, | 34 BasicPortAllocator(rtc::NetworkManager* network_manager, |
35 const ServerAddresses& stun_servers, | 35 const ServerAddresses& stun_servers, |
36 const rtc::SocketAddress& relay_server_udp, | 36 const rtc::SocketAddress& relay_server_udp, |
37 const rtc::SocketAddress& relay_server_tcp, | 37 const rtc::SocketAddress& relay_server_tcp, |
38 const rtc::SocketAddress& relay_server_ssl); | 38 const rtc::SocketAddress& relay_server_ssl); |
39 virtual ~BasicPortAllocator(); | 39 virtual ~BasicPortAllocator(); |
40 | 40 |
41 void SetIceServers( | |
42 const ServerAddresses& stun_servers, | |
43 const std::vector<RelayServerConfig>& turn_servers) override { | |
44 stun_servers_ = stun_servers; | |
45 turn_servers_ = turn_servers; | |
46 } | |
47 | |
48 // Set to kDefaultNetworkIgnoreMask by default. | 41 // Set to kDefaultNetworkIgnoreMask by default. |
49 void SetNetworkIgnoreMask(int network_ignore_mask) override { | 42 void SetNetworkIgnoreMask(int network_ignore_mask) override { |
50 // TODO(phoglund): implement support for other types than loopback. | 43 // TODO(phoglund): implement support for other types than loopback. |
51 // See https://code.google.com/p/webrtc/issues/detail?id=4288. | 44 // See https://code.google.com/p/webrtc/issues/detail?id=4288. |
52 // Then remove set_network_ignore_list from NetworkManager. | 45 // Then remove set_network_ignore_list from NetworkManager. |
53 network_ignore_mask_ = network_ignore_mask; | 46 network_ignore_mask_ = network_ignore_mask; |
54 } | 47 } |
55 | 48 |
56 int network_ignore_mask() const { return network_ignore_mask_; } | 49 int network_ignore_mask() const { return network_ignore_mask_; } |
57 | 50 |
58 rtc::NetworkManager* network_manager() { return network_manager_; } | 51 rtc::NetworkManager* network_manager() { return network_manager_; } |
59 | 52 |
60 // If socket_factory() is set to NULL each PortAllocatorSession | 53 // If socket_factory() is set to NULL each PortAllocatorSession |
61 // creates its own socket factory. | 54 // creates its own socket factory. |
62 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } | 55 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
63 | 56 |
64 const ServerAddresses& stun_servers() const { | |
65 return stun_servers_; | |
66 } | |
67 | |
68 const std::vector<RelayServerConfig>& turn_servers() const { | |
69 return turn_servers_; | |
70 } | |
71 virtual void AddTurnServer(const RelayServerConfig& turn_server) { | |
72 turn_servers_.push_back(turn_server); | |
73 } | |
74 | |
75 PortAllocatorSession* CreateSessionInternal( | 57 PortAllocatorSession* CreateSessionInternal( |
76 const std::string& content_name, | 58 const std::string& content_name, |
77 int component, | 59 int component, |
78 const std::string& ice_ufrag, | 60 const std::string& ice_ufrag, |
79 const std::string& ice_pwd) override; | 61 const std::string& ice_pwd) override; |
80 | 62 |
63 // Convenience method that adds a TURN server to the configuration. | |
64 void AddTurnServer(const RelayServerConfig& turn_server); | |
65 | |
81 private: | 66 private: |
82 void Construct(); | 67 void Construct(); |
83 | 68 |
84 rtc::NetworkManager* network_manager_; | 69 rtc::NetworkManager* network_manager_; |
85 rtc::PacketSocketFactory* socket_factory_; | 70 rtc::PacketSocketFactory* socket_factory_; |
86 ServerAddresses stun_servers_; | |
87 std::vector<RelayServerConfig> turn_servers_; | |
88 bool allow_tcp_listen_; | 71 bool allow_tcp_listen_; |
89 int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask; | 72 int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask; |
90 }; | 73 }; |
91 | 74 |
92 struct PortConfiguration; | 75 struct PortConfiguration; |
93 class AllocationSequence; | 76 class AllocationSequence; |
94 | 77 |
95 class BasicPortAllocatorSession : public PortAllocatorSession, | 78 class BasicPortAllocatorSession : public PortAllocatorSession, |
96 public rtc::MessageHandler { | 79 public rtc::MessageHandler { |
97 public: | 80 public: |
98 BasicPortAllocatorSession(BasicPortAllocator* allocator, | 81 BasicPortAllocatorSession(BasicPortAllocator* allocator, |
99 const std::string& content_name, | 82 const std::string& content_name, |
100 int component, | 83 int component, |
101 const std::string& ice_ufrag, | 84 const std::string& ice_ufrag, |
102 const std::string& ice_pwd); | 85 const std::string& ice_pwd); |
103 ~BasicPortAllocatorSession(); | 86 ~BasicPortAllocatorSession(); |
104 | 87 |
105 virtual BasicPortAllocator* allocator() { return allocator_; } | 88 virtual BasicPortAllocator* allocator() { return allocator_; } |
106 rtc::Thread* network_thread() { return network_thread_; } | 89 rtc::Thread* network_thread() { return network_thread_; } |
107 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } | 90 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
108 | 91 |
109 void StartGettingPorts() override; | 92 void StartGettingPorts() override; |
110 void StopGettingPorts() override; | 93 void StopGettingPorts() override; |
111 void ClearGettingPorts() override; | 94 void ClearGettingPorts() override; |
112 bool IsGettingPorts() override { return running_; } | 95 bool IsGettingPorts() override { return running_; } |
96 // These will all be cricket::Ports. | |
97 std::vector<PortInterface*> ReadyPorts() const override; | |
98 std::vector<Candidate> ReadyCandidates() const override; | |
99 bool CandidatesAllocationDone() const override; | |
113 | 100 |
114 protected: | 101 protected: |
102 void UpdateTransportInformationInternal() override; | |
103 | |
115 // Starts the process of getting the port configurations. | 104 // Starts the process of getting the port configurations. |
116 virtual void GetPortConfigurations(); | 105 virtual void GetPortConfigurations(); |
117 | 106 |
118 // Adds a port configuration that is now ready. Once we have one for each | 107 // Adds a port configuration that is now ready. Once we have one for each |
119 // network (or a timeout occurs), we will start allocating ports. | 108 // network (or a timeout occurs), we will start allocating ports. |
120 virtual void ConfigReady(PortConfiguration* config); | 109 virtual void ConfigReady(PortConfiguration* config); |
121 | 110 |
122 // MessageHandler. Can be overriden if message IDs do not conflict. | 111 // MessageHandler. Can be overriden if message IDs do not conflict. |
123 void OnMessage(rtc::Message* message) override; | 112 void OnMessage(rtc::Message* message) override; |
124 | 113 |
125 private: | 114 private: |
126 class PortData { | 115 class PortData { |
127 public: | 116 public: |
128 PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {} | 117 PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {} |
129 PortData(Port* port, AllocationSequence* seq) | 118 PortData(Port* port, AllocationSequence* seq) |
130 : port_(port), sequence_(seq), state_(STATE_INIT) { | 119 : port_(port), sequence_(seq), state_(STATE_INIT) { |
131 } | 120 } |
132 | 121 |
133 Port* port() { return port_; } | 122 Port* port() const { return port_; } |
134 AllocationSequence* sequence() { return sequence_; } | 123 AllocationSequence* sequence() const { return sequence_; } |
135 bool ready() const { return state_ == STATE_READY; } | 124 bool ready() const { return state_ == STATE_READY; } |
136 bool complete() const { | 125 bool ready_or_complete() const { |
137 // Returns true if candidate allocation has completed one way or another. | 126 return ((state_ == STATE_READY) || (state_ == STATE_COMPLETE)); |
127 } | |
pthatcher1
2016/05/05 21:51:25
Why not just have complete() and then let callers
Taylor Brandstetter
2016/05/06 03:53:35
I was just keeping it the way it was before. I ass
| |
128 // Returns true if candidate allocation has completed one way or another. | |
129 bool complete_or_error() const { | |
138 return ((state_ == STATE_COMPLETE) || (state_ == STATE_ERROR)); | 130 return ((state_ == STATE_COMPLETE) || (state_ == STATE_ERROR)); |
139 } | 131 } |
pthatcher1
2016/05/05 21:51:25
Same here: "complete() || error()"
Taylor Brandstetter
2016/05/06 03:53:35
Done.
| |
140 | 132 |
141 void set_ready() { ASSERT(state_ == STATE_INIT); state_ = STATE_READY; } | 133 void set_ready() { ASSERT(state_ == STATE_INIT); state_ = STATE_READY; } |
142 void set_complete() { | 134 void set_complete() { |
143 state_ = STATE_COMPLETE; | 135 state_ = STATE_COMPLETE; |
144 } | 136 } |
145 void set_error() { | 137 void set_error() { |
146 ASSERT(state_ == STATE_INIT || state_ == STATE_READY); | 138 ASSERT(state_ == STATE_INIT || state_ == STATE_READY); |
147 state_ = STATE_ERROR; | 139 state_ = STATE_ERROR; |
148 } | 140 } |
149 | 141 |
(...skipping 25 matching lines...) Expand all Loading... | |
175 void OnPortComplete(Port* port); | 167 void OnPortComplete(Port* port); |
176 void OnPortError(Port* port); | 168 void OnPortError(Port* port); |
177 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); | 169 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); |
178 void OnPortDestroyed(PortInterface* port); | 170 void OnPortDestroyed(PortInterface* port); |
179 void OnShake(); | 171 void OnShake(); |
180 void MaybeSignalCandidatesAllocationDone(); | 172 void MaybeSignalCandidatesAllocationDone(); |
181 void OnPortAllocationComplete(AllocationSequence* seq); | 173 void OnPortAllocationComplete(AllocationSequence* seq); |
182 PortData* FindPort(Port* port); | 174 PortData* FindPort(Port* port); |
183 void GetNetworks(std::vector<rtc::Network*>* networks); | 175 void GetNetworks(std::vector<rtc::Network*>* networks); |
184 | 176 |
185 bool CheckCandidateFilter(const Candidate& c); | 177 bool CheckCandidateFilter(const Candidate& c) const; |
186 | 178 |
187 BasicPortAllocator* allocator_; | 179 BasicPortAllocator* allocator_; |
188 rtc::Thread* network_thread_; | 180 rtc::Thread* network_thread_; |
189 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; | 181 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
190 rtc::PacketSocketFactory* socket_factory_; | 182 rtc::PacketSocketFactory* socket_factory_; |
191 bool allocation_started_; | 183 bool allocation_started_; |
192 bool network_manager_started_; | 184 bool network_manager_started_; |
193 bool running_; // set when StartGetAllPorts is called | 185 bool running_; // set when StartGetAllPorts is called |
194 bool allocation_sequences_created_; | 186 bool allocation_sequences_created_; |
195 std::vector<PortConfiguration*> configs_; | 187 std::vector<PortConfiguration*> configs_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; | 316 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; |
325 // There will be only one udp port per AllocationSequence. | 317 // There will be only one udp port per AllocationSequence. |
326 UDPPort* udp_port_; | 318 UDPPort* udp_port_; |
327 std::vector<TurnPort*> turn_ports_; | 319 std::vector<TurnPort*> turn_ports_; |
328 int phase_; | 320 int phase_; |
329 }; | 321 }; |
330 | 322 |
331 } // namespace cricket | 323 } // namespace cricket |
332 | 324 |
333 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 325 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
OLD | NEW |