Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: remoting/protocol/transport.h

Issue 1420273002: Add TransportSession interface to prepare for WebRTC-based transport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/session.h ('k') | remoting/remoting_srcs.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
20 4
21 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ 5 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_
22 #define REMOTING_PROTOCOL_TRANSPORT_H_ 6 #define REMOTING_PROTOCOL_TRANSPORT_H_
23 7
24 #include <string> 8 #include <string>
25 9
26 #include "base/basictypes.h" 10 #include "base/basictypes.h"
27 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
28 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
29 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
30 #include "net/base/ip_endpoint.h" 14 #include "net/base/ip_endpoint.h"
15 #include "remoting/protocol/errors.h"
31 16
32 namespace cricket { 17 namespace cricket {
33 class Candidate; 18 class Candidate;
34 } // namespace cricket 19 } // namespace cricket
35 20
21 namespace buzz {
22 class XmlElement;
23 } // namespace buzz
24
36 namespace remoting { 25 namespace remoting {
37 namespace protocol { 26 namespace protocol {
38 27
39 class ChannelAuthenticator; 28 class Authenticator;
29 class DatagramChannelFactory;
40 class P2PDatagramSocket; 30 class P2PDatagramSocket;
31 class StreamChannelFactory;
41 32
42 enum class TransportRole { 33 enum class TransportRole {
43 SERVER, 34 SERVER,
44 CLIENT, 35 CLIENT,
45 }; 36 };
46 37
47 struct TransportRoute { 38 struct TransportRoute {
48 enum RouteType { 39 enum RouteType {
49 DIRECT, 40 DIRECT,
50 STUN, 41 STUN,
51 RELAY, 42 RELAY,
52 }; 43 };
53 44
54 // Helper method to get string representation of the type. 45 // Helper method to get string representation of the type.
55 static std::string GetTypeString(RouteType type); 46 static std::string GetTypeString(RouteType type);
56 47
57 TransportRoute(); 48 TransportRoute();
58 ~TransportRoute(); 49 ~TransportRoute();
59 50
60 RouteType type; 51 RouteType type;
61 net::IPEndPoint remote_address; 52 net::IPEndPoint remote_address;
62 net::IPEndPoint local_address; 53 net::IPEndPoint local_address;
63 }; 54 };
64 55
56 // Transport objects are responsible for establishing P2P connections.
57 //
58 // TODO(sergeyu): Remove this interface and rename TransportSession interface to
59 // Transport.
65 class Transport : public base::NonThreadSafe { 60 class Transport : public base::NonThreadSafe {
66 public: 61 public:
67 class EventHandler { 62 class EventHandler {
68 public: 63 public:
69 EventHandler() {}; 64 EventHandler() {};
70 virtual ~EventHandler() {}; 65 virtual ~EventHandler() {};
71 66
72 // Called to pass ICE credentials to the session. Used only for STANDARD 67 // Called to pass ICE credentials to the session. Used only for STANDARD
73 // version of ICE, see SetIceVersion(). 68 // version of ICE, see SetIceVersion().
74 virtual void OnTransportIceCredentials(Transport* transport, 69 virtual void OnTransportIceCredentials(Transport* transport,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // parallel connections. 110 // parallel connections.
116 virtual const std::string& name() const = 0; 111 virtual const std::string& name() const = 0;
117 112
118 // Returns true if the channel is already connected. 113 // Returns true if the channel is already connected.
119 virtual bool is_connected() const = 0; 114 virtual bool is_connected() const = 0;
120 115
121 private: 116 private:
122 DISALLOW_COPY_AND_ASSIGN(Transport); 117 DISALLOW_COPY_AND_ASSIGN(Transport);
123 }; 118 };
124 119
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
125 class TransportFactory { 163 class TransportFactory {
126 public: 164 public:
127 TransportFactory() { } 165 TransportFactory() { }
128 virtual ~TransportFactory() { } 166 virtual ~TransportFactory() { }
129 167
130 // Called to notify transport factory that a new transport might be created 168 // Called to notify transport factory that a new transport might be created
131 // soon, e.g. when a new session is being created. Implementation may use it 169 // soon, e.g. when a new session is being created. Implementation may use it
132 // to start asynchronous preparation, e.g. fetch a new relay token if 170 // to start asynchronous preparation, e.g. fetch a new relay token if
133 // necessary while the session is being authenticated. 171 // necessary while the session is being authenticated.
134 virtual void PrepareTokens() = 0; 172 virtual void PrepareTokens() = 0;
135 173
136 virtual scoped_ptr<Transport> CreateTransport() = 0; 174 // Creates a new TransportSession. The factory must outlive the session.
175 virtual scoped_ptr<TransportSession> CreateTransportSession() = 0;
137 176
138 private: 177 private:
139 DISALLOW_COPY_AND_ASSIGN(TransportFactory); 178 DISALLOW_COPY_AND_ASSIGN(TransportFactory);
140 }; 179 };
141 180
142 } // namespace protocol 181 } // namespace protocol
143 } // namespace remoting 182 } // namespace remoting
144 183
145 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ 184 #endif // REMOTING_PROTOCOL_TRANSPORT_H_
OLDNEW
« no previous file with comments | « remoting/protocol/session.h ('k') | remoting/remoting_srcs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698