| 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 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ | 5 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ |
| 6 #define REMOTING_PROTOCOL_TRANSPORT_H_ | 6 #define REMOTING_PROTOCOL_TRANSPORT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 15 #include "remoting/protocol/errors.h" | 15 #include "remoting/protocol/errors.h" |
| 16 | 16 |
| 17 namespace cricket { | |
| 18 class Candidate; | |
| 19 } // namespace cricket | |
| 20 | |
| 21 namespace buzz { | 17 namespace buzz { |
| 22 class XmlElement; | 18 class XmlElement; |
| 23 } // namespace buzz | 19 } // namespace buzz |
| 24 | 20 |
| 25 namespace webrtc { | 21 namespace webrtc { |
| 26 class PeerConnectionInterface; | 22 class PeerConnectionInterface; |
| 27 } // namespace webrtc | 23 } // namespace webrtc |
| 28 | 24 |
| 29 namespace remoting { | 25 namespace remoting { |
| 30 namespace protocol { | 26 namespace protocol { |
| 31 | 27 |
| 32 class Authenticator; | 28 class Authenticator; |
| 33 class DatagramChannelFactory; | 29 class DatagramChannelFactory; |
| 34 class P2PDatagramSocket; | 30 class P2PDatagramSocket; |
| 35 class StreamChannelFactory; | 31 class StreamChannelFactory; |
| 36 class WebrtcTransport; | |
| 37 | 32 |
| 38 enum class TransportRole { | 33 enum class TransportRole { |
| 39 SERVER, | 34 SERVER, |
| 40 CLIENT, | 35 CLIENT, |
| 41 }; | 36 }; |
| 42 | 37 |
| 43 struct TransportRoute { | 38 struct TransportRoute { |
| 44 enum RouteType { | 39 enum RouteType { |
| 45 DIRECT, | 40 DIRECT, |
| 46 STUN, | 41 STUN, |
| 47 RELAY, | 42 RELAY, |
| 48 }; | 43 }; |
| 49 | 44 |
| 50 // Helper method to get string representation of the type. | 45 // Helper method to get string representation of the type. |
| 51 static std::string GetTypeString(RouteType type); | 46 static std::string GetTypeString(RouteType type); |
| 52 | 47 |
| 53 TransportRoute(); | 48 TransportRoute(); |
| 54 ~TransportRoute(); | 49 ~TransportRoute(); |
| 55 | 50 |
| 56 RouteType type; | 51 RouteType type; |
| 57 net::IPEndPoint remote_address; | 52 net::IPEndPoint remote_address; |
| 58 net::IPEndPoint local_address; | 53 net::IPEndPoint local_address; |
| 59 }; | 54 }; |
| 60 | 55 |
| 61 // Transport represents a P2P connection that consists of one or more | 56 // Transport represents a P2P connection that consists of one or more channels. |
| 62 // channels. | 57 // This interface is used just to send and receive transport-info messages. |
| 58 // Implementations should provide other methods to send and receive data. |
| 63 class Transport { | 59 class Transport { |
| 64 public: | 60 public: |
| 65 class EventHandler { | 61 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> transport_info)> |
| 66 public: | 62 SendTransportInfoCallback; |
| 67 // Called to send a transport-info message. | |
| 68 virtual void OnOutgoingTransportInfo( | |
| 69 scoped_ptr<buzz::XmlElement> message) = 0; | |
| 70 | 63 |
| 71 // Called when transport route changes. | |
| 72 virtual void OnTransportRouteChange(const std::string& channel_name, | |
| 73 const TransportRoute& route) = 0; | |
| 74 | |
| 75 // Called when the transport is connected. | |
| 76 virtual void OnTransportConnected() = 0; | |
| 77 | |
| 78 // Called when there is an error connecting the session. | |
| 79 virtual void OnTransportError(ErrorCode error) = 0; | |
| 80 }; | |
| 81 | |
| 82 Transport() {} | |
| 83 virtual ~Transport() {} | 64 virtual ~Transport() {} |
| 84 | 65 |
| 85 // Starts transport session. Both parameters must outlive Transport. | 66 // Sets the object responsible for delivering outgoing transport-info messages |
| 86 virtual void Start(EventHandler* event_handler, | 67 // to the peer. |
| 87 Authenticator* authenticator) = 0; | 68 virtual void Start( |
| 88 | 69 Authenticator* authenticator, |
| 89 // Called to process incoming transport message. Returns false if | 70 SendTransportInfoCallback send_transport_info_callback) = 0; |
| 90 // |transport_info| is in invalid format. | |
| 91 virtual bool ProcessTransportInfo(buzz::XmlElement* transport_info) = 0; | 71 virtual bool ProcessTransportInfo(buzz::XmlElement* transport_info) = 0; |
| 92 | |
| 93 // Channel factory for the session that creates stream channels. | |
| 94 virtual StreamChannelFactory* GetStreamChannelFactory() = 0; | |
| 95 | |
| 96 // Returns a factory that creates multiplexed channels over a single stream | |
| 97 // channel. | |
| 98 virtual StreamChannelFactory* GetMultiplexedChannelFactory() = 0; | |
| 99 | |
| 100 // Returns the transport as WebrtcTransport or nullptr if this is not a | |
| 101 // WebrtcTransport. | |
| 102 // | |
| 103 // TODO(sergeyu): Move creation and ownership of Transport objects to the | |
| 104 // Connection classes. That way the Connection classes will be able to ensure | |
| 105 // that correct transport implementation is used for the connection and this | |
| 106 // method will not be necessary. | |
| 107 virtual WebrtcTransport* AsWebrtcTransport(); | |
| 108 | |
| 109 private: | |
| 110 DISALLOW_COPY_AND_ASSIGN(Transport); | |
| 111 }; | |
| 112 | |
| 113 class TransportFactory { | |
| 114 public: | |
| 115 TransportFactory() { } | |
| 116 virtual ~TransportFactory() { } | |
| 117 | |
| 118 // Creates a new Transport. The factory must outlive the session. | |
| 119 virtual scoped_ptr<Transport> CreateTransport() = 0; | |
| 120 | |
| 121 private: | |
| 122 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | |
| 123 }; | 72 }; |
| 124 | 73 |
| 125 } // namespace protocol | 74 } // namespace protocol |
| 126 } // namespace remoting | 75 } // namespace remoting |
| 127 | 76 |
| 128 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 77 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
| OLD | NEW |