diff options
Diffstat (limited to 'remoting/protocol/jingle_chromoting_connection.cc')
-rw-r--r-- | remoting/protocol/jingle_chromoting_connection.cc | 129 |
1 files changed, 87 insertions, 42 deletions
diff --git a/remoting/protocol/jingle_chromoting_connection.cc b/remoting/protocol/jingle_chromoting_connection.cc index 10d8709..fe1cb7d 100644 --- a/remoting/protocol/jingle_chromoting_connection.cc +++ b/remoting/protocol/jingle_chromoting_connection.cc @@ -21,12 +21,15 @@ using cricket::Session; namespace remoting { namespace { +const char kControlChannelName[] = "control"; +const char kEventChannelName[] = "event"; const char kVideoChannelName[] = "video"; const char kVideoRtpChannelName[] = "videortp"; const char kVideoRtcpChannelName[] = "videortcp"; -const char kEventChannelName[] = "event"; } // namespace +const char JingleChromotingConnection::kChromotingContentName[] = "chromoting"; + JingleChromotingConnection::JingleChromotingConnection( JingleChromotingServer* server) : server_(server), @@ -73,10 +76,9 @@ void JingleChromotingConnection::SetStateChangeCallback( state_change_callback_.reset(callback); } -// TODO(sergeyu): Remove this method after we switch to RTP. -net::Socket* JingleChromotingConnection::GetVideoChannel() { +net::Socket* JingleChromotingConnection::GetControlChannel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); - return video_channel_adapter_.get(); + return control_channel_adapter_.get(); } net::Socket* JingleChromotingConnection::GetEventChannel() { @@ -84,6 +86,12 @@ net::Socket* JingleChromotingConnection::GetEventChannel() { return event_channel_adapter_.get(); } +// TODO(sergeyu): Remove this method after we switch to RTP. +net::Socket* JingleChromotingConnection::GetVideoChannel() { + DCHECK_EQ(server_->message_loop(), MessageLoop::current()); + return video_channel_adapter_.get(); +} + net::Socket* JingleChromotingConnection::GetVideoRtpChannel() { DCHECK_EQ(server_->message_loop(), MessageLoop::current()); return video_rtp_channel_.get(); @@ -137,6 +145,14 @@ void JingleChromotingConnection::Close(Task* closed_task) { } if (!closed_) { + if (control_channel_adapter_.get()) + control_channel_adapter_->Close(net::ERR_CONNECTION_CLOSED); + + if (control_channel_) { + control_channel_->OnSessionTerminate(session_); + control_channel_ = NULL; + } + if (event_channel_adapter_.get()) event_channel_adapter_->Close(net::ERR_CONNECTION_CLOSED); @@ -176,22 +192,19 @@ void JingleChromotingConnection::OnSessionState( switch (state) { case Session::STATE_SENTINITIATE: - OnInitiate(false); - break; - case Session::STATE_RECEIVEDINITIATE: - OnInitiate(true); + OnInitiate(); break; case Session::STATE_SENTACCEPT: - OnAccept(false); - break; - case Session::STATE_RECEIVEDACCEPT: - OnAccept(true); + OnAccept(); break; + case Session::STATE_SENTTERMINATE: case Session::STATE_RECEIVEDTERMINATE: + case Session::STATE_SENTREJECT: + case Session::STATE_RECEIVEDREJECT: OnTerminate(); break; @@ -201,50 +214,45 @@ void JingleChromotingConnection::OnSessionState( break; default: + // We don't care about other steates. break; } } -void JingleChromotingConnection::OnInitiate(bool incoming) { +void JingleChromotingConnection::OnInitiate() { jid_ = session_->remote_name(); - if (incoming) - server_->AcceptConnection(this, session_); - SetState(CONNECTING); -} - -void JingleChromotingConnection::OnAccept(bool incoming) { - const cricket::ContentInfo* content = - session_->remote_description()->FirstContentByType( - kChromotingXmlNamespace); - CHECK(content); - - // Set config for outgoing connections. - if (incoming) { - const ChromotingContentDescription* content_description = - static_cast<const ChromotingContentDescription*>(content->description); - ChromotocolConfig* config = content_description->config()->GetFinalConfig(); - // Terminate the session if the config we received is invalid. - if (!config || !candidate_config()->IsSupported(config)) { - LOG(ERROR) << "Terminating outgoing session after an " - "invalid session description has been received."; - session_->Terminate(); - return; - } - - set_config(config); + std::string content_name; + // If we initiate the connection, we get to specify the content name. When + // accepting one, the remote end specifies it. + if (session_->initiator()) { + content_name = kChromotingContentName; + } else { + const cricket::ContentInfo* content; + content = session_->remote_description()->FirstContentByType( + kChromotingXmlNamespace); + CHECK(content); + content_name = content->name; } // Create video RTP channels. video_rtp_channel_.reset(new TransportChannelSocketAdapter( - session_->CreateChannel(content->name, kVideoRtpChannelName))); + session_->CreateChannel(content_name, kVideoRtpChannelName))); video_rtcp_channel_.reset(new TransportChannelSocketAdapter( - session_->CreateChannel(content->name, kVideoRtcpChannelName))); + session_->CreateChannel(content_name, kVideoRtcpChannelName))); + + // Create control channel. + // TODO(sergeyu): Don't use talk_base::Thread::Current() here. + control_channel_ = + new PseudoTcpChannel(talk_base::Thread::Current(), session_); + control_channel_->Connect(content_name, kControlChannelName); + control_channel_adapter_.reset(new StreamSocketAdapter( + control_channel_->GetStream())); // Create event channel. event_channel_ = new PseudoTcpChannel(talk_base::Thread::Current(), session_); - event_channel_->Connect(content->name, kEventChannelName); + event_channel_->Connect(content_name, kEventChannelName); event_channel_adapter_.reset(new StreamSocketAdapter( event_channel_->GetStream())); @@ -252,14 +260,51 @@ void JingleChromotingConnection::OnAccept(bool incoming) { // TODO(sergeyu): Remove video channel when we are ready to switch to RTP. video_channel_ = new PseudoTcpChannel(talk_base::Thread::Current(), session_); - video_channel_->Connect(content->name, kVideoChannelName); + video_channel_->Connect(content_name, kVideoChannelName); video_channel_adapter_.reset(new StreamSocketAdapter( video_channel_->GetStream())); + if (!session_->initiator()) + server_->AcceptConnection(this, session_); + + SetState(CONNECTING); +} + +void JingleChromotingConnection::OnAccept() { + // Set config for outgoing connections. + if (session_->initiator()) { + const cricket::ContentInfo* content = + session_->remote_description()->FirstContentByType( + kChromotingXmlNamespace); + CHECK(content); + + const ChromotingContentDescription* content_description = + static_cast<const ChromotingContentDescription*>(content->description); + ChromotocolConfig* config = content_description->config()->GetFinalConfig(); + + // Terminate the session if the config we received is invalid. + if (!config || !candidate_config()->IsSupported(config)) { + // TODO(sergeyu): Inform the user that the host is misbehaving? + LOG(ERROR) << "Terminating outgoing session after an " + "invalid session description has been received."; + session_->Terminate(); + return; + } + + set_config(config); + } + SetState(CONNECTED); } void JingleChromotingConnection::OnTerminate() { + if (control_channel_adapter_.get()) + control_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); + if (control_channel_) { + control_channel_->OnSessionTerminate(session_); + control_channel_ = NULL; + } + if (event_channel_adapter_.get()) event_channel_adapter_->Close(net::ERR_CONNECTION_ABORTED); if (event_channel_) { |