OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ |
| 12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ |
| 13 |
| 14 #include <map> |
| 15 #include <string> |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/base/sigslot.h" |
| 19 #include "webrtc/base/sslstreamadapter.h" |
| 20 #include "webrtc/p2p/base/candidate.h" |
| 21 #include "webrtc/p2p/base/transport.h" |
| 22 |
| 23 namespace rtc { |
| 24 class Thread; |
| 25 } |
| 26 |
| 27 namespace cricket { |
| 28 |
| 29 class TransportController : public sigslot::has_slots<>, |
| 30 public rtc::MessageHandler { |
| 31 public: |
| 32 enum ConnectionState { |
| 33 // Default state; either there are no transports, or one is still connecting |
| 34 kConnecting, |
| 35 // At least one transport has failed |
| 36 kFailed, |
| 37 // All transports are connected |
| 38 kConnected, |
| 39 // All transports are connected AND completed |
| 40 kCompleted, |
| 41 }; |
| 42 |
| 43 TransportController(rtc::Thread* signaling_thread, |
| 44 rtc::Thread* worker_thread, |
| 45 PortAllocator* port_allocator); |
| 46 |
| 47 virtual ~TransportController(); |
| 48 |
| 49 rtc::Thread* signaling_thread() const { return signaling_thread_; } |
| 50 rtc::Thread* worker_thread() const { return worker_thread_; } |
| 51 PortAllocator* port_allocator() const { return port_allocator_; } |
| 52 |
| 53 void SetIceConnectionReceivingTimeout(int timeout_ms); |
| 54 void SetIceRole(IceRole ice_role); |
| 55 |
| 56 // Takes ownership of identity and passes it down to transports |
| 57 bool SetIdentity(rtc::SSLIdentity* identity); |
| 58 |
| 59 // Caller owns returned identity |
| 60 bool GetIdentity(const std::string& transport_name, |
| 61 rtc::SSLIdentity** identity); |
| 62 |
| 63 // Caller owns returned certificate |
| 64 bool GetRemoteCertificate(const std::string& transport_name, |
| 65 rtc::SSLCertificate** cert); |
| 66 |
| 67 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); |
| 68 bool SetLocalTransportDescription( |
| 69 const std::string& transport_name, |
| 70 const TransportDescription& tdesc, |
| 71 ContentAction action, |
| 72 std::string* err); |
| 73 bool SetRemoteTransportDescription( |
| 74 const std::string& transport_name, |
| 75 const TransportDescription& tdesc, |
| 76 ContentAction action, |
| 77 std::string* err); |
| 78 bool AddRemoteCandidates( |
| 79 const std::string& transport_name, |
| 80 const Candidates& candidates, |
| 81 std::string* err); |
| 82 |
| 83 bool ReadyForRemoteCandidates(const std::string& transport_name); |
| 84 |
| 85 bool GetSslRole(rtc::SSLRole* role); |
| 86 bool GetStats( |
| 87 const std::string& transport_name, |
| 88 TransportStats* stats); |
| 89 |
| 90 virtual TransportChannel* CreateTransportChannel_w( |
| 91 const std::string& transport_name, int component); |
| 92 virtual void DestroyTransportChannel_w( |
| 93 const std::string& transport_name, int component); |
| 94 |
| 95 void ConnectChannels(); |
| 96 |
| 97 // All of these signals are fired on the signalling thread. |
| 98 sigslot::signal1<ConnectionState> SignalConnectionStateChanged; |
| 99 sigslot::signal1<bool> SignalReceiving; |
| 100 sigslot::signal0<> SignalCandidatesAllocationStarted; |
| 101 // (transport_name, candidates) |
| 102 sigslot::signal2<const std::string&, const Candidates&> SignalCandidatesReady; |
| 103 sigslot::signal0<> SignalCandidatesAllocationDone; |
| 104 |
| 105 protected: |
| 106 virtual void OnMessage(rtc::Message* pmsg); |
| 107 |
| 108 // protected and virtual so we can override it in unit tests. |
| 109 virtual Transport* CreateTransport_w(const std::string& transport_name); |
| 110 |
| 111 // for unit tests |
| 112 const std::map<std::string, Transport*>& transports() { return transports_; } |
| 113 |
| 114 Transport* GetOrCreateTransport_w(const std::string& transport_name); |
| 115 Transport* GetTransport_w(const std::string& transport_name); |
| 116 void DestroyTransport_w(const std::string& transport_name); |
| 117 void DestroyAllTransports_w(); |
| 118 |
| 119 private: |
| 120 void SetIceConnectionReceivingTimeout_w(int timeout_ms); |
| 121 void SetIceRole_w(IceRole ice_role); |
| 122 bool SetIdentity_w(rtc::SSLIdentity* identity); |
| 123 bool GetIdentity_w(const std::string& transport_name, |
| 124 rtc::SSLIdentity** identity); |
| 125 bool GetRemoteCertificate_w(const std::string& transport_name, |
| 126 rtc::SSLCertificate** cert); |
| 127 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version); |
| 128 void ConnectChannels_w(); |
| 129 bool SetLocalTransportDescription_w( |
| 130 const std::string& transport_name, |
| 131 const TransportDescription& tdesc, |
| 132 ContentAction action, |
| 133 std::string* err); |
| 134 bool SetRemoteTransportDescription_w( |
| 135 const std::string& transport_name, |
| 136 const TransportDescription& tdesc, |
| 137 ContentAction action, |
| 138 std::string* err); |
| 139 bool AddRemoteCandidates_w( |
| 140 const std::string& transport_name, |
| 141 const Candidates& candidates, |
| 142 std::string* err); |
| 143 bool ReadyForRemoteCandidates_w(const std::string& transport_name); |
| 144 bool GetSslRole_w(rtc::SSLRole* role); |
| 145 bool GetStats_w( |
| 146 const std::string& transport_name, |
| 147 TransportStats* stats); |
| 148 |
| 149 // Handlers for signals from Transport. |
| 150 void OnTransportConnecting_w(Transport* transport); |
| 151 void OnTransportWritableState_w(Transport* transport); |
| 152 void OnTransportReceivingState_w(Transport* transport); |
| 153 void OnTransportCandidatesAllocationStarted_w(Transport* transport); |
| 154 void OnTransportRouteChange_w(Transport* transport, |
| 155 int component, |
| 156 const Candidate& candidate); |
| 157 void OnTransportCandidatesAllocationDone_w(Transport* transport); |
| 158 void OnTransportRoleConflict_w(); |
| 159 void OnTransportCompleted_w(Transport* transport); |
| 160 void OnTransportFailed_w(Transport* transport); |
| 161 void OnTransportCandidatesReady_w(Transport* transport, |
| 162 const std::vector<Candidate>& candidates); |
| 163 |
| 164 // Update our internal aggregate Transport states, |
| 165 // and signal if they changed. |
| 166 void UpdateState_w(); |
| 167 |
| 168 // Check if allocation done for all Transports, and if so, emit signal |
| 169 void CheckIfCandidatesAllocationDone_w(); |
| 170 |
| 171 rtc::Thread* const signaling_thread_; |
| 172 rtc::Thread* const worker_thread_; |
| 173 PortAllocator* const port_allocator_; |
| 174 |
| 175 // Timeout value in milliseconds for which no ICE connection receives |
| 176 // any packets |
| 177 int ice_receiving_timeout_ms_; |
| 178 IceRole ice_role_; |
| 179 rtc::scoped_ptr<rtc::SSLIdentity> identity_; |
| 180 rtc::SSLProtocolVersion ssl_max_version_; |
| 181 std::map<std::string, Transport*> transports_; |
| 182 |
| 183 // Flag which will be set to true after the first role switch |
| 184 bool ice_role_switch_; |
| 185 uint64 ice_tiebreaker_; |
| 186 |
| 187 // Aggregate state for Transports |
| 188 ConnectionState connection_state_; |
| 189 bool receiving_; |
| 190 bool candidates_allocated_; |
| 191 Transport::CandidateGatheringState candidate_gathering_state_; |
| 192 }; |
| 193 |
| 194 } // namespace cricket |
| 195 |
| 196 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ |
OLD | NEW |