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