Introduce option to enable SSL encryption for LocalTrajectoryUploader (#1084)

master
Christoph Schütte 2018-04-18 16:47:03 +02:00 committed by Wally B. Feed
parent 3383643627
commit 337e594662
6 changed files with 22 additions and 9 deletions

View File

@ -41,8 +41,8 @@ const common::Duration kPopTimeout = common::FromMilliseconds(100);
class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface {
public:
LocalTrajectoryUploader(const std::string &uplink_server_address,
int batch_size);
~LocalTrajectoryUploader() {}
int batch_size, bool enable_ssl_encryption);
~LocalTrajectoryUploader();
// Starts the upload thread.
void Start() final;
@ -75,9 +75,13 @@ class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface {
};
LocalTrajectoryUploader::LocalTrajectoryUploader(
const std::string &uplink_server_address, int batch_size)
const std::string &uplink_server_address, int batch_size,
bool enable_ssl_encryption)
: client_channel_(::grpc::CreateChannel(
uplink_server_address, ::grpc::InsecureChannelCredentials())),
uplink_server_address,
enable_ssl_encryption
? ::grpc::SslCredentials(::grpc::SslCredentialsOptions())
: ::grpc::InsecureChannelCredentials())),
batch_size_(batch_size) {
std::chrono::system_clock::time_point deadline(
std::chrono::system_clock::now() +
@ -88,6 +92,8 @@ LocalTrajectoryUploader::LocalTrajectoryUploader(
}
}
LocalTrajectoryUploader::~LocalTrajectoryUploader() {}
void LocalTrajectoryUploader::Start() {
CHECK(!shutting_down_);
CHECK(!upload_thread_);
@ -180,9 +186,10 @@ void LocalTrajectoryUploader::EnqueueSensorData(
} // namespace
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
const std::string &uplink_server_address, int batch_size) {
return make_unique<LocalTrajectoryUploader>(uplink_server_address,
batch_size);
const std::string &uplink_server_address, int batch_size,
bool enable_ssl_encryption) {
return make_unique<LocalTrajectoryUploader>(uplink_server_address, batch_size,
enable_ssl_encryption);
}
} // namespace cloud

View File

@ -55,7 +55,8 @@ class LocalTrajectoryUploaderInterface {
// Returns LocalTrajectoryUploader with the actual implementation.
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
const std::string& uplink_server_address, int batch_size);
const std::string& uplink_server_address, int batch_size,
bool enable_ssl_encryption);
} // namespace cloud
} // namespace cartographer

View File

@ -61,7 +61,8 @@ MapBuilderServer::MapBuilderServer(
if (!map_builder_server_options.uplink_server_address().empty()) {
local_trajectory_uploader_ = CreateLocalTrajectoryUploader(
map_builder_server_options.uplink_server_address(),
map_builder_server_options.upload_batch_size());
map_builder_server_options.upload_batch_size(),
map_builder_server_options.enable_ssl_encryption());
}
server_builder.RegisterHandler<handlers::AddTrajectoryHandler>();
server_builder.RegisterHandler<handlers::AddOdometryDataHandler>();

View File

@ -39,6 +39,8 @@ proto::MapBuilderServerOptions CreateMapBuilderServerOptions(
lua_parameter_dictionary->GetString("uplink_server_address"));
map_builder_server_options.set_upload_batch_size(
lua_parameter_dictionary->GetInt("upload_batch_size"));
map_builder_server_options.set_enable_ssl_encryption(
lua_parameter_dictionary->GetBool("enable_ssl_encryption"));
return map_builder_server_options;
}

View File

@ -25,4 +25,5 @@ message MapBuilderServerOptions {
cartographer.mapping.proto.MapBuilderOptions map_builder_options = 4;
string uplink_server_address = 5;
int32 upload_batch_size = 6;
bool enable_ssl_encryption = 7;
}

View File

@ -21,4 +21,5 @@ MAP_BUILDER_SERVER = {
server_address = "0.0.0.0:50051",
uplink_server_address = "",
upload_batch_size = 100,
enable_ssl_encryption = false,
}