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 #include "remoting/protocol/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 class JingleSession::OrderedMessageQueue { | 108 class JingleSession::OrderedMessageQueue { |
109 public: | 109 public: |
110 OrderedMessageQueue() {} | 110 OrderedMessageQueue() {} |
111 ~OrderedMessageQueue() {} | 111 ~OrderedMessageQueue() {} |
112 | 112 |
113 // Returns the list of messages ordered by their sequential IDs. | 113 // Returns the list of messages ordered by their sequential IDs. |
114 std::vector<PendingMessage> OnIncomingMessage( | 114 std::vector<PendingMessage> OnIncomingMessage( |
115 const std::string& id, | 115 const std::string& id, |
116 PendingMessage&& pending_message); | 116 PendingMessage&& pending_message); |
117 | 117 |
| 118 // Sets the initial ID of the session initiate message. |
| 119 void SetInitialId(const std::string& id); |
| 120 |
118 private: | 121 private: |
119 // Implements an ordered list by using map with the |sequence_id| as the key, | 122 // Implements an ordered list by using map with the |sequence_id| as the key, |
120 // so that |queue_| is always sorted by |sequence_id|. | 123 // so that |queue_| is always sorted by |sequence_id|. |
121 std::map<int, PendingMessage> queue_; | 124 std::map<int, PendingMessage> queue_; |
122 | 125 |
123 int next_incoming_ = kAny; | 126 int next_incoming_ = kAny; |
124 | 127 |
125 DISALLOW_COPY_AND_ASSIGN(OrderedMessageQueue); | 128 DISALLOW_COPY_AND_ASSIGN(OrderedMessageQueue); |
126 }; | 129 }; |
127 | 130 |
(...skipping 27 matching lines...) Expand all Loading... |
155 next_incoming_++; | 158 next_incoming_++; |
156 } | 159 } |
157 | 160 |
158 if (current - next_incoming_ >= 3) { | 161 if (current - next_incoming_ >= 3) { |
159 LOG(WARNING) << "Multiple messages are missing: expected= " | 162 LOG(WARNING) << "Multiple messages are missing: expected= " |
160 << next_incoming_ << " current= " << current; | 163 << next_incoming_ << " current= " << current; |
161 } | 164 } |
162 return result; | 165 return result; |
163 }; | 166 }; |
164 | 167 |
| 168 void JingleSession::OrderedMessageQueue::SetInitialId(const std::string& id) { |
| 169 int current = GetSequentialId(id); |
| 170 if (current != kInvalid) |
| 171 next_incoming_ = current + 1; |
| 172 } |
| 173 |
165 JingleSession::PendingMessage::PendingMessage() = default; | 174 JingleSession::PendingMessage::PendingMessage() = default; |
166 JingleSession::PendingMessage::PendingMessage(PendingMessage&& moved) = default; | 175 JingleSession::PendingMessage::PendingMessage(PendingMessage&& moved) = default; |
167 JingleSession::PendingMessage::PendingMessage( | 176 JingleSession::PendingMessage::PendingMessage( |
168 std::unique_ptr<JingleMessage> message, | 177 std::unique_ptr<JingleMessage> message, |
169 const ReplyCallback& reply_callback) | 178 const ReplyCallback& reply_callback) |
170 : message(std::move(message)), reply_callback(reply_callback) {} | 179 : message(std::move(message)), reply_callback(reply_callback) {} |
171 JingleSession::PendingMessage::~PendingMessage() = default; | 180 JingleSession::PendingMessage::~PendingMessage() = default; |
172 | 181 |
173 JingleSession::PendingMessage& JingleSession::PendingMessage::operator=( | 182 JingleSession::PendingMessage& JingleSession::PendingMessage::operator=( |
174 PendingMessage&& moved) = default; | 183 PendingMessage&& moved) = default; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Delay sending session-initiate message to ensure SessionPlugin can be | 226 // Delay sending session-initiate message to ensure SessionPlugin can be |
218 // attached before the message. | 227 // attached before the message. |
219 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 228 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
220 base::Bind(&JingleSession::SendSessionInitiateMessage, | 229 base::Bind(&JingleSession::SendSessionInitiateMessage, |
221 weak_factory_.GetWeakPtr())); | 230 weak_factory_.GetWeakPtr())); |
222 | 231 |
223 SetState(CONNECTING); | 232 SetState(CONNECTING); |
224 } | 233 } |
225 | 234 |
226 void JingleSession::InitializeIncomingConnection( | 235 void JingleSession::InitializeIncomingConnection( |
| 236 const std::string& message_id, |
227 const JingleMessage& initiate_message, | 237 const JingleMessage& initiate_message, |
228 std::unique_ptr<Authenticator> authenticator) { | 238 std::unique_ptr<Authenticator> authenticator) { |
229 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
230 DCHECK(initiate_message.description.get()); | 240 DCHECK(initiate_message.description.get()); |
231 DCHECK(authenticator.get()); | 241 DCHECK(authenticator.get()); |
232 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); | 242 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); |
233 | 243 |
234 peer_address_ = initiate_message.from; | 244 peer_address_ = initiate_message.from; |
235 authenticator_ = std::move(authenticator); | 245 authenticator_ = std::move(authenticator); |
236 session_id_ = initiate_message.sid; | 246 session_id_ = initiate_message.sid; |
| 247 message_queue_->SetInitialId(message_id); |
237 | 248 |
238 SetState(ACCEPTING); | 249 SetState(ACCEPTING); |
239 | 250 |
240 config_ = | 251 config_ = |
241 SessionConfig::SelectCommon(initiate_message.description->config(), | 252 SessionConfig::SelectCommon(initiate_message.description->config(), |
242 session_manager_->protocol_config_.get()); | 253 session_manager_->protocol_config_.get()); |
243 if (!config_) { | 254 if (!config_) { |
244 LOG(WARNING) << "Rejecting connection from " << peer_address_.id() | 255 LOG(WARNING) << "Rejecting connection from " << peer_address_.id() |
245 << " because no compatible configuration has been found."; | 256 << " because no compatible configuration has been found."; |
246 Close(INCOMPATIBLE_PROTOCOL); | 257 Close(INCOMPATIBLE_PROTOCOL); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 authenticator_->GetNextMessage())); | 811 authenticator_->GetNextMessage())); |
801 SendMessage(std::move(message)); | 812 SendMessage(std::move(message)); |
802 } | 813 } |
803 | 814 |
804 std::string JingleSession::GetNextOutgoingId() { | 815 std::string JingleSession::GetNextOutgoingId() { |
805 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); | 816 return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); |
806 } | 817 } |
807 | 818 |
808 } // namespace protocol | 819 } // namespace protocol |
809 } // namespace remoting | 820 } // namespace remoting |
OLD | NEW |