-
Notifications
You must be signed in to change notification settings - Fork 1.6k
gRPC: add gRPC wrapper classes to CMake build #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 67 commits
ce6949c
f6f3f84
282009c
635c473
59f070c
3139cb4
7170b70
a0f061f
5bfc05b
1d38fb1
dd3d10c
23070bb
9dca0f9
928953a
29e726c
40b6260
7a86c73
4c57926
c4e01a6
289df14
63f5146
805b673
839f408
a93b783
4fe32a1
0ea6fcc
21d30b6
7f60ad0
feb0285
8332a5f
ab6df2e
9f9d94d
555e1d8
6f0d4e6
84e454b
c96f670
e2e53b0
1bcfc0f
2d68f12
80a938e
85b6570
1cd2950
9ede2b0
0cbae74
761b26d
25a4130
2786250
8934b7a
3dd4c4a
21d95ee
4fbfcd3
b8edd81
aeb4e57
116b95e
97a5ef6
87ae3ae
5ee93e8
22efcfd
de56f42
2c0b555
3d4356f
a1883c6
9c9988b
3d5af99
48a2eb7
3b789d5
00af67c
8120e41
f76027a
5c07da4
640284e
090bd08
9408698
45a8826
3e4e9a2
80fd42c
9c33561
5a1324d
69db1e0
8a54cc7
45ff81c
64e9b59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_VERSION_H_ | ||
#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_VERSION_H_ | ||
|
||
/** Version for Firestore. */ | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
|
||
/** Version string for the Firebase Firestore SDK. */ | ||
extern const char* const firestore_version_string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be named as a constant, i.e. kFirestoreVersionString? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
} // namespace firestore | ||
} // namespace firebase | ||
|
||
#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_VERSION_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 Google | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "Firestore/core/include/firebase/firestore/firestore_version.h" | ||
|
||
#ifndef FIRFirestore_VERSION | ||
#error \ | ||
"FIRFirestore_VERSION is not defined: add -DFIRFirestore_VERSION=... to the build invocation" // NOLINT(whitespace/line_length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively to the // NOLINT at the end of an already long line, you could instead use // NOLINTNEXTLINE on the previous line instead. (https://engdoc.corp.google.com/eng/doc/devguide/cpp/styleguide.md#cpplint) Optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The combination fo the comment with line continuation confuses |
||
#endif | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
|
||
// The following two macros supply the incantation so that the C | ||
// preprocessor does not try to parse the version as a floating | ||
// point number. See | ||
// https://www.guyrutenberg.com/2008/12/20/expanding-macros-into-string-constants-in-c/ | ||
#define STR(x) STR_EXPAND(x) | ||
#define STR_EXPAND(x) #x | ||
|
||
extern const char* const firestore_version_string = STR(FIRFirestore_VERSION); | ||
|
||
} // namespace firestore | ||
} // namespace firebase |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,17 +23,17 @@ | |
#include <utility> | ||
|
||
#include "Firestore/core/include/firebase/firestore/firestore_errors.h" | ||
#include "Firestore/core/include/firebase/firestore/firestore_version.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect you can drop the fstream/sstream includes now. |
||
#include "Firestore/core/src/firebase/firestore/auth/token.h" | ||
#include "Firestore/core/src/firebase/firestore/model/database_id.h" | ||
#include "Firestore/core/src/firebase/firestore/remote/grpc_root_certificate_finder.h" | ||
#include "Firestore/core/src/firebase/firestore/util/filesystem.h" | ||
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" | ||
#include "Firestore/core/src/firebase/firestore/util/log.h" | ||
#include "Firestore/core/src/firebase/firestore/util/string_format.h" | ||
#include "absl/memory/memory.h" | ||
#include "grpcpp/create_channel.h" | ||
|
||
#import "Firestore/Source/API/FIRFirestoreVersion.h" | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
namespace remote { | ||
|
@@ -43,6 +43,7 @@ | |
using model::DatabaseId; | ||
using util::Path; | ||
using util::Status; | ||
using util::StatusOr; | ||
using util::StringFormat; | ||
|
||
namespace { | ||
|
@@ -54,22 +55,10 @@ | |
return view.data() ? std::string{view.data(), view.size()} : std::string{}; | ||
} | ||
|
||
std::string LoadCertificate(const Path& path) { | ||
std::ifstream certificate_file{path.native_value()}; | ||
HARD_ASSERT(certificate_file.good(), | ||
StringFormat("Unable to open root certificates at file path %s", | ||
path.ToUtf8String()) | ||
.c_str()); | ||
|
||
std::stringstream buffer; | ||
buffer << certificate_file.rdbuf(); | ||
return buffer.str(); | ||
} | ||
|
||
std::shared_ptr<grpc::ChannelCredentials> CreateSslCredentials( | ||
const Path& certificate_path) { | ||
const std::string& certificate) { | ||
grpc::SslCredentialsOptions options; | ||
options.pem_root_certs = LoadCertificate(certificate_path); | ||
options.pem_root_certs = certificate; | ||
return grpc::SslCredentials(options); | ||
} | ||
|
||
|
@@ -132,8 +121,7 @@ bool HasSpecialConfig(const std::string& host) { | |
// C++ SDK, etc.). | ||
context->AddMetadata( | ||
kXGoogAPIClientHeader, | ||
StringFormat("gl-objc/ fire/%s grpc/", | ||
reinterpret_cast<const char*>(FIRFirestoreVersionString))); | ||
StringFormat("gl-objc/ fire/%s grpc/", firestore_version_string)); | ||
|
||
// This header is used to improve routing and project isolation by the | ||
// backend. | ||
|
@@ -159,9 +147,8 @@ bool HasSpecialConfig(const std::string& host) { | |
const std::string& host = database_info_->host(); | ||
|
||
if (!HasSpecialConfig(host)) { | ||
Path root_certificate_path = FindGrpcRootCertificate(); | ||
return grpc::CreateChannel(host, | ||
CreateSslCredentials(root_certificate_path)); | ||
std::string root_certificate = LoadGrpcRootCertificate(); | ||
return grpc::CreateChannel(host, CreateSslCredentials(root_certificate)); | ||
} | ||
|
||
const HostConfig& host_config = Config()[host]; | ||
|
@@ -174,8 +161,15 @@ bool HasSpecialConfig(const std::string& host) { | |
// For tests only | ||
grpc::ChannelArguments args; | ||
args.SetSslTargetNameOverride(host_config.target_name); | ||
Path path = host_config.certificate_path; | ||
StatusOr<std::string> test_certificate = ReadFile(path); | ||
HARD_ASSERT(test_certificate.ok(), | ||
StringFormat("Unable to open root certificates at file path %s", | ||
path.ToUtf8String()) | ||
.c_str()); | ||
|
||
return grpc::CreateCustomChannel( | ||
host, CreateSslCredentials(host_config.certificate_path), args); | ||
host, CreateSslCredentials(test_certificate.ValueOrDie()), args); | ||
} | ||
|
||
std::unique_ptr<GrpcStream> GrpcConnection::CreateStream( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ namespace firestore { | |
namespace remote { | ||
|
||
/** | ||
* Finds the file containing gRPC root certificates (`roots.pem`, must be among | ||
* resources accessible by Firestore) and returns its path. Will trigger | ||
* assertion failure if the file cannot be found. | ||
* Finds the file containing gRPC root certificates (how it is stored differs by | ||
* platform) and returns its contents as a string. Will trigger assertion | ||
* failure if the file cannot be found or open. | ||
*/ | ||
util::Path FindGrpcRootCertificate(); | ||
std::string LoadGrpcRootCertificate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the assumption made by the previous interface that |
||
|
||
} // namespace remote | ||
} // namespace firestore | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: elsewhere we spell out "external" (
download_external_sources
,add_external_subdirectory
,external/src
, etc). This stands out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.