| 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 |
| 11 // methods to send/receive data. Instead it creates an instance of | 11 // methods to send/receive data. Instead it creates an instance of |
| 12 // net::Socket or net::SocketStream which provides access to the data | 12 // P2PDatagramSocket which provides access to the data channel. After a |
| 13 // channel. After a new transport is Initialize()'ed the Connect() | 13 // new transport is Initialize()'ed the Connect() method must be called. |
| 14 // method must be called. Connect() starts asynchronous creation and | 14 // Connect() starts asynchronous creation and initialization of the |
| 15 // initialization of the connection socket that can be used later to | 15 // connection socket that can be used later to send and receive data. |
| 16 // send and receive data. The socket is passed to the callback | 16 // The socket is passed to the callback specified in the Connect() call. |
| 17 // specified in the Connect() call. The Transport object must exist | 17 // The Transport object must exist during the whole lifetime of the |
| 18 // during the whole lifetime of the connection socket. Later deletion | 18 // connection socket. Later deletion of the connection socket causes |
| 19 // of the connection socket causes teardown of the corresponding | 19 // teardown of the corresponding Transport object. |
| 20 // Transport object. | |
| 21 | 20 |
| 22 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ | 21 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ |
| 23 #define REMOTING_PROTOCOL_TRANSPORT_H_ | 22 #define REMOTING_PROTOCOL_TRANSPORT_H_ |
| 24 | 23 |
| 25 #include <string> | 24 #include <string> |
| 26 | 25 |
| 27 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
| 28 #include "base/callback_forward.h" | 27 #include "base/callback_forward.h" |
| 29 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
| 30 #include "base/threading/non_thread_safe.h" | 29 #include "base/threading/non_thread_safe.h" |
| 31 #include "net/base/ip_endpoint.h" | 30 #include "net/base/ip_endpoint.h" |
| 32 | 31 |
| 33 namespace cricket { | 32 namespace cricket { |
| 34 class Candidate; | 33 class Candidate; |
| 35 } // namespace cricket | 34 } // namespace cricket |
| 36 | 35 |
| 37 namespace net { | |
| 38 class Socket; | |
| 39 class StreamSocket; | |
| 40 } // namespace net | |
| 41 | |
| 42 namespace remoting { | 36 namespace remoting { |
| 43 namespace protocol { | 37 namespace protocol { |
| 44 | 38 |
| 45 class ChannelAuthenticator; | 39 class ChannelAuthenticator; |
| 40 class P2PDatagramSocket; |
| 46 | 41 |
| 47 enum class TransportRole { | 42 enum class TransportRole { |
| 48 SERVER, | 43 SERVER, |
| 49 CLIENT, | 44 CLIENT, |
| 50 }; | 45 }; |
| 51 | 46 |
| 52 struct TransportRoute { | 47 struct TransportRoute { |
| 53 enum RouteType { | 48 enum RouteType { |
| 54 DIRECT, | 49 DIRECT, |
| 55 STUN, | 50 STUN, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 virtual void OnTransportRouteChange(Transport* transport, | 86 virtual void OnTransportRouteChange(Transport* transport, |
| 92 const TransportRoute& route) = 0; | 87 const TransportRoute& route) = 0; |
| 93 | 88 |
| 94 // Called when when the transport has failed to connect or reconnect. | 89 // Called when when the transport has failed to connect or reconnect. |
| 95 virtual void OnTransportFailed(Transport* transport) = 0; | 90 virtual void OnTransportFailed(Transport* transport) = 0; |
| 96 | 91 |
| 97 // Called when the transport is about to be deleted. | 92 // Called when the transport is about to be deleted. |
| 98 virtual void OnTransportDeleted(Transport* transport) = 0; | 93 virtual void OnTransportDeleted(Transport* transport) = 0; |
| 99 }; | 94 }; |
| 100 | 95 |
| 101 typedef base::Callback<void(scoped_ptr<net::Socket>)> ConnectedCallback; | 96 typedef base::Callback<void(scoped_ptr<P2PDatagramSocket>)> ConnectedCallback; |
| 102 | 97 |
| 103 Transport() {} | 98 Transport() {} |
| 104 virtual ~Transport() {} | 99 virtual ~Transport() {} |
| 105 | 100 |
| 106 // Connects the transport and calls the |callback| after that. | 101 // Connects the transport and calls the |callback| after that. |
| 107 virtual void Connect(const std::string& name, | 102 virtual void Connect(const std::string& name, |
| 108 Transport::EventHandler* event_handler, | 103 Transport::EventHandler* event_handler, |
| 109 const ConnectedCallback& callback) = 0; | 104 const ConnectedCallback& callback) = 0; |
| 110 | 105 |
| 111 // Sets remote ICE credentials. | 106 // Sets remote ICE credentials. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 virtual scoped_ptr<Transport> CreateTransport() = 0; | 142 virtual scoped_ptr<Transport> CreateTransport() = 0; |
| 148 | 143 |
| 149 private: | 144 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | 145 DISALLOW_COPY_AND_ASSIGN(TransportFactory); |
| 151 }; | 146 }; |
| 152 | 147 |
| 153 } // namespace protocol | 148 } // namespace protocol |
| 154 } // namespace remoting | 149 } // namespace remoting |
| 155 | 150 |
| 156 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 151 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
| OLD | NEW |