| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 virtual void OnTransportRouteChange(Transport* transport, | 80 virtual void OnTransportRouteChange(Transport* transport, |
| 81 const TransportRoute& route) = 0; | 81 const TransportRoute& route) = 0; |
| 82 | 82 |
| 83 // Called when when the transport has failed to connect or reconnect. | 83 // Called when when the transport has failed to connect or reconnect. |
| 84 virtual void OnTransportFailed(Transport* transport) = 0; | 84 virtual void OnTransportFailed(Transport* transport) = 0; |
| 85 | 85 |
| 86 // Called when the transport is about to be deleted. | 86 // Called when the transport is about to be deleted. |
| 87 virtual void OnTransportDeleted(Transport* transport) = 0; | 87 virtual void OnTransportDeleted(Transport* transport) = 0; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; |
| 91 |
| 90 Transport() {} | 92 Transport() {} |
| 91 virtual ~Transport() {} | 93 virtual ~Transport() {} |
| 92 | 94 |
| 93 // Intialize the transport with the specified parameters. | 95 // Connects the transport and calls the |callback| after that. |
| 94 // |authenticator| is used to secure and authenticate the connection. | 96 virtual void Connect(const std::string& name, |
| 95 virtual void Initialize(const std::string& name, | 97 Transport::EventHandler* event_handler, |
| 96 Transport::EventHandler* event_handler, | 98 const ConnectedCallback& callback) = 0; |
| 97 scoped_ptr<ChannelAuthenticator> authenticator) = 0; | |
| 98 | 99 |
| 99 // Adds |candidate| received from the peer. | 100 // Adds |candidate| received from the peer. |
| 100 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; | 101 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; |
| 101 | 102 |
| 102 // 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 |
| 103 // disambiguate candidates it generates from candidates generated by | 104 // disambiguate candidates it generates from candidates generated by |
| 104 // parallel connections. | 105 // parallel connections. |
| 105 virtual const std::string& name() const = 0; | 106 virtual const std::string& name() const = 0; |
| 106 | 107 |
| 107 // Returns true if the channel is already connected. | 108 // Returns true if the channel is already connected. |
| 108 virtual bool is_connected() const = 0; | 109 virtual bool is_connected() const = 0; |
| 109 | 110 |
| 110 private: | 111 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(Transport); | 112 DISALLOW_COPY_AND_ASSIGN(Transport); |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 class StreamTransport : public Transport { | |
| 115 public: | |
| 116 typedef base::Callback<void(scoped_ptr<net::StreamSocket>)> ConnectedCallback; | |
| 117 | |
| 118 StreamTransport() { } | |
| 119 virtual ~StreamTransport() { } | |
| 120 | |
| 121 virtual void Connect(const ConnectedCallback& callback) = 0; | |
| 122 | |
| 123 private: | |
| 124 DISALLOW_COPY_AND_ASSIGN(StreamTransport); | |
| 125 }; | |
| 126 | |
| 127 class DatagramTransport : public Transport { | |
| 128 public: | |
| 129 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; | |
| 130 | |
| 131 DatagramTransport() { } | |
| 132 virtual ~DatagramTransport() { } | |
| 133 | |
| 134 virtual void Connect(const ConnectedCallback& callback) = 0; | |
| 135 | |
| 136 private: | |
| 137 DISALLOW_COPY_AND_ASSIGN(DatagramTransport); | |
| 138 }; | |
| 139 | |
| 140 class TransportFactory { | 115 class TransportFactory { |
| 141 public: | 116 public: |
| 142 TransportFactory() { } | 117 TransportFactory() { } |
| 143 virtual ~TransportFactory() { } | 118 virtual ~TransportFactory() { } |
| 144 | 119 |
| 145 // 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 |
| 146 // 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 |
| 147 // 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 |
| 148 // necessary while the session is being authenticated. | 123 // necessary while the session is being authenticated. |
| 149 virtual void PrepareTokens() = 0; | 124 virtual void PrepareTokens() = 0; |
| 150 | 125 |
| 151 virtual scoped_ptr<StreamTransport> CreateStreamTransport() = 0; | 126 virtual scoped_ptr<Transport> CreateTransport() = 0; |
| 152 virtual scoped_ptr<DatagramTransport> CreateDatagramTransport() = 0; | |
| 153 | 127 |
| 154 private: | 128 private: |
| 155 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | 129 DISALLOW_COPY_AND_ASSIGN(TransportFactory); |
| 156 }; | 130 }; |
| 157 | 131 |
| 158 } // namespace protocol | 132 } // namespace protocol |
| 159 } // namespace remoting | 133 } // namespace remoting |
| 160 | 134 |
| 161 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 135 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
| OLD | NEW |