| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_JINGLE_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "remoting/protocol/authenticator.h" | 17 #include "remoting/protocol/authenticator.h" |
| 18 #include "remoting/protocol/datagram_channel_factory.h" | 18 #include "remoting/protocol/datagram_channel_factory.h" |
| 19 #include "remoting/protocol/jingle_messages.h" | 19 #include "remoting/protocol/jingle_messages.h" |
| 20 #include "remoting/protocol/session.h" | 20 #include "remoting/protocol/session.h" |
| 21 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
| 22 #include "remoting/protocol/transport.h" | 22 #include "remoting/protocol/transport.h" |
| 23 #include "remoting/signaling/iq_sender.h" | 23 #include "remoting/signaling/iq_sender.h" |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 namespace protocol { | 26 namespace protocol { |
| 27 | 27 |
| 28 class ChannelMultiplexer; |
| 28 class JingleSessionManager; | 29 class JingleSessionManager; |
| 30 class PseudoTcpChannelFactory; |
| 29 class QuicChannelFactory; | 31 class QuicChannelFactory; |
| 32 class SecureChannelFactory; |
| 30 | 33 |
| 31 // JingleSessionManager and JingleSession implement the subset of the | 34 // JingleSessionManager and JingleSession implement the subset of the |
| 32 // Jingle protocol used in Chromoting. Instances of this class are | 35 // Jingle protocol used in Chromoting. Instances of this class are |
| 33 // created by the JingleSessionManager. | 36 // created by the JingleSessionManager. |
| 34 class JingleSession : public base::NonThreadSafe, | 37 class JingleSession : public base::NonThreadSafe, |
| 35 public Session, | 38 public Session, |
| 36 public TransportSession::EventHandler { | 39 public DatagramChannelFactory, |
| 40 public Transport::EventHandler { |
| 37 public: | 41 public: |
| 38 ~JingleSession() override; | 42 ~JingleSession() override; |
| 39 | 43 |
| 40 // Session interface. | 44 // Session interface. |
| 41 void SetEventHandler(Session::EventHandler* event_handler) override; | 45 void SetEventHandler(Session::EventHandler* event_handler) override; |
| 42 ErrorCode error() override; | 46 ErrorCode error() override; |
| 43 const std::string& jid() override; | 47 const std::string& jid() override; |
| 44 const SessionConfig& config() override; | 48 const SessionConfig& config() override; |
| 45 TransportSession* GetTransportSession() override; | 49 StreamChannelFactory* GetTransportChannelFactory() override; |
| 50 StreamChannelFactory* GetMultiplexedChannelFactory() override; |
| 46 StreamChannelFactory* GetQuicChannelFactory() override; | 51 StreamChannelFactory* GetQuicChannelFactory() override; |
| 47 void Close() override; | 52 void Close() override; |
| 48 | 53 |
| 54 // DatagramChannelFactory interface. |
| 55 void CreateChannel(const std::string& name, |
| 56 const ChannelCreatedCallback& callback) override; |
| 57 void CancelChannelCreation(const std::string& name) override; |
| 58 |
| 59 // Transport::EventHandler interface. |
| 60 void OnTransportIceCredentials(Transport* transport, |
| 61 const std::string& ufrag, |
| 62 const std::string& password) override; |
| 63 void OnTransportCandidate(Transport* transport, |
| 64 const cricket::Candidate& candidate) override; |
| 65 void OnTransportRouteChange(Transport* transport, |
| 66 const TransportRoute& route) override; |
| 67 void OnTransportFailed(Transport* transport) override; |
| 68 void OnTransportDeleted(Transport* transport) override; |
| 69 |
| 49 private: | 70 private: |
| 50 friend class JingleSessionManager; | 71 friend class JingleSessionManager; |
| 51 | 72 |
| 73 typedef std::map<std::string, Transport*> ChannelsMap; |
| 52 typedef base::Callback<void(JingleMessageReply::ErrorType)> ReplyCallback; | 74 typedef base::Callback<void(JingleMessageReply::ErrorType)> ReplyCallback; |
| 53 | 75 |
| 54 explicit JingleSession(JingleSessionManager* session_manager); | 76 explicit JingleSession(JingleSessionManager* session_manager); |
| 55 | 77 |
| 56 // Start connection by sending session-initiate message. | 78 // Start connection by sending session-initiate message. |
| 57 void StartConnection(const std::string& peer_jid, | 79 void StartConnection(const std::string& peer_jid, |
| 58 scoped_ptr<Authenticator> authenticator); | 80 scoped_ptr<Authenticator> authenticator); |
| 59 | 81 |
| 82 // Passes transport info to a new |channel| in case it was received before the |
| 83 // channel was created. |
| 84 void AddPendingRemoteTransportInfo(Transport* channel); |
| 85 |
| 60 // Called by JingleSessionManager for incoming connections. | 86 // Called by JingleSessionManager for incoming connections. |
| 61 void InitializeIncomingConnection(const JingleMessage& initiate_message, | 87 void InitializeIncomingConnection(const JingleMessage& initiate_message, |
| 62 scoped_ptr<Authenticator> authenticator); | 88 scoped_ptr<Authenticator> authenticator); |
| 63 void AcceptIncomingConnection(const JingleMessage& initiate_message); | 89 void AcceptIncomingConnection(const JingleMessage& initiate_message); |
| 64 | 90 |
| 65 // Sends |message| to the peer. The session is closed if the send fails or no | 91 // Sends |message| to the peer. The session is closed if the send fails or no |
| 66 // response is received within a reasonable time. All other responses are | 92 // response is received within a reasonable time. All other responses are |
| 67 // ignored. | 93 // ignored. |
| 68 void SendMessage(const JingleMessage& message); | 94 void SendMessage(const JingleMessage& message); |
| 69 | 95 |
| 70 // Iq response handler. | 96 // Iq response handler. |
| 71 void OnMessageResponse(JingleMessage::ActionType request_type, | 97 void OnMessageResponse(JingleMessage::ActionType request_type, |
| 72 IqRequest* request, | 98 IqRequest* request, |
| 73 const buzz::XmlElement* response); | 99 const buzz::XmlElement* response); |
| 74 | 100 |
| 75 // TransportSession::Delegate interface. | 101 // Creates empty |pending_transport_info_message_| and schedules timer for |
| 76 void OnOutgoingTransportInfo( | 102 // SentTransportInfo() to sent the message later. |
| 77 scoped_ptr<buzz::XmlElement> transport_info) override; | 103 void EnsurePendingTransportInfoMessage(); |
| 78 void OnTransportRouteChange(const std::string& component, | 104 |
| 79 const TransportRoute& route) override; | 105 // Sends transport-info message with candidates from |pending_candidates_|. |
| 80 void OnTransportError(ErrorCode error) override; | 106 void SendTransportInfo(); |
| 81 | 107 |
| 82 // Response handler for transport-info responses. Transport-info timeouts are | 108 // Response handler for transport-info responses. Transport-info timeouts are |
| 83 // ignored and don't terminate connection. | 109 // ignored and don't terminate connection. |
| 84 void OnTransportInfoResponse(IqRequest* request, | 110 void OnTransportInfoResponse(IqRequest* request, |
| 85 const buzz::XmlElement* response); | 111 const buzz::XmlElement* response); |
| 86 | 112 |
| 87 // Called by JingleSessionManager on incoming |message|. Must call | 113 // Called by JingleSessionManager on incoming |message|. Must call |
| 88 // |reply_callback| to send reply message before sending any other | 114 // |reply_callback| to send reply message before sending any other |
| 89 // messages. | 115 // messages. |
| 90 void OnIncomingMessage(const JingleMessage& message, | 116 void OnIncomingMessage(const JingleMessage& message, |
| 91 const ReplyCallback& reply_callback); | 117 const ReplyCallback& reply_callback); |
| 92 | 118 |
| 93 // Message handlers for incoming messages. | 119 // Message handlers for incoming messages. |
| 94 void OnAccept(const JingleMessage& message, | 120 void OnAccept(const JingleMessage& message, |
| 95 const ReplyCallback& reply_callback); | 121 const ReplyCallback& reply_callback); |
| 96 void OnSessionInfo(const JingleMessage& message, | 122 void OnSessionInfo(const JingleMessage& message, |
| 97 const ReplyCallback& reply_callback); | 123 const ReplyCallback& reply_callback); |
| 98 void OnTerminate(const JingleMessage& message, | 124 void OnTerminate(const JingleMessage& message, |
| 99 const ReplyCallback& reply_callback); | 125 const ReplyCallback& reply_callback); |
| 126 void ProcessTransportInfo(const JingleMessage& message); |
| 100 | 127 |
| 101 // Called from OnAccept() to initialize session config. | 128 // Called from OnAccept() to initialize session config. |
| 102 bool InitializeConfigFromDescription(const ContentDescription* description); | 129 bool InitializeConfigFromDescription(const ContentDescription* description); |
| 103 | 130 |
| 104 // Called after the initial incoming authenticator message is processed. | 131 // Called after the initial incoming authenticator message is processed. |
| 105 void ContinueAcceptIncomingConnection(); | 132 void ContinueAcceptIncomingConnection(); |
| 106 | 133 |
| 107 // Called after subsequent authenticator messages are processed. | 134 // Called after subsequent authenticator messages are processed. |
| 108 void ProcessAuthenticationStep(); | 135 void ProcessAuthenticationStep(); |
| 109 | 136 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 129 Session::EventHandler* event_handler_; | 156 Session::EventHandler* event_handler_; |
| 130 | 157 |
| 131 std::string session_id_; | 158 std::string session_id_; |
| 132 State state_; | 159 State state_; |
| 133 ErrorCode error_; | 160 ErrorCode error_; |
| 134 | 161 |
| 135 scoped_ptr<SessionConfig> config_; | 162 scoped_ptr<SessionConfig> config_; |
| 136 | 163 |
| 137 scoped_ptr<Authenticator> authenticator_; | 164 scoped_ptr<Authenticator> authenticator_; |
| 138 | 165 |
| 139 scoped_ptr<TransportSession> transport_session_; | |
| 140 | |
| 141 // Pending Iq requests. Used for all messages except transport-info. | 166 // Pending Iq requests. Used for all messages except transport-info. |
| 142 std::set<IqRequest*> pending_requests_; | 167 std::set<IqRequest*> pending_requests_; |
| 143 | 168 |
| 144 // Pending transport-info requests. | 169 // Pending transport-info requests. |
| 145 std::list<IqRequest*> transport_info_requests_; | 170 std::list<IqRequest*> transport_info_requests_; |
| 146 | 171 |
| 172 ChannelsMap channels_; |
| 173 scoped_ptr<PseudoTcpChannelFactory> pseudotcp_channel_factory_; |
| 174 scoped_ptr<SecureChannelFactory> secure_channel_factory_; |
| 175 scoped_ptr<ChannelMultiplexer> channel_multiplexer_; |
| 147 scoped_ptr<QuicChannelFactory> quic_channel_factory_; | 176 scoped_ptr<QuicChannelFactory> quic_channel_factory_; |
| 148 | 177 |
| 178 scoped_ptr<JingleMessage> pending_transport_info_message_; |
| 179 base::OneShotTimer transport_info_timer_; |
| 180 |
| 181 // Pending remote transport info received before the local channels were |
| 182 // created. |
| 183 std::list<JingleMessage::IceCredentials> pending_remote_ice_credentials_; |
| 184 std::list<JingleMessage::NamedCandidate> pending_remote_candidates_; |
| 185 |
| 149 base::WeakPtrFactory<JingleSession> weak_factory_; | 186 base::WeakPtrFactory<JingleSession> weak_factory_; |
| 150 | 187 |
| 151 DISALLOW_COPY_AND_ASSIGN(JingleSession); | 188 DISALLOW_COPY_AND_ASSIGN(JingleSession); |
| 152 }; | 189 }; |
| 153 | 190 |
| 154 } // namespace protocol | 191 } // namespace protocol |
| 155 } // namespace remoting | 192 } // namespace remoting |
| 156 | 193 |
| 157 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 194 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| OLD | NEW |