OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 5 #ifndef REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
6 #define REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 6 #define REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
7 | 7 |
8 #include <array> | |
8 #include <list> | 9 #include <list> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "remoting/protocol/ice_config.h" | 16 #include "remoting/protocol/ice_config.h" |
16 #include "remoting/protocol/network_settings.h" | 17 #include "remoting/protocol/network_settings.h" |
17 #include "remoting/protocol/transport.h" | 18 #include "remoting/protocol/transport.h" |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 | 21 |
21 class SignalStrategy; | 22 class SignalStrategy; |
22 class UrlRequestFactory; | 23 class UrlRequestFactory; |
23 | 24 |
24 namespace protocol { | 25 namespace protocol { |
25 | 26 |
26 class PortAllocatorFactory; | 27 class PortAllocatorFactory; |
27 class IceConfigRequest; | 28 class IceConfigRequest; |
28 | 29 |
29 // TransportContext is responsible for storing all parameters required for | 30 // TransportContext is responsible for storing all parameters required for |
30 // P2P transport initialization. It's also responsible for fetching STUN and | 31 // P2P transport initialization. It's also responsible for fetching STUN and |
31 // TURN configuration. | 32 // TURN configuration. |
32 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { | 33 class TransportContext : public base::RefCountedThreadSafe<TransportContext> { |
33 public: | 34 public: |
35 enum RelayMode { | |
36 GTURN, | |
37 TURN | |
38 }; | |
39 static const int kNumRelayModes = RelayMode::TURN + 1; | |
garykac
2016/03/15 20:38:59
The enum should end with MAX_RELAYMODE (or somethi
Sergey Ulanov
2016/03/15 21:54:53
That would make the compiler complain that MAX_REL
garykac
2016/03/16 00:58:21
enum RelayMode {
GTURN,
TURN,
LAST_RELAYMODE
Sergey Ulanov
2016/03/16 18:34:13
Done.
| |
40 | |
34 typedef base::Callback<void(const IceConfig& ice_config)> | 41 typedef base::Callback<void(const IceConfig& ice_config)> |
35 GetIceConfigCallback; | 42 GetIceConfigCallback; |
36 | 43 |
37 static scoped_refptr<TransportContext> ForTests(TransportRole role); | 44 static scoped_refptr<TransportContext> ForTests(TransportRole role); |
38 | 45 |
39 TransportContext(SignalStrategy* signal_strategy, | 46 TransportContext(SignalStrategy* signal_strategy, |
40 scoped_ptr<PortAllocatorFactory> port_allocator_factory, | 47 scoped_ptr<PortAllocatorFactory> port_allocator_factory, |
41 scoped_ptr<UrlRequestFactory> url_request_factory, | 48 scoped_ptr<UrlRequestFactory> url_request_factory, |
42 const NetworkSettings& network_settings, | 49 const NetworkSettings& network_settings, |
43 TransportRole role); | 50 TransportRole role); |
44 | 51 |
45 // Enables standard TURN servers. | 52 void set_ice_config_url(const std::string& ice_config_url) { |
46 void UseTurn(const std::string& ice_config_url) { | |
47 ice_config_url_ = ice_config_url; | 53 ice_config_url_ = ice_config_url; |
48 } | 54 } |
49 | 55 |
56 // Sets relay mode for all future calls of GetIceConfig(). Doesn't affect | |
57 // previous GetIceConfig() requests. | |
58 void set_relay_mode(RelayMode relay_mode) { relay_mode_ = relay_mode; } | |
59 | |
50 // Prepares fresh JingleInfo. It may be called while connection is being | 60 // Prepares fresh JingleInfo. It may be called while connection is being |
51 // negotiated to minimize the chance that the following GetIceConfig() will | 61 // negotiated to minimize the chance that the following GetIceConfig() will |
52 // be blocking. | 62 // be blocking. |
53 void Prepare(); | 63 void Prepare(); |
54 | 64 |
55 // Requests fresh STUN and TURN information. | 65 // Requests fresh STUN and TURN information. |
56 void GetIceConfig(const GetIceConfigCallback& callback); | 66 void GetIceConfig(const GetIceConfigCallback& callback); |
57 | 67 |
58 PortAllocatorFactory* port_allocator_factory() { | 68 PortAllocatorFactory* port_allocator_factory() { |
59 return port_allocator_factory_.get(); | 69 return port_allocator_factory_.get(); |
60 } | 70 } |
61 UrlRequestFactory* url_request_factory() { | 71 UrlRequestFactory* url_request_factory() { |
62 return url_request_factory_.get(); | 72 return url_request_factory_.get(); |
63 } | 73 } |
64 const NetworkSettings& network_settings() const { return network_settings_; } | 74 const NetworkSettings& network_settings() const { return network_settings_; } |
65 TransportRole role() const { return role_; } | 75 TransportRole role() const { return role_; } |
66 | 76 |
67 private: | 77 private: |
68 friend class base::RefCountedThreadSafe<TransportContext>; | 78 friend class base::RefCountedThreadSafe<TransportContext>; |
69 | 79 |
70 ~TransportContext(); | 80 ~TransportContext(); |
71 | 81 |
72 void EnsureFreshJingleInfo(); | 82 void EnsureFreshIceConfig(); |
73 void OnIceConfig(const IceConfig& ice_config); | 83 void OnIceConfig(RelayMode relay_mode, const IceConfig& ice_config); |
74 | 84 |
75 SignalStrategy* signal_strategy_; | 85 SignalStrategy* signal_strategy_; |
76 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; | 86 scoped_ptr<PortAllocatorFactory> port_allocator_factory_; |
77 scoped_ptr<UrlRequestFactory> url_request_factory_; | 87 scoped_ptr<UrlRequestFactory> url_request_factory_; |
78 NetworkSettings network_settings_; | 88 NetworkSettings network_settings_; |
79 TransportRole role_; | 89 TransportRole role_; |
80 | 90 |
81 std::string ice_config_url_; | 91 std::string ice_config_url_; |
92 RelayMode relay_mode_ = RelayMode::GTURN; | |
82 | 93 |
83 scoped_ptr<IceConfigRequest> ice_config_request_; | 94 std::array<scoped_ptr<IceConfigRequest>, kNumRelayModes> ice_config_request_; |
95 std::array<IceConfig, kNumRelayModes> ice_config_; | |
84 | 96 |
85 IceConfig ice_config_; | 97 // When there is an active |ice_config_request_| stores list of callbacks to |
86 | |
87 // When there is an active |jingle_info_request_| stores list of callbacks to | |
88 // be called once the request is finished. | 98 // be called once the request is finished. |
89 std::list<GetIceConfigCallback> pending_ice_config_callbacks_; | 99 std::array<std::list<GetIceConfigCallback>, kNumRelayModes> |
100 pending_ice_config_callbacks_; | |
90 | 101 |
91 DISALLOW_COPY_AND_ASSIGN(TransportContext); | 102 DISALLOW_COPY_AND_ASSIGN(TransportContext); |
92 }; | 103 }; |
93 | 104 |
94 } // namespace protocol | 105 } // namespace protocol |
95 } // namespace remoting | 106 } // namespace remoting |
96 | 107 |
97 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ | 108 #endif // REMOTING_PROTOCOL_TRANSPORT_CONTEXT_H_ |
OLD | NEW |