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

Side by Side Diff: webrtc/pc/srtpfilter.h

Issue 2938013003: Delete SignalSrtpError. (Closed)
Patch Set: Delete left-over declaration of set_signal_silent_time. Created 3 years, 6 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
1 /* 1 /*
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_PC_SRTPFILTER_H_ 11 #ifndef WEBRTC_PC_SRTPFILTER_H_
12 #define WEBRTC_PC_SRTPFILTER_H_ 12 #define WEBRTC_PC_SRTPFILTER_H_
13 13
14 #include <list> 14 #include <list>
15 #include <map> 15 #include <map>
16 #include <memory> 16 #include <memory>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "webrtc/base/basictypes.h" 20 #include "webrtc/base/basictypes.h"
21 #include "webrtc/base/constructormagic.h" 21 #include "webrtc/base/constructormagic.h"
22 #include "webrtc/base/criticalsection.h" 22 #include "webrtc/base/criticalsection.h"
23 #include "webrtc/base/sigslotrepeater.h"
24 #include "webrtc/base/sslstreamadapter.h" 23 #include "webrtc/base/sslstreamadapter.h"
25 #include "webrtc/base/thread_checker.h" 24 #include "webrtc/base/thread_checker.h"
26 #include "webrtc/media/base/cryptoparams.h" 25 #include "webrtc/media/base/cryptoparams.h"
27 #include "webrtc/p2p/base/sessiondescription.h" 26 #include "webrtc/p2p/base/sessiondescription.h"
28 27
29 // Forward declaration to avoid pulling in libsrtp headers here 28 // Forward declaration to avoid pulling in libsrtp headers here
30 struct srtp_event_data_t; 29 struct srtp_event_data_t;
31 struct srtp_ctx_t_; 30 struct srtp_ctx_t_;
32 31
33 namespace cricket { 32 namespace cricket {
34 33
35 class SrtpSession; 34 class SrtpSession;
36 class SrtpStat;
37 35
38 void ShutdownSrtp(); 36 void ShutdownSrtp();
39 37
40 // Class to transform SRTP to/from RTP. 38 // Class to transform SRTP to/from RTP.
41 // Initialize by calling SetSend with the local security params, then call 39 // Initialize by calling SetSend with the local security params, then call
42 // SetRecv once the remote security params are received. At that point 40 // SetRecv once the remote security params are received. At that point
43 // Protect/UnprotectRt(c)p can be called to encrypt/decrypt data. 41 // Protect/UnprotectRt(c)p can be called to encrypt/decrypt data.
44 // TODO: Figure out concurrency policy for SrtpFilter. 42 // TODO: Figure out concurrency policy for SrtpFilter.
45 class SrtpFilter { 43 class SrtpFilter {
46 public: 44 public:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // if it is actually used. This method is only valid before the RTP params 118 // if it is actually used. This method is only valid before the RTP params
121 // have been set. 119 // have been set.
122 void EnableExternalAuth(); 120 void EnableExternalAuth();
123 bool IsExternalAuthEnabled() const; 121 bool IsExternalAuthEnabled() const;
124 122
125 // A SRTP filter supports external creation of the auth tag if a non-GCM 123 // A SRTP filter supports external creation of the auth tag if a non-GCM
126 // cipher is used. This method is only valid after the RTP params have 124 // cipher is used. This method is only valid after the RTP params have
127 // been set. 125 // been set.
128 bool IsExternalAuthActive() const; 126 bool IsExternalAuthActive() const;
129 127
130 // Update the silent threshold (in ms) for signaling errors.
131 void set_signal_silent_time(int signal_silent_time_in_ms);
132
133 bool ResetParams(); 128 bool ResetParams();
134 129
135 sigslot::repeater3<uint32_t, Mode, Error> SignalSrtpError;
136
137 protected: 130 protected:
138 bool ExpectOffer(ContentSource source); 131 bool ExpectOffer(ContentSource source);
139 bool StoreParams(const std::vector<CryptoParams>& params, 132 bool StoreParams(const std::vector<CryptoParams>& params,
140 ContentSource source); 133 ContentSource source);
141 bool ExpectAnswer(ContentSource source); 134 bool ExpectAnswer(ContentSource source);
142 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params, 135 bool DoSetAnswer(const std::vector<CryptoParams>& answer_params,
143 ContentSource source, 136 ContentSource source,
144 bool final); 137 bool final);
145 void CreateSrtpSessions(); 138 void CreateSrtpSessions();
146 bool NegotiateParams(const std::vector<CryptoParams>& answer_params, 139 bool NegotiateParams(const std::vector<CryptoParams>& answer_params,
(...skipping 22 matching lines...) Expand all
169 // SRTP filter is active but the sent answer is only provisional. 162 // SRTP filter is active but the sent answer is only provisional.
170 // When the final answer is set, the state transitions to ST_ACTIVE or 163 // When the final answer is set, the state transitions to ST_ACTIVE or
171 // ST_INIT. 164 // ST_INIT.
172 ST_SENTPRANSWER, 165 ST_SENTPRANSWER,
173 // SRTP filter is active but the received answer is only provisional. 166 // SRTP filter is active but the received answer is only provisional.
174 // When the final answer is set, the state transitions to ST_ACTIVE or 167 // When the final answer is set, the state transitions to ST_ACTIVE or
175 // ST_INIT. 168 // ST_INIT.
176 ST_RECEIVEDPRANSWER 169 ST_RECEIVEDPRANSWER
177 }; 170 };
178 State state_ = ST_INIT; 171 State state_ = ST_INIT;
179 int signal_silent_time_in_ms_ = 0;
180 bool external_auth_enabled_ = false; 172 bool external_auth_enabled_ = false;
181 std::vector<CryptoParams> offer_params_; 173 std::vector<CryptoParams> offer_params_;
182 std::unique_ptr<SrtpSession> send_session_; 174 std::unique_ptr<SrtpSession> send_session_;
183 std::unique_ptr<SrtpSession> recv_session_; 175 std::unique_ptr<SrtpSession> recv_session_;
184 std::unique_ptr<SrtpSession> send_rtcp_session_; 176 std::unique_ptr<SrtpSession> send_rtcp_session_;
185 std::unique_ptr<SrtpSession> recv_rtcp_session_; 177 std::unique_ptr<SrtpSession> recv_rtcp_session_;
186 CryptoParams applied_send_params_; 178 CryptoParams applied_send_params_;
187 CryptoParams applied_recv_params_; 179 CryptoParams applied_recv_params_;
188 }; 180 };
189 181
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // if it is actually used. This method is only valid before the RTP params 218 // if it is actually used. This method is only valid before the RTP params
227 // have been set. 219 // have been set.
228 void EnableExternalAuth(); 220 void EnableExternalAuth();
229 bool IsExternalAuthEnabled() const; 221 bool IsExternalAuthEnabled() const;
230 222
231 // A SRTP session supports external creation of the auth tag if a non-GCM 223 // A SRTP session supports external creation of the auth tag if a non-GCM
232 // cipher is used. This method is only valid after the RTP params have 224 // cipher is used. This method is only valid after the RTP params have
233 // been set. 225 // been set.
234 bool IsExternalAuthActive() const; 226 bool IsExternalAuthActive() const;
235 227
236 // Update the silent threshold (in ms) for signaling errors.
237 void set_signal_silent_time(int signal_silent_time_in_ms);
238
239 // Calls srtp_shutdown if it's initialized. 228 // Calls srtp_shutdown if it's initialized.
240 static void Terminate(); 229 static void Terminate();
241 230
242 sigslot::repeater3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error>
243 SignalSrtpError;
244
245 private: 231 private:
246 bool SetKey(int type, int cs, const uint8_t* key, size_t len); 232 bool SetKey(int type, int cs, const uint8_t* key, size_t len);
247 // Returns send stream current packet index from srtp db. 233 // Returns send stream current packet index from srtp db.
248 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index); 234 bool GetSendStreamPacketIndex(void* data, int in_len, int64_t* index);
249 235
250 static bool Init(); 236 static bool Init();
251 void HandleEvent(const srtp_event_data_t* ev); 237 void HandleEvent(const srtp_event_data_t* ev);
252 static void HandleEventThunk(srtp_event_data_t* ev); 238 static void HandleEventThunk(srtp_event_data_t* ev);
253 239
254 rtc::ThreadChecker thread_checker_; 240 rtc::ThreadChecker thread_checker_;
255 srtp_ctx_t_* session_ = nullptr; 241 srtp_ctx_t_* session_ = nullptr;
256 int rtp_auth_tag_len_ = 0; 242 int rtp_auth_tag_len_ = 0;
257 int rtcp_auth_tag_len_ = 0; 243 int rtcp_auth_tag_len_ = 0;
258 std::unique_ptr<SrtpStat> srtp_stat_;
259 static bool inited_; 244 static bool inited_;
260 static rtc::GlobalLockPod lock_; 245 static rtc::GlobalLockPod lock_;
261 int last_send_seq_num_ = -1; 246 int last_send_seq_num_ = -1;
262 bool external_auth_active_ = false; 247 bool external_auth_active_ = false;
263 bool external_auth_enabled_ = false; 248 bool external_auth_enabled_ = false;
264 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); 249 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession);
265 }; 250 };
266 251
267 // Class that collects failures of SRTP.
268 class SrtpStat {
269 public:
270 SrtpStat();
271
272 // Report RTP protection results to the handler.
273 void AddProtectRtpResult(uint32_t ssrc, int result);
274 // Report RTP unprotection results to the handler.
275 void AddUnprotectRtpResult(uint32_t ssrc, int result);
276 // Report RTCP protection results to the handler.
277 void AddProtectRtcpResult(int result);
278 // Report RTCP unprotection results to the handler.
279 void AddUnprotectRtcpResult(int result);
280
281 // Get silent time (in ms) for SRTP statistics handler.
282 int signal_silent_time() const { return signal_silent_time_; }
283 // Set silent time (in ms) for SRTP statistics handler.
284 void set_signal_silent_time(int signal_silent_time) {
285 signal_silent_time_ = signal_silent_time;
286 }
287
288 // Sigslot for reporting errors.
289 sigslot::signal3<uint32_t, SrtpFilter::Mode, SrtpFilter::Error>
290 SignalSrtpError;
291
292 private:
293 // For each different ssrc and error, we collect statistics separately.
294 struct FailureKey {
295 FailureKey()
296 : ssrc(0),
297 mode(SrtpFilter::PROTECT),
298 error(SrtpFilter::ERROR_NONE) {
299 }
300 FailureKey(uint32_t in_ssrc,
301 SrtpFilter::Mode in_mode,
302 SrtpFilter::Error in_error)
303 : ssrc(in_ssrc), mode(in_mode), error(in_error) {}
304 bool operator <(const FailureKey& key) const {
305 return
306 (ssrc < key.ssrc) ||
307 (ssrc == key.ssrc && mode < key.mode) ||
308 (ssrc == key.ssrc && mode == key.mode && error < key.error);
309 }
310 uint32_t ssrc;
311 SrtpFilter::Mode mode;
312 SrtpFilter::Error error;
313 };
314 // For tracing conditions for signaling, currently we only use
315 // last_signal_time. Wrap this as a struct so that later on, if we need any
316 // other improvements, it will be easier.
317 struct FailureStat {
318 FailureStat()
319 : last_signal_time(0) {
320 }
321 explicit FailureStat(uint32_t in_last_signal_time)
322 : last_signal_time(in_last_signal_time) {}
323 void Reset() {
324 last_signal_time = 0;
325 }
326 int64_t last_signal_time;
327 };
328
329 // Inspect SRTP result and signal error if needed.
330 void HandleSrtpResult(const FailureKey& key);
331
332 std::map<FailureKey, FailureStat> failures_;
333 // Threshold in ms to silent the signaling errors.
334 int signal_silent_time_;
335
336 RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat);
337 };
338
339 } // namespace cricket 252 } // namespace cricket
340 253
341 #endif // WEBRTC_PC_SRTPFILTER_H_ 254 #endif // WEBRTC_PC_SRTPFILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698