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