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 // | 4 // |
5 // This file defines the interface for peer-to-peer transport. There | 5 // This file defines the interface for peer-to-peer transport. There |
6 // are two types of transport: StreamTransport and DatagramTransport. | 6 // are two types of transport: StreamTransport and DatagramTransport. |
7 // They must both be created using TransportFactory instances and they | 7 // They must both be created using TransportFactory instances and they |
8 // provide the same interface, except that one should be used for | 8 // provide the same interface, except that one should be used for |
9 // reliable stream connection and the other one for unreliable | 9 // reliable stream connection and the other one for unreliable |
10 // datagram connection. The Transport interface itself doesn't provide | 10 // datagram connection. The Transport interface itself doesn't provide |
(...skipping 26 matching lines...) Expand all Loading... |
37 namespace net { | 37 namespace net { |
38 class Socket; | 38 class Socket; |
39 class StreamSocket; | 39 class StreamSocket; |
40 } // namespace net | 40 } // namespace net |
41 | 41 |
42 namespace remoting { | 42 namespace remoting { |
43 namespace protocol { | 43 namespace protocol { |
44 | 44 |
45 class ChannelAuthenticator; | 45 class ChannelAuthenticator; |
46 | 46 |
47 enum class TransportRole { | |
48 SERVER, | |
49 CLIENT, | |
50 }; | |
51 | |
52 struct TransportRoute { | 47 struct TransportRoute { |
53 enum RouteType { | 48 enum RouteType { |
54 DIRECT, | 49 DIRECT, |
55 STUN, | 50 STUN, |
56 RELAY, | 51 RELAY, |
57 }; | 52 }; |
58 | 53 |
59 // Helper method to get string representation of the type. | 54 // Helper method to get string representation of the type. |
60 static std::string GetTypeString(RouteType type); | 55 static std::string GetTypeString(RouteType type); |
61 | 56 |
62 TransportRoute(); | 57 TransportRoute(); |
63 ~TransportRoute(); | 58 ~TransportRoute(); |
64 | 59 |
65 RouteType type; | 60 RouteType type; |
66 net::IPEndPoint remote_address; | 61 net::IPEndPoint remote_address; |
67 net::IPEndPoint local_address; | 62 net::IPEndPoint local_address; |
68 }; | 63 }; |
69 | 64 |
70 class Transport : public base::NonThreadSafe { | 65 class Transport : public base::NonThreadSafe { |
71 public: | 66 public: |
72 class EventHandler { | 67 class EventHandler { |
73 public: | 68 public: |
74 EventHandler() {}; | 69 EventHandler() {}; |
75 virtual ~EventHandler() {}; | 70 virtual ~EventHandler() {}; |
76 | 71 |
77 // Called to pass ICE credentials to the session. Used only for STANDARD | |
78 // version of ICE, see SetIceVersion(). | |
79 virtual void OnTransportIceCredentials(Transport* transport, | |
80 const std::string& ufrag, | |
81 const std::string& password) = 0; | |
82 | |
83 // Called when the transport generates a new candidate that needs | 72 // Called when the transport generates a new candidate that needs |
84 // to be passed to the AddRemoteCandidate() method on the remote | 73 // to be passed to the AddRemoteCandidate() method on the remote |
85 // end of the connection. | 74 // end of the connection. |
86 virtual void OnTransportCandidate(Transport* transport, | 75 virtual void OnTransportCandidate(Transport* transport, |
87 const cricket::Candidate& candidate) = 0; | 76 const cricket::Candidate& candidate) = 0; |
88 | 77 |
89 // Called when transport route changes. Can be called even before | 78 // Called when transport route changes. Can be called even before |
90 // the transport is connected. | 79 // the transport is connected. |
91 virtual void OnTransportRouteChange(Transport* transport, | 80 virtual void OnTransportRouteChange(Transport* transport, |
92 const TransportRoute& route) = 0; | 81 const TransportRoute& route) = 0; |
93 | 82 |
94 // Called when when the transport has failed to connect or reconnect. | 83 // Called when when the transport has failed to connect or reconnect. |
95 virtual void OnTransportFailed(Transport* transport) = 0; | 84 virtual void OnTransportFailed(Transport* transport) = 0; |
96 | 85 |
97 // Called when the transport is about to be deleted. | 86 // Called when the transport is about to be deleted. |
98 virtual void OnTransportDeleted(Transport* transport) = 0; | 87 virtual void OnTransportDeleted(Transport* transport) = 0; |
99 }; | 88 }; |
100 | 89 |
101 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; | 90 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; |
102 | 91 |
103 Transport() {} | 92 Transport() {} |
104 virtual ~Transport() {} | 93 virtual ~Transport() {} |
105 | 94 |
106 // Connects the transport and calls the |callback| after that. | 95 // Connects the transport and calls the |callback| after that. |
107 virtual void Connect(const std::string& name, | 96 virtual void Connect(const std::string& name, |
108 Transport::EventHandler* event_handler, | 97 Transport::EventHandler* event_handler, |
109 const ConnectedCallback& callback) = 0; | 98 const ConnectedCallback& callback) = 0; |
110 | 99 |
111 // Sets remote ICE credentials. | |
112 virtual void SetRemoteCredentials(const std::string& ufrag, | |
113 const std::string& password) = 0; | |
114 | |
115 // Adds |candidate| received from the peer. | 100 // Adds |candidate| received from the peer. |
116 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; | 101 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; |
117 | 102 |
118 // Name of the channel. It is used to identify the channel and | 103 // Name of the channel. It is used to identify the channel and |
119 // disambiguate candidates it generates from candidates generated by | 104 // disambiguate candidates it generates from candidates generated by |
120 // parallel connections. | 105 // parallel connections. |
121 virtual const std::string& name() const = 0; | 106 virtual const std::string& name() const = 0; |
122 | 107 |
123 // Returns true if the channel is already connected. | 108 // Returns true if the channel is already connected. |
124 virtual bool is_connected() const = 0; | 109 virtual bool is_connected() const = 0; |
125 | 110 |
126 // Sets ICE version for the transport. | |
127 // | |
128 // TODO(sergeyu): Remove this when support for legacy ICE is removed. | |
129 // crbug.com/473758 | |
130 virtual void SetUseStandardIce(bool use_standard_ice) {} | |
131 | |
132 private: | 111 private: |
133 DISALLOW_COPY_AND_ASSIGN(Transport); | 112 DISALLOW_COPY_AND_ASSIGN(Transport); |
134 }; | 113 }; |
135 | 114 |
136 class TransportFactory { | 115 class TransportFactory { |
137 public: | 116 public: |
138 TransportFactory() { } | 117 TransportFactory() { } |
139 virtual ~TransportFactory() { } | 118 virtual ~TransportFactory() { } |
140 | 119 |
141 // Called to notify transport factory that a new transport might be created | 120 // Called to notify transport factory that a new transport might be created |
142 // soon, e.g. when a new session is being created. Implementation may use it | 121 // soon, e.g. when a new session is being created. Implementation may use it |
143 // to start asynchronous preparation, e.g. fetch a new relay token if | 122 // to start asynchronous preparation, e.g. fetch a new relay token if |
144 // necessary while the session is being authenticated. | 123 // necessary while the session is being authenticated. |
145 virtual void PrepareTokens() = 0; | 124 virtual void PrepareTokens() = 0; |
146 | 125 |
147 virtual scoped_ptr<Transport> CreateTransport() = 0; | 126 virtual scoped_ptr<Transport> CreateTransport() = 0; |
148 | 127 |
149 private: | 128 private: |
150 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | 129 DISALLOW_COPY_AND_ASSIGN(TransportFactory); |
151 }; | 130 }; |
152 | 131 |
153 } // namespace protocol | 132 } // namespace protocol |
154 } // namespace remoting | 133 } // namespace remoting |
155 | 134 |
156 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 135 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
OLD | NEW |