| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 PortInterface* origin_port_; | 46 PortInterface* origin_port_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // P2PTransportChannel manages the candidates and connection process to keep | 49 // P2PTransportChannel manages the candidates and connection process to keep |
| 50 // two P2P clients connected to each other. | 50 // two P2P clients connected to each other. |
| 51 class P2PTransportChannel : public TransportChannelImpl, | 51 class P2PTransportChannel : public TransportChannelImpl, |
| 52 public rtc::MessageHandler { | 52 public rtc::MessageHandler { |
| 53 public: | 53 public: |
| 54 P2PTransportChannel(const std::string& content_name, | 54 P2PTransportChannel(const std::string& transport_name, |
| 55 int component, | 55 int component, |
| 56 P2PTransport* transport, | 56 P2PTransport* transport, |
| 57 PortAllocator *allocator); | 57 PortAllocator* allocator); |
| 58 ~P2PTransportChannel() override; | 58 virtual ~P2PTransportChannel(); |
| 59 | 59 |
| 60 // From TransportChannelImpl: | 60 // From TransportChannelImpl: |
| 61 Transport* GetTransport() override { return transport_; } | 61 Transport* GetTransport() override { return transport_; } |
| 62 TransportChannelState GetState() const override; | 62 TransportChannelState GetState() const override; |
| 63 void SetIceRole(IceRole role) override; | 63 void SetIceRole(IceRole role) override; |
| 64 IceRole GetIceRole() const override { return ice_role_; } | 64 IceRole GetIceRole() const override { return ice_role_; } |
| 65 void SetIceTiebreaker(uint64 tiebreaker) override; | 65 void SetIceTiebreaker(uint64 tiebreaker) override; |
| 66 void SetIceCredentials(const std::string& ice_ufrag, | 66 void SetIceCredentials(const std::string& ice_ufrag, |
| 67 const std::string& ice_pwd) override; | 67 const std::string& ice_pwd) override; |
| 68 void SetRemoteIceCredentials(const std::string& ice_ufrag, | 68 void SetRemoteIceCredentials(const std::string& ice_ufrag, |
| 69 const std::string& ice_pwd) override; | 69 const std::string& ice_pwd) override; |
| 70 void SetRemoteIceMode(IceMode mode) override; | 70 void SetRemoteIceMode(IceMode mode) override; |
| 71 void Connect() override; | 71 void Connect() override; |
| 72 void OnSignalingReady() override; | 72 void MaybeStartGathering() override; |
| 73 void OnCandidate(const Candidate& candidate) override; | 73 IceGatheringState gathering_state() const override { |
| 74 return gathering_state_; |
| 75 } |
| 76 void AddRemoteCandidate(const Candidate& candidate) override; |
| 74 // Sets the receiving timeout in milliseconds. | 77 // Sets the receiving timeout in milliseconds. |
| 75 // This also sets the check_receiving_delay proportionally. | 78 // This also sets the check_receiving_delay proportionally. |
| 76 void SetReceivingTimeout(int receiving_timeout_ms) override; | 79 void SetReceivingTimeout(int receiving_timeout_ms) override; |
| 77 | 80 |
| 78 // From TransportChannel: | 81 // From TransportChannel: |
| 79 int SendPacket(const char *data, size_t len, | 82 int SendPacket(const char* data, |
| 80 const rtc::PacketOptions& options, int flags) override; | 83 size_t len, |
| 84 const rtc::PacketOptions& options, |
| 85 int flags) override; |
| 81 int SetOption(rtc::Socket::Option opt, int value) override; | 86 int SetOption(rtc::Socket::Option opt, int value) override; |
| 82 bool GetOption(rtc::Socket::Option opt, int* value) override; | 87 bool GetOption(rtc::Socket::Option opt, int* value) override; |
| 83 int GetError() override { return error_; } | 88 int GetError() override { return error_; } |
| 84 bool GetStats(std::vector<ConnectionInfo>* stats) override; | 89 bool GetStats(std::vector<ConnectionInfo>* stats) override; |
| 85 | 90 |
| 86 const Connection* best_connection() const { return best_connection_; } | 91 const Connection* best_connection() const { return best_connection_; } |
| 87 void set_incoming_only(bool value) { incoming_only_ = value; } | 92 void set_incoming_only(bool value) { incoming_only_ = value; } |
| 88 | 93 |
| 89 // Note: This is only for testing purpose. | 94 // Note: This is only for testing purpose. |
| 90 // |ports_| should not be changed from outside. | 95 // |ports_| should not be changed from outside. |
| 91 const std::vector<PortInterface*>& ports() { return ports_; } | 96 const std::vector<PortInterface*>& ports() { return ports_; } |
| 92 | 97 |
| 93 IceMode remote_ice_mode() const { return remote_ice_mode_; } | 98 IceMode remote_ice_mode() const { return remote_ice_mode_; } |
| 94 | 99 |
| 95 // DTLS methods. | 100 // DTLS methods. |
| 96 bool IsDtlsActive() const override { return false; } | 101 bool IsDtlsActive() const override { return false; } |
| 97 | 102 |
| 98 // Default implementation. | 103 // Default implementation. |
| 99 bool GetSslRole(rtc::SSLRole* role) const override { | 104 bool GetSslRole(rtc::SSLRole* role) const override { return false; } |
| 100 return false; | |
| 101 } | |
| 102 | 105 |
| 103 bool SetSslRole(rtc::SSLRole role) override { | 106 bool SetSslRole(rtc::SSLRole role) override { return false; } |
| 104 return false; | |
| 105 } | |
| 106 | 107 |
| 107 // Set up the ciphers to use for DTLS-SRTP. | 108 // Set up the ciphers to use for DTLS-SRTP. |
| 108 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { | 109 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { |
| 109 return false; | 110 return false; |
| 110 } | 111 } |
| 111 | 112 |
| 112 // Find out which DTLS-SRTP cipher was negotiated. | 113 // Find out which DTLS-SRTP cipher was negotiated. |
| 113 bool GetSrtpCipher(std::string* cipher) override { | 114 bool GetSrtpCipher(std::string* cipher) override { return false; } |
| 114 return false; | |
| 115 } | |
| 116 | 115 |
| 117 // Find out which DTLS cipher was negotiated. | 116 // Find out which DTLS cipher was negotiated. |
| 118 bool GetSslCipher(std::string* cipher) override { | 117 bool GetSslCipher(std::string* cipher) override { return false; } |
| 119 return false; | |
| 120 } | |
| 121 | 118 |
| 122 // Returns null because the channel is not encrypted by default. | 119 // Returns null because the channel is not encrypted by default. |
| 123 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { | 120 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { |
| 124 return nullptr; | 121 return nullptr; |
| 125 } | 122 } |
| 126 | 123 |
| 127 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override { | 124 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert) const override { |
| 128 return false; | 125 return false; |
| 129 } | 126 } |
| 130 | 127 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 158 | 155 |
| 159 // Public for unit tests. | 156 // Public for unit tests. |
| 160 Connection* FindNextPingableConnection(); | 157 Connection* FindNextPingableConnection(); |
| 161 | 158 |
| 162 private: | 159 private: |
| 163 rtc::Thread* thread() { return worker_thread_; } | 160 rtc::Thread* thread() { return worker_thread_; } |
| 164 PortAllocatorSession* allocator_session() { | 161 PortAllocatorSession* allocator_session() { |
| 165 return allocator_sessions_.back(); | 162 return allocator_sessions_.back(); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void Allocate(); | |
| 169 void UpdateConnectionStates(); | 165 void UpdateConnectionStates(); |
| 170 void RequestSort(); | 166 void RequestSort(); |
| 171 void SortConnections(); | 167 void SortConnections(); |
| 172 void SwitchBestConnectionTo(Connection* conn); | 168 void SwitchBestConnectionTo(Connection* conn); |
| 173 void UpdateChannelState(); | 169 void UpdateChannelState(); |
| 174 void HandleWritable(); | 170 void HandleWritable(); |
| 175 void HandleNotWritable(); | 171 void HandleNotWritable(); |
| 176 void HandleAllTimedOut(); | 172 void HandleAllTimedOut(); |
| 177 | 173 |
| 178 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; | 174 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 206 void OnRoleConflict(PortInterface* port); | 202 void OnRoleConflict(PortInterface* port); |
| 207 | 203 |
| 208 void OnConnectionStateChange(Connection* connection); | 204 void OnConnectionStateChange(Connection* connection); |
| 209 void OnReadPacket(Connection *connection, const char *data, size_t len, | 205 void OnReadPacket(Connection *connection, const char *data, size_t len, |
| 210 const rtc::PacketTime& packet_time); | 206 const rtc::PacketTime& packet_time); |
| 211 void OnReadyToSend(Connection* connection); | 207 void OnReadyToSend(Connection* connection); |
| 212 void OnConnectionDestroyed(Connection *connection); | 208 void OnConnectionDestroyed(Connection *connection); |
| 213 | 209 |
| 214 void OnNominated(Connection* conn); | 210 void OnNominated(Connection* conn); |
| 215 | 211 |
| 216 void OnMessage(rtc::Message *pmsg) override; | 212 void OnMessage(rtc::Message* pmsg) override; |
| 217 void OnSort(); | 213 void OnSort(); |
| 218 void OnPing(); | 214 void OnPing(); |
| 219 | 215 |
| 220 void OnCheckReceiving(); | 216 void OnCheckReceiving(); |
| 221 | 217 |
| 222 void PruneConnections(); | 218 void PruneConnections(); |
| 223 Connection* best_nominated_connection() const; | 219 Connection* best_nominated_connection() const; |
| 224 | 220 |
| 225 P2PTransport* transport_; | 221 P2PTransport* transport_; |
| 226 PortAllocator *allocator_; | 222 PortAllocator* allocator_; |
| 227 rtc::Thread *worker_thread_; | 223 rtc::Thread* worker_thread_; |
| 228 bool incoming_only_; | 224 bool incoming_only_; |
| 229 bool waiting_for_signaling_; | |
| 230 int error_; | 225 int error_; |
| 231 std::vector<PortAllocatorSession*> allocator_sessions_; | 226 std::vector<PortAllocatorSession*> allocator_sessions_; |
| 232 std::vector<PortInterface *> ports_; | 227 std::vector<PortInterface *> ports_; |
| 233 std::vector<Connection *> connections_; | 228 std::vector<Connection *> connections_; |
| 234 Connection* best_connection_; | 229 Connection* best_connection_; |
| 235 // Connection selected by the controlling agent. This should be used only | 230 // Connection selected by the controlling agent. This should be used only |
| 236 // at controlled side when protocol type is RFC5245. | 231 // at controlled side when protocol type is RFC5245. |
| 237 Connection* pending_best_connection_; | 232 Connection* pending_best_connection_; |
| 238 std::vector<RemoteCandidate> remote_candidates_; | 233 std::vector<RemoteCandidate> remote_candidates_; |
| 239 bool sort_dirty_; // indicates whether another sort is needed right now | 234 bool sort_dirty_; // indicates whether another sort is needed right now |
| 240 bool was_writable_; | 235 bool was_writable_; |
| 236 bool had_connection_ = false; // if connections_ has ever been nonempty |
| 241 typedef std::map<rtc::Socket::Option, int> OptionMap; | 237 typedef std::map<rtc::Socket::Option, int> OptionMap; |
| 242 OptionMap options_; | 238 OptionMap options_; |
| 243 std::string ice_ufrag_; | 239 std::string ice_ufrag_; |
| 244 std::string ice_pwd_; | 240 std::string ice_pwd_; |
| 245 std::string remote_ice_ufrag_; | 241 std::string remote_ice_ufrag_; |
| 246 std::string remote_ice_pwd_; | 242 std::string remote_ice_pwd_; |
| 247 IceMode remote_ice_mode_; | 243 IceMode remote_ice_mode_; |
| 248 IceRole ice_role_; | 244 IceRole ice_role_; |
| 249 uint64 tiebreaker_; | 245 uint64 tiebreaker_; |
| 250 uint32 remote_candidate_generation_; | 246 uint32 remote_candidate_generation_; |
| 247 IceGatheringState gathering_state_; |
| 251 | 248 |
| 252 int check_receiving_delay_; | 249 int check_receiving_delay_; |
| 253 int receiving_timeout_; | 250 int receiving_timeout_; |
| 254 | 251 |
| 255 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 252 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
| 256 }; | 253 }; |
| 257 | 254 |
| 258 } // namespace cricket | 255 } // namespace cricket |
| 259 | 256 |
| 260 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 257 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
| OLD | NEW |