summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/jingle_stream_connector.h
blob: ab7968b7504c1ff2278d5b94b4a3f3d664b91fb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_
#define REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/completion_callback.h"
#include "remoting/protocol/jingle_channel_connector.h"
#include "remoting/protocol/session.h"

namespace cricket {
class TransportChannel;
}  // namespace cricket

namespace jingle_glue {
class TransportChannelSocketAdapter;
}  // namespace jingle_glue

namespace net {
class CertVerifier;
class StreamSocket;
}  // namespace net

namespace remoting {
namespace protocol {

class JingleSession;

class JingleStreamConnector : public JingleChannelConnector {
 public:
  JingleStreamConnector(JingleSession* session,
                        const std::string& name,
                        const Session::StreamChannelCallback& callback);
  virtual ~JingleStreamConnector();

  // Starts connection process for the channel. |local_private_key| is
  // owned by the caller, and must exist until this object is
  // destroyed.
  virtual void Connect(bool initiator,
                       net::X509Certificate* local_cert,
                       net::X509Certificate* remote_cert,
                       crypto::RSAPrivateKey* local_private_key,
                        cricket::TransportChannel* raw_channel) OVERRIDE;

 private:
  bool EstablishTCPConnection(net::Socket* socket);
  void OnTCPConnect(int result);

  bool EstablishSSLConnection();
  void OnSSLConnect(int result);

  void NotifyDone(net::StreamSocket* socket);
  void NotifyError();

  JingleSession* session_;

  std::string name_;

  Session::StreamChannelCallback callback_;

  bool initiator_;
  scoped_refptr<net::X509Certificate> local_cert_;
  scoped_refptr<net::X509Certificate> remote_cert_;
  crypto::RSAPrivateKey* local_private_key_;

  cricket::TransportChannel* raw_channel_;
  scoped_ptr<net::StreamSocket> socket_;

  // Used to verify the certificate received in SSLClientSocket.
  scoped_ptr<net::CertVerifier> cert_verifier_;

  // Callback called by the TCP and SSL layers.
  net::CompletionCallbackImpl<JingleStreamConnector> tcp_connect_callback_;
  net::CompletionCallbackImpl<JingleStreamConnector> ssl_connect_callback_;

  DISALLOW_COPY_AND_ASSIGN(JingleStreamConnector);
};

}  // namespace protocol
}  // namespace remoting

#endif  // REMOTING_PROTOCOL_JINGLE_STREAM_CONNECTOR_H_