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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/rand_util.h" |
| 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
15 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
16 #include "crypto/rsa_private_key.h" | 18 #include "crypto/rsa_private_key.h" |
17 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
18 #include "remoting/protocol/authenticator.h" | 20 #include "remoting/protocol/authenticator.h" |
19 #include "remoting/protocol/datagram_channel_factory.h" | 21 #include "remoting/protocol/datagram_channel_factory.h" |
20 #include "remoting/protocol/jingle_messages.h" | 22 #include "remoting/protocol/jingle_messages.h" |
21 #include "remoting/protocol/session.h" | 23 #include "remoting/protocol/session.h" |
22 #include "remoting/protocol/session_config.h" | 24 #include "remoting/protocol/session_config.h" |
23 #include "remoting/signaling/iq_sender.h" | 25 #include "remoting/signaling/iq_sender.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const buzz::XmlElement* response); | 76 const buzz::XmlElement* response); |
75 | 77 |
76 // Response handler for transport-info responses. Transport-info timeouts are | 78 // Response handler for transport-info responses. Transport-info timeouts are |
77 // ignored and don't terminate connection. | 79 // ignored and don't terminate connection. |
78 void OnTransportInfoResponse(IqRequest* request, | 80 void OnTransportInfoResponse(IqRequest* request, |
79 const buzz::XmlElement* response); | 81 const buzz::XmlElement* response); |
80 | 82 |
81 // Called by JingleSessionManager on incoming |message|. Must call | 83 // Called by JingleSessionManager on incoming |message|. Must call |
82 // |reply_callback| to send reply message before sending any other | 84 // |reply_callback| to send reply message before sending any other |
83 // messages. | 85 // messages. |
84 void OnIncomingMessage(std::unique_ptr<JingleMessage> message, | 86 void OnIncomingMessage(const std::string& id, |
| 87 std::unique_ptr<JingleMessage> message, |
85 const ReplyCallback& reply_callback); | 88 const ReplyCallback& reply_callback); |
86 | 89 |
| 90 // Called by OnIncomingMessage() to process the incoming Jingle messages |
| 91 // in the same order that they are sent. |
| 92 void ProcessIncomingMessage(std::unique_ptr<JingleMessage> message, |
| 93 const ReplyCallback& reply_callback); |
| 94 |
87 // Message handlers for incoming messages. | 95 // Message handlers for incoming messages. |
88 void OnAccept(std::unique_ptr<JingleMessage> message, | 96 void OnAccept(std::unique_ptr<JingleMessage> message, |
89 const ReplyCallback& reply_callback); | 97 const ReplyCallback& reply_callback); |
90 void OnSessionInfo(std::unique_ptr<JingleMessage> message, | 98 void OnSessionInfo(std::unique_ptr<JingleMessage> message, |
91 const ReplyCallback& reply_callback); | 99 const ReplyCallback& reply_callback); |
92 void OnTerminate(std::unique_ptr<JingleMessage> message, | 100 void OnTerminate(std::unique_ptr<JingleMessage> message, |
93 const ReplyCallback& reply_callback); | 101 const ReplyCallback& reply_callback); |
94 | 102 |
95 // Called from OnAccept() to initialize session config. | 103 // Called from OnAccept() to initialize session config. |
96 bool InitializeConfigFromDescription(const ContentDescription* description); | 104 bool InitializeConfigFromDescription(const ContentDescription* description); |
97 | 105 |
98 // Called after the initial incoming authenticator message is processed. | 106 // Called after the initial incoming authenticator message is processed. |
99 void ContinueAcceptIncomingConnection(); | 107 void ContinueAcceptIncomingConnection(); |
100 | 108 |
101 // Called after subsequent authenticator messages are processed. | 109 // Called after subsequent authenticator messages are processed. |
102 void ProcessAuthenticationStep(); | 110 void ProcessAuthenticationStep(); |
103 | 111 |
104 // Called after the authenticating step is finished. | 112 // Called after the authenticating step is finished. |
105 void ContinueAuthenticationStep(); | 113 void ContinueAuthenticationStep(); |
106 | 114 |
107 // Called when authentication is finished. | 115 // Called when authentication is finished. |
108 void OnAuthenticated(); | 116 void OnAuthenticated(); |
109 | 117 |
110 // Sets |state_| to |new_state| and calls state change callback. | 118 // Sets |state_| to |new_state| and calls state change callback. |
111 void SetState(State new_state); | 119 void SetState(State new_state); |
112 | 120 |
113 // Returns true if the state of the session is not CLOSED or FAILED | 121 // Returns true if the state of the session is not CLOSED or FAILED |
114 bool is_session_active(); | 122 bool is_session_active(); |
115 | 123 |
| 124 // Returns the value of the ID attribute of the next outgoing set IQ with the |
| 125 // sequence ID encoded. |
| 126 std::string GetNextOutgoingId(); |
| 127 |
116 base::ThreadChecker thread_checker_; | 128 base::ThreadChecker thread_checker_; |
117 | 129 |
118 JingleSessionManager* session_manager_; | 130 JingleSessionManager* session_manager_; |
119 SignalingAddress peer_address_; | 131 SignalingAddress peer_address_; |
120 Session::EventHandler* event_handler_; | 132 Session::EventHandler* event_handler_; |
121 | 133 |
122 std::string session_id_; | 134 std::string session_id_; |
123 State state_; | 135 State state_; |
124 ErrorCode error_; | 136 ErrorCode error_; |
125 | 137 |
126 std::unique_ptr<SessionConfig> config_; | 138 std::unique_ptr<SessionConfig> config_; |
127 | 139 |
128 std::unique_ptr<Authenticator> authenticator_; | 140 std::unique_ptr<Authenticator> authenticator_; |
129 | 141 |
130 Transport* transport_ = nullptr; | 142 Transport* transport_ = nullptr; |
131 | 143 |
132 // Pending Iq requests. Used for all messages except transport-info. | 144 // Pending Iq requests. Used for all messages except transport-info. |
133 std::set<std::unique_ptr<IqRequest>> pending_requests_; | 145 std::set<std::unique_ptr<IqRequest>> pending_requests_; |
134 | 146 |
135 // Pending transport-info requests. | 147 // Pending transport-info requests. |
136 std::list<std::unique_ptr<IqRequest>> transport_info_requests_; | 148 std::list<std::unique_ptr<IqRequest>> transport_info_requests_; |
137 | 149 |
| 150 struct PendingMessage { |
| 151 PendingMessage(std::unique_ptr<JingleMessage> message, |
| 152 const ReplyCallback& reply_callback); |
| 153 ~PendingMessage(); |
| 154 std::unique_ptr<JingleMessage> message; |
| 155 const ReplyCallback reply_callback; |
| 156 }; |
| 157 |
| 158 // A message queue to guarantee the incoming messages are processed in order. |
| 159 class OrderedMessageQueue; |
| 160 std::unique_ptr<OrderedMessageQueue> message_queue_; |
| 161 |
| 162 // This prefix is necessary to disambiguate between the ID's sent from the |
| 163 // client and the ID's sent from the host. |
| 164 std::string outgoing_id_prefix_ = base::Uint64ToString(base::RandUint64()); |
| 165 int next_outgoing_id_ = 0; |
| 166 |
138 base::WeakPtrFactory<JingleSession> weak_factory_; | 167 base::WeakPtrFactory<JingleSession> weak_factory_; |
139 | 168 |
140 DISALLOW_COPY_AND_ASSIGN(JingleSession); | 169 DISALLOW_COPY_AND_ASSIGN(JingleSession); |
141 }; | 170 }; |
142 | 171 |
143 } // namespace protocol | 172 } // namespace protocol |
144 } // namespace remoting | 173 } // namespace remoting |
145 | 174 |
146 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 175 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
OLD | NEW |