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

Side by Side Diff: talk/app/webrtc/dtlsidentitystore.h

Issue 1176383004: DtlsIdentityStore[Interface/Impl] updated, DtlsIdentityService to be removed (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge w master AFTER the landing of 1268363002. "CreatePC(service,store)" using store instead of service. Created 5 years, 4 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
« no previous file with comments | « talk/app/webrtc/dtlsidentityservice.cc ('k') | talk/app/webrtc/dtlsidentitystore.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 // TODO(hbos): To be implemented. 78 // TODO(hbos): To be implemented.
79 // This interface defines an in-memory DTLS identity store, which generates DTLS 79 // This interface defines an in-memory DTLS identity store, which generates DTLS
80 // identities. 80 // identities.
81 // APIs calls must be made on the signaling thread and the callbacks are also 81 // APIs calls must be made on the signaling thread and the callbacks are also
82 // called on the signaling thread. 82 // called on the signaling thread.
83 class DtlsIdentityStoreInterface { 83 class DtlsIdentityStoreInterface {
84 public: 84 public:
85 virtual ~DtlsIdentityStoreInterface() { } 85 virtual ~DtlsIdentityStoreInterface() { }
86 86
87 // The |observer| will be called when the requested identity is ready, or when
88 // identity generation fails.
87 virtual void RequestIdentity( 89 virtual void RequestIdentity(
88 rtc::KeyType key_type, 90 rtc::KeyType key_type,
89 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) = 0; 91 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) = 0;
90 }; 92 };
91 93
92 // This class implements an in-memory DTLS identity store, which generates the 94 // The WebRTC default implementation of DtlsIdentityStoreInterface.
93 // DTLS identity on the worker thread. 95 // Identity generation is performed on the worker thread.
94 // APIs calls must be made on the signaling thread and the callbacks are also 96 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface,
95 // called on the signaling thread. 97 public rtc::MessageHandler {
96 class DtlsIdentityStore : public rtc::MessageHandler {
97 public: 98 public:
98 static const char kIdentityName[]; 99 // This will start to preemptively generating an RSA identity in the
100 // background if the worker thread is not the same as the signaling thread.
101 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread,
102 rtc::Thread* worker_thread);
103 ~DtlsIdentityStoreImpl() override;
99 104
100 DtlsIdentityStore(rtc::Thread* signaling_thread, 105 // DtlsIdentityStoreInterface override;
101 rtc::Thread* worker_thread); 106 void RequestIdentity(
102 virtual ~DtlsIdentityStore(); 107 rtc::KeyType key_type,
103 108 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override;
104 // Initialize will start generating the free identity in the background.
105 void Initialize();
106
107 // The |observer| will be called when the requested identity is ready, or when
108 // identity generation fails.
109 void RequestIdentity(webrtc::DTLSIdentityRequestObserver* observer);
110 109
111 // rtc::MessageHandler override; 110 // rtc::MessageHandler override;
112 void OnMessage(rtc::Message* msg) override; 111 void OnMessage(rtc::Message* msg) override;
113 112
114 // Returns true if there is a free identity, used for unit tests. 113 // Returns true if there is a free RSA identity, used for unit tests.
115 bool HasFreeIdentityForTesting() const; 114 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const;
116 115
117 private: 116 private:
117 void GenerateIdentity(
118 rtc::KeyType key_type,
119 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer);
120 void OnIdentityGenerated(rtc::KeyType key_type,
121 rtc::scoped_ptr<rtc::SSLIdentity> identity);
122
123 class WorkerTask;
124 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask>
125 WorkerTaskMessageData;
126
127 // A key type-identity pair.
128 struct IdentityResult {
129 IdentityResult(rtc::KeyType key_type,
130 rtc::scoped_ptr<rtc::SSLIdentity> identity)
131 : key_type_(key_type), identity_(identity.Pass()) {}
132
133 rtc::KeyType key_type_;
134 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
135 };
136
137 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData;
138
118 sigslot::signal0<> SignalDestroyed; 139 sigslot::signal0<> SignalDestroyed;
119 class WorkerTask;
120 typedef rtc::ScopedMessageData<DtlsIdentityStore::WorkerTask>
121 IdentityTaskMessageData;
122
123 void GenerateIdentity();
124 void OnIdentityGenerated(rtc::scoped_ptr<rtc::SSLIdentity> identity);
125 void ReturnIdentity(rtc::scoped_ptr<rtc::SSLIdentity> identity);
126
127 void PostGenerateIdentityResult_w(rtc::scoped_ptr<rtc::SSLIdentity> identity);
128 140
129 rtc::Thread* const signaling_thread_; 141 rtc::Thread* const signaling_thread_;
142 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over
143 // to 2048, DtlsIdentityStore should use a new thread and not the "general
144 // purpose" worker thread.
130 rtc::Thread* const worker_thread_; 145 rtc::Thread* const worker_thread_;
131 146
132 // These members should be accessed on the signaling thread only. 147 struct RequestInfo {
133 int pending_jobs_; 148 RequestInfo()
134 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; 149 : request_observers_(), gen_in_progress_counts_(0), free_identity_() {}
135 typedef std::queue<rtc::scoped_refptr<webrtc::DTLSIdentityRequestObserver>> 150
136 ObserverList; 151 std::queue<rtc::scoped_refptr<DtlsIdentityRequestObserver>>
137 ObserverList pending_observers_; 152 request_observers_;
153 size_t gen_in_progress_counts_;
154 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_;
155 };
156
157 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|.
158 RequestInfo request_info_[rtc::KT_LAST];
138 }; 159 };
139 160
140 } // namespace webrtc 161 } // namespace webrtc
141 162
142 #endif // TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_ 163 #endif // TALK_APP_WEBRTC_DTLSIDENTITYSTORE_H_
OLDNEW
« no previous file with comments | « talk/app/webrtc/dtlsidentityservice.cc ('k') | talk/app/webrtc/dtlsidentitystore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698