From b02b772954ea76b8227b3fffc817bd9254da2463 Mon Sep 17 00:00:00 2001 From: Yu Shan Date: Tue, 18 Jun 2024 17:38:11 -0700 Subject: [PATCH] Allow two service address to be registered. Allow Grpc vehicle proxy server bind to two addrs. We need one for vsock to be used by VHAL and another one for local ethernet connection. vsock local loopback does not work on the host. Flag: EXEMPT host-side component. Test: Manual test. Bug: 328316981 Change-Id: I4efc802121b780b663fd8a26b65dc56a001feff6 --- .../vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp | 10 ++++++++-- .../vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.h | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp index a6abfa308b..eb98af04fe 100644 --- a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp +++ b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp @@ -40,7 +40,11 @@ static std::shared_ptr<::grpc::ServerCredentials> getServerCredentials() { GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr, std::unique_ptr&& hardware) - : mServiceAddr(std::move(serverAddr)), mHardware(std::move(hardware)) { + : GrpcVehicleProxyServer(std::vector({serverAddr}), std::move(hardware)){}; + +GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::vector serverAddrs, + std::unique_ptr&& hardware) + : mServiceAddrs(std::move(serverAddrs)), mHardware(std::move(hardware)) { mHardware->registerOnPropertyChangeEvent( std::make_unique( [this](std::vector values) { @@ -254,7 +258,9 @@ GrpcVehicleProxyServer& GrpcVehicleProxyServer::Start() { } ::grpc::ServerBuilder builder; builder.RegisterService(this); - builder.AddListeningPort(mServiceAddr, getServerCredentials()); + for (const std::string& serviceAddr : mServiceAddrs) { + builder.AddListeningPort(serviceAddr, getServerCredentials()); + } mServer = builder.BuildAndStart(); CHECK(mServer) << __func__ << ": failed to create the GRPC server, " << "please make sure the configuration and permissions are correct"; diff --git a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.h b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.h index dd9e2aad4c..5ffb531c7a 100644 --- a/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.h +++ b/automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.h @@ -41,6 +41,9 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service { public: GrpcVehicleProxyServer(std::string serverAddr, std::unique_ptr&& hardware); + GrpcVehicleProxyServer(std::vector serverAddrs, + std::unique_ptr&& hardware); + ::grpc::Status GetAllPropertyConfig( ::grpc::ServerContext* context, const ::google::protobuf::Empty* request, ::grpc::ServerWriter* stream) override; @@ -116,7 +119,7 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service { static std::atomic connection_id_counter_; }; - std::string mServiceAddr; + std::vector mServiceAddrs; std::unique_ptr<::grpc::Server> mServer{nullptr}; std::unique_ptr mHardware;