How to know the port at which a gRPC request was received

1.1k Views Asked by At

I have a c++ gRPC service which listens on multiple ports, 55555, 44444 and 44888, with the following RPC:

message FooRequest { string message = 1; }
message FooResponse { string message = 1; }
service FooService {
  rpc FooRpc(FooRequest) returns (FooResponse) {}
}

I add multiple ports for listening by calling the API grpc::ServerBuilder::AddListeningPort(...)

So clients of my service can invoke the RPC at any of these ports. I want to know on the service side, at which port the RPC was received, is it possible?

Status FooRpc(ServerContext* context, const FooRequest* request,
              FooResponse* response) override {
 // how to know the port at which this RPC was received?
 return Status::OK;
}

I want to use different types of authentication on RPCs received on different ports. Port 55555 is exposed only within the device, (inter process communication) so requests received on it don't need authentication. Port 44888 is exposed to the internet and so we want certificate based authentication for requests received on it.

0

There are 0 best solutions below