Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: webrtc/p2p/base/transportchannel.h

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Merge Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCHANNEL_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTCHANNEL_H_
13
14 #include <memory>
15 #include <string>
16 #include <vector>
17
18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/p2p/base/candidate.h"
20 #include "webrtc/p2p/base/candidatepairinterface.h"
21 #include "webrtc/p2p/base/packettransportinterface.h"
22 #include "webrtc/p2p/base/jseptransport.h"
23 #include "webrtc/p2p/base/transportdescription.h"
24 #include "webrtc/base/asyncpacketsocket.h"
25 #include "webrtc/base/basictypes.h"
26 #include "webrtc/base/dscp.h"
27 #include "webrtc/base/sigslot.h"
28 #include "webrtc/base/socket.h"
29 #include "webrtc/base/sslidentity.h"
30 #include "webrtc/base/sslstreamadapter.h"
31
32 namespace cricket {
33
34 class Candidate;
35
36 // Flags for SendPacket/SignalReadPacket.
37 enum PacketFlags {
38 PF_NORMAL = 0x00, // A normal packet.
39 PF_SRTP_BYPASS = 0x01, // An encrypted SRTP packet; bypass any additional
40 // crypto provided by the transport (e.g. DTLS)
41 };
42
43 // Used to indicate channel's connection state.
44 enum TransportChannelState {
45 STATE_INIT,
46 STATE_CONNECTING, // Will enter this state once a connection is created
47 STATE_COMPLETED,
48 STATE_FAILED
49 };
50
51 // A TransportChannel represents one logical stream of packets that are sent
52 // between the two sides of a session.
53 // TODO(deadbeef): This interface currently represents the unity of an ICE
54 // transport and a DTLS transport. They need to be separated apart.
55 class TransportChannel : public rtc::PacketTransportInterface {
56 public:
57 TransportChannel(const std::string& transport_name, int component)
58 : transport_name_(transport_name),
59 component_(component),
60 writable_(false),
61 receiving_(false) {}
62 virtual ~TransportChannel() {}
63
64 // TODO(guoweis) - Make this pure virtual once all subclasses of
65 // TransportChannel have this defined.
66 virtual TransportChannelState GetState() const {
67 return TransportChannelState::STATE_CONNECTING;
68 }
69
70 const std::string& transport_name() const { return transport_name_; }
71 int component() const { return component_; }
72 const std::string debug_name() const override {
73 return transport_name() + " " + std::to_string(component());
74 }
75
76 // Returns the states of this channel. Each time one of these states changes,
77 // a signal is raised. These states are aggregated by the TransportManager.
78 bool writable() const override { return writable_; }
79 bool receiving() const override { return receiving_; }
80 DtlsTransportState dtls_state() const { return dtls_state_; }
81 // Emitted whenever DTLS-SRTP is setup which will require setting up a new
82 // SRTP context.
83 sigslot::signal2<TransportChannel*, DtlsTransportState> SignalDtlsState;
84
85 // Returns the current stats for this connection.
86 virtual bool GetStats(ConnectionInfos* infos) = 0;
87
88 // Is DTLS active?
89 virtual bool IsDtlsActive() const = 0;
90
91 // Default implementation.
92 virtual bool GetSslRole(rtc::SSLRole* role) const = 0;
93
94 // Sets up the ciphers to use for DTLS-SRTP. TODO(guoweis): Make this pure
95 // virtual once all dependencies have implementation.
96 virtual bool SetSrtpCryptoSuites(const std::vector<int>& ciphers);
97
98 // Keep the original one for backward compatibility until all dependencies
99 // move away. TODO(guoweis): Remove this function.
100 virtual bool SetSrtpCiphers(const std::vector<std::string>& ciphers);
101
102 // Finds out which DTLS-SRTP cipher was negotiated.
103 // TODO(guoweis): Remove this once all dependencies implement this.
104 virtual bool GetSrtpCryptoSuite(int* cipher) { return false; }
105
106 // Finds out which DTLS cipher was negotiated.
107 // TODO(guoweis): Remove this once all dependencies implement this.
108 virtual bool GetSslCipherSuite(int* cipher) { return false; }
109
110 // Gets the local RTCCertificate used for DTLS.
111 virtual rtc::scoped_refptr<rtc::RTCCertificate>
112 GetLocalCertificate() const = 0;
113
114 // Gets a copy of the remote side's SSL certificate.
115 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate()
116 const = 0;
117
118 // Allows key material to be extracted for external encryption.
119 virtual bool ExportKeyingMaterial(const std::string& label,
120 const uint8_t* context,
121 size_t context_len,
122 bool use_context,
123 uint8_t* result,
124 size_t result_len) = 0;
125
126 // Deprecated by SignalSelectedCandidatePairChanged
127 // This signal occurs when there is a change in the way that packets are
128 // being routed, i.e. to a different remote location. The candidate
129 // indicates where and how we are currently sending media.
130 sigslot::signal2<TransportChannel*, const Candidate&> SignalRouteChange;
131
132 // Signalled when the current selected candidate pair has changed.
133 // The first parameter is the transport channel that signals the event.
134 // The second parameter is the new selected candidate pair. The third
135 // parameter is the last packet id sent on the previous candidate pair.
136 // The fourth parameter is a boolean which is true if the TransportChannel
137 // is ready to send with this candidate pair.
138 sigslot::signal4<TransportChannel*, CandidatePairInterface*, int, bool>
139 SignalSelectedCandidatePairChanged;
140
141 // Invoked when the channel is being destroyed.
142 sigslot::signal1<TransportChannel*> SignalDestroyed;
143
144 // Debugging description of this transport channel.
145 std::string ToString() const;
146
147 protected:
148 // Sets the writable state, signaling if necessary.
149 void set_writable(bool writable);
150
151 // Sets the receiving state, signaling if necessary.
152 void set_receiving(bool receiving);
153
154 // Sets the DTLS state, signaling if necessary.
155 void set_dtls_state(DtlsTransportState state);
156
157 private:
158 // Used mostly for debugging.
159 std::string transport_name_;
160 int component_;
161 bool writable_;
162 bool receiving_;
163 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
164
165 RTC_DISALLOW_COPY_AND_ASSIGN(TransportChannel);
166 };
167
168 } // namespace cricket
169
170 #endif // WEBRTC_P2P_BASE_TRANSPORTCHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698