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 // |
| 5 // This file defines the interface for peer-to-peer transport. There |
| 6 // are two types of transport: StreamTransport and DatagramTransport. |
| 7 // They must both be created using TransportFactory instances and they |
| 8 // provide the same interface, except that one should be used for |
| 9 // reliable stream connection and the other one for unreliable |
| 10 // datagram connection. The Transport interface itself doesn't provide |
| 11 // methods to send/receive data. Instead it creates an instance of |
| 12 // P2PDatagramSocket which provides access to the data channel. After a |
| 13 // new transport is Initialize()'ed the Connect() method must be called. |
| 14 // Connect() starts asynchronous creation and initialization of the |
| 15 // connection socket that can be used later to send and receive data. |
| 16 // The socket is passed to the callback specified in the Connect() call. |
| 17 // The Transport object must exist during the whole lifetime of the |
| 18 // connection socket. Later deletion of the connection socket causes |
| 19 // teardown of the corresponding Transport object. |
4 | 20 |
5 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ | 21 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ |
6 #define REMOTING_PROTOCOL_TRANSPORT_H_ | 22 #define REMOTING_PROTOCOL_TRANSPORT_H_ |
7 | 23 |
8 #include <string> | 24 #include <string> |
9 | 25 |
10 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
11 #include "base/callback_forward.h" | 27 #include "base/callback_forward.h" |
12 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
13 #include "base/threading/non_thread_safe.h" | 29 #include "base/threading/non_thread_safe.h" |
14 #include "net/base/ip_endpoint.h" | 30 #include "net/base/ip_endpoint.h" |
15 #include "remoting/protocol/errors.h" | |
16 | 31 |
17 namespace cricket { | 32 namespace cricket { |
18 class Candidate; | 33 class Candidate; |
19 } // namespace cricket | 34 } // namespace cricket |
20 | 35 |
21 namespace buzz { | |
22 class XmlElement; | |
23 } // namespace buzz | |
24 | |
25 namespace remoting { | 36 namespace remoting { |
26 namespace protocol { | 37 namespace protocol { |
27 | 38 |
28 class Authenticator; | 39 class ChannelAuthenticator; |
29 class DatagramChannelFactory; | |
30 class P2PDatagramSocket; | 40 class P2PDatagramSocket; |
31 class StreamChannelFactory; | |
32 | 41 |
33 enum class TransportRole { | 42 enum class TransportRole { |
34 SERVER, | 43 SERVER, |
35 CLIENT, | 44 CLIENT, |
36 }; | 45 }; |
37 | 46 |
38 struct TransportRoute { | 47 struct TransportRoute { |
39 enum RouteType { | 48 enum RouteType { |
40 DIRECT, | 49 DIRECT, |
41 STUN, | 50 STUN, |
42 RELAY, | 51 RELAY, |
43 }; | 52 }; |
44 | 53 |
45 // Helper method to get string representation of the type. | 54 // Helper method to get string representation of the type. |
46 static std::string GetTypeString(RouteType type); | 55 static std::string GetTypeString(RouteType type); |
47 | 56 |
48 TransportRoute(); | 57 TransportRoute(); |
49 ~TransportRoute(); | 58 ~TransportRoute(); |
50 | 59 |
51 RouteType type; | 60 RouteType type; |
52 net::IPEndPoint remote_address; | 61 net::IPEndPoint remote_address; |
53 net::IPEndPoint local_address; | 62 net::IPEndPoint local_address; |
54 }; | 63 }; |
55 | 64 |
56 // Transport objects are responsible for establishing P2P connections. | |
57 // | |
58 // TODO(sergeyu): Remove this interface and rename TransportSession interface to | |
59 // Transport. | |
60 class Transport : public base::NonThreadSafe { | 65 class Transport : public base::NonThreadSafe { |
61 public: | 66 public: |
62 class EventHandler { | 67 class EventHandler { |
63 public: | 68 public: |
64 EventHandler() {}; | 69 EventHandler() {}; |
65 virtual ~EventHandler() {}; | 70 virtual ~EventHandler() {}; |
66 | 71 |
67 // Called to pass ICE credentials to the session. Used only for STANDARD | 72 // Called to pass ICE credentials to the session. Used only for STANDARD |
68 // version of ICE, see SetIceVersion(). | 73 // version of ICE, see SetIceVersion(). |
69 virtual void OnTransportIceCredentials(Transport* transport, | 74 virtual void OnTransportIceCredentials(Transport* transport, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // parallel connections. | 115 // parallel connections. |
111 virtual const std::string& name() const = 0; | 116 virtual const std::string& name() const = 0; |
112 | 117 |
113 // Returns true if the channel is already connected. | 118 // Returns true if the channel is already connected. |
114 virtual bool is_connected() const = 0; | 119 virtual bool is_connected() const = 0; |
115 | 120 |
116 private: | 121 private: |
117 DISALLOW_COPY_AND_ASSIGN(Transport); | 122 DISALLOW_COPY_AND_ASSIGN(Transport); |
118 }; | 123 }; |
119 | 124 |
120 // TransportSession represents a P2P connection that consists of one or more | |
121 // channels. | |
122 class TransportSession { | |
123 public: | |
124 class EventHandler { | |
125 public: | |
126 // Called to send a transport-info message. | |
127 virtual void OnOutgoingTransportInfo( | |
128 scoped_ptr<buzz::XmlElement> message) = 0; | |
129 | |
130 // Called when transport route changes. | |
131 virtual void OnTransportRouteChange(const std::string& channel_name, | |
132 const TransportRoute& route) = 0; | |
133 | |
134 // Called when there is an error connecting the session. | |
135 virtual void OnTransportError(ErrorCode error) = 0; | |
136 }; | |
137 | |
138 TransportSession() {} | |
139 virtual ~TransportSession() {} | |
140 | |
141 // Starts transport session. Both parameters must outlive TransportSession. | |
142 virtual void Start(EventHandler* event_handler, | |
143 Authenticator* authenticator) = 0; | |
144 | |
145 // Called to process incoming transport message. Returns false if | |
146 // |transport_info| is in invalid format. | |
147 virtual bool ProcessTransportInfo(buzz::XmlElement* transport_info) = 0; | |
148 | |
149 // Channel factory for the session that creates raw ICE channels. | |
150 virtual DatagramChannelFactory* GetDatagramChannelFactory() = 0; | |
151 | |
152 // Channel factory for the session that creates stream channels. | |
153 virtual StreamChannelFactory* GetStreamChannelFactory() = 0; | |
154 | |
155 // Returns a factory that creates multiplexed channels over a single stream | |
156 // channel. | |
157 virtual StreamChannelFactory* GetMultiplexedChannelFactory() = 0; | |
158 | |
159 private: | |
160 DISALLOW_COPY_AND_ASSIGN(TransportSession); | |
161 }; | |
162 | |
163 class TransportFactory { | 125 class TransportFactory { |
164 public: | 126 public: |
165 TransportFactory() { } | 127 TransportFactory() { } |
166 virtual ~TransportFactory() { } | 128 virtual ~TransportFactory() { } |
167 | 129 |
168 // Called to notify transport factory that a new transport might be created | 130 // Called to notify transport factory that a new transport might be created |
169 // soon, e.g. when a new session is being created. Implementation may use it | 131 // soon, e.g. when a new session is being created. Implementation may use it |
170 // to start asynchronous preparation, e.g. fetch a new relay token if | 132 // to start asynchronous preparation, e.g. fetch a new relay token if |
171 // necessary while the session is being authenticated. | 133 // necessary while the session is being authenticated. |
172 virtual void PrepareTokens() = 0; | 134 virtual void PrepareTokens() = 0; |
173 | 135 |
174 // Creates a new TransportSession. The factory must outlive the session. | 136 virtual scoped_ptr<Transport> CreateTransport() = 0; |
175 virtual scoped_ptr<TransportSession> CreateTransportSession() = 0; | |
176 | 137 |
177 private: | 138 private: |
178 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | 139 DISALLOW_COPY_AND_ASSIGN(TransportFactory); |
179 }; | 140 }; |
180 | 141 |
181 } // namespace protocol | 142 } // namespace protocol |
182 } // namespace remoting | 143 } // namespace remoting |
183 | 144 |
184 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 145 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
OLD | NEW |