| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/timer.h" |
| 13 #include "crypto/rsa_private_key.h" |
| 14 #include "net/base/completion_callback.h" |
| 15 #include "remoting/protocol/jingle_messages.h" |
| 16 #include "remoting/protocol/session.h" |
| 17 #include "remoting/protocol/session_config.h" |
| 18 |
| 19 namespace net { |
| 20 class CertVerifier; |
| 21 class ClientSocketFactory; |
| 22 class Socket; |
| 23 class StreamSocket; |
| 24 class X509Certificate; |
| 25 } // namespace net |
| 26 |
| 27 namespace pp { |
| 28 class Instance; |
| 29 } // namespace pp |
| 30 |
| 31 namespace remoting { |
| 32 |
| 33 class IqRequest; |
| 34 |
| 35 namespace protocol { |
| 36 |
| 37 class PepperChannel; |
| 38 class PepperSessionManager; |
| 39 class SocketWrapper; |
| 40 |
| 41 // Implements the protocol::Session interface using the Pepper P2P |
| 42 // Transport API. Created by PepperSessionManager for incoming and |
| 43 // outgoing connections. |
| 44 class PepperSession : public Session { |
| 45 public: |
| 46 // TODO(sergeyu): Move this type and error() method to the Session |
| 47 // interface. |
| 48 enum Error { |
| 49 ERROR_NO_ERROR = 0, |
| 50 ERROR_PEER_IS_OFFLINE, |
| 51 ERROR_SESSION_REJECTED, |
| 52 ERROR_INCOMPATIBLE_PROTOCOL, |
| 53 ERROR_CHANNEL_CONNECTION_FAILURE, |
| 54 }; |
| 55 |
| 56 virtual ~PepperSession(); |
| 57 |
| 58 Error error(); |
| 59 |
| 60 // Session interface. |
| 61 virtual void SetStateChangeCallback(StateChangeCallback* callback) OVERRIDE; |
| 62 virtual void CreateStreamChannel( |
| 63 const std::string& name, |
| 64 const StreamChannelCallback& callback) OVERRIDE; |
| 65 virtual void CreateDatagramChannel( |
| 66 const std::string& name, |
| 67 const DatagramChannelCallback& callback) OVERRIDE; |
| 68 virtual net::Socket* control_channel() OVERRIDE; |
| 69 virtual net::Socket* event_channel() OVERRIDE; |
| 70 virtual const std::string& jid() OVERRIDE; |
| 71 virtual const CandidateSessionConfig* candidate_config() OVERRIDE; |
| 72 virtual const SessionConfig& config() OVERRIDE; |
| 73 virtual void set_config(const SessionConfig& config) OVERRIDE; |
| 74 virtual const std::string& initiator_token() OVERRIDE; |
| 75 virtual void set_initiator_token(const std::string& initiator_token) OVERRIDE; |
| 76 virtual const std::string& receiver_token() OVERRIDE; |
| 77 virtual void set_receiver_token(const std::string& receiver_token) OVERRIDE; |
| 78 virtual void set_shared_secret(const std::string& secret) OVERRIDE; |
| 79 virtual const std::string& shared_secret() OVERRIDE; |
| 80 virtual void Close() OVERRIDE; |
| 81 |
| 82 private: |
| 83 friend class PepperSessionManager; |
| 84 friend class PepperStreamChannel; |
| 85 |
| 86 typedef std::map<std::string, PepperChannel*> ChannelsMap; |
| 87 |
| 88 PepperSession(PepperSessionManager* session_manager); |
| 89 |
| 90 // Start cs connection by sending session-initiate message. |
| 91 void StartConnection(const std::string& peer_jid, |
| 92 const std::string& peer_public_key, |
| 93 const std::string& client_token, |
| 94 CandidateSessionConfig* config, |
| 95 Session::StateChangeCallback* state_change_callback); |
| 96 |
| 97 // Handler for session-initiate response. |
| 98 void OnSessionInitiateResponse(const buzz::XmlElement* response); |
| 99 |
| 100 // Called when an error occurs. Sets |error_| and closes the session. |
| 101 void OnError(Error error); |
| 102 |
| 103 // Called by PepperSessionManager on incoming |message|. Must fill |
| 104 // in |reply|. |
| 105 void OnIncomingMessage(const JingleMessage& message, |
| 106 JingleMessageReply* reply); |
| 107 |
| 108 // Message handlers for incoming messages. |
| 109 void OnAccept(const JingleMessage& message, JingleMessageReply* reply); |
| 110 void OnReject(const JingleMessage& message, JingleMessageReply* reply); |
| 111 void OnTerminate(const JingleMessage& message, JingleMessageReply* reply); |
| 112 void ProcessTransportInfo(const JingleMessage& message); |
| 113 |
| 114 // Called from OnAccept() to initialize session config. |
| 115 bool InitializeConfigFromDescription(const ContentDescription* description); |
| 116 |
| 117 // Called by PepperChannel. |
| 118 void AddLocalCandidate(const cricket::Candidate& candidate); |
| 119 void OnDeleteChannel(PepperChannel* channel); |
| 120 |
| 121 void SendTransportInfo(); |
| 122 |
| 123 // Helper methods to create event and control channels. |
| 124 // TODO(sergeyu): Remove these methods. |
| 125 void CreateChannels(); |
| 126 void OnChannelConnected(scoped_ptr<net::Socket>* socket_container, |
| 127 net::StreamSocket* socket); |
| 128 |
| 129 // Close all the channels and terminate the session. |
| 130 void CloseInternal(bool failed); |
| 131 |
| 132 // Sets |state_| to |new_state| and calls state change callback. |
| 133 void SetState(State new_state); |
| 134 |
| 135 PepperSessionManager* session_manager_; |
| 136 std::string peer_jid_; |
| 137 std::string peer_public_key_; |
| 138 scoped_ptr<CandidateSessionConfig> candidate_config_; |
| 139 scoped_ptr<StateChangeCallback> state_change_callback_; |
| 140 |
| 141 std::string session_id_; |
| 142 State state_; |
| 143 Error error_; |
| 144 |
| 145 std::string remote_cert_; |
| 146 SessionConfig config_; |
| 147 |
| 148 std::string shared_secret_; |
| 149 std::string initiator_token_; |
| 150 std::string receiver_token_; |
| 151 |
| 152 scoped_ptr<IqRequest> initiate_request_; |
| 153 |
| 154 ChannelsMap channels_; |
| 155 |
| 156 scoped_ptr<net::Socket> control_channel_socket_; |
| 157 scoped_ptr<net::Socket> event_channel_socket_; |
| 158 |
| 159 base::OneShotTimer<PepperSession> transport_infos_timer_; |
| 160 std::list<cricket::Candidate> pending_candidates_; |
| 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(PepperSession); |
| 163 }; |
| 164 |
| 165 } // namespace protocol |
| 166 } // namespace remoting |
| 167 |
| 168 #endif // REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| OLD | NEW |