1

I'm trying do some reverse engineering trying to understand what services are called among several .proto files. My question is if it's possible to implement a service on the server that handles all the call made and gives me the information of which function and service was called.

Example:

protocol.proto

syntax = "proto3";

package greating;

message PersonRequest {
    string name = 1;
    int32 age = 2;
}

message PersonResponse {
    string message = 1;
}

service GreatingService {
    rpc helloPerson (PersonRequest) returns (PersonResponse);
} 

service WarningService {
    rpc attentionPerson (PersonRequest) returns (PersonResponse);
}


server.js

const packageDefinition = protoLoader.loadSync("greating.proto");
const greatingProto = grpc.loadPackageDefinition(packageDefinition);

var server = new grpc.Server();

server.addService(greatingProto.greating.GreatingService.service, {
    helloPerson: function(call, callback) {
        let response = `Hello ${call.request.name}! You're ${call.request.age} years old`;

        return callback(null, { message: response });
    }
});

server.addService(greatingProto.greating.WarningService.service, {
    helloPerson: function(call, callback) {

        let response = `Attention ${call.request.name}! You're  ${call.request.age} years left to live`;

        return callback(null, { message: response });
    }
});


What I want to do is to implement a 3rd function that handles both (all) calls, and displays which service was called. Something like this:

server.addService("*", {
    function(call, callback) {
        let response = `The service ${call.service}, function ${call.function} was called.`;

        return callback(null, { message: response });
    }
});

Is there a way to do this?

Thank you.

  • I don't think this affects your question, but in your code for handling the `WarningService` you are passing a function called `helloPerson`, not `attentionPerson`. I believe if you run that code you should see a warning that the implementation for `attentionPerson` was not provided. – murgatroid99 Feb 21 '20 at 19:19
  • You're correct. That was a copy-paste mistake. Than you. – Leonardo Teixeira Feb 26 '20 at 10:12

1 Answers1

1

No, grpc does not support wildcard method handlers, or any other way of handling every incoming request with a single handler.

murgatroid99
  • 19,007
  • 10
  • 60
  • 95