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