Skip to content
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

RPC Hooks or ProtocolMessenger configuration option #757

Open
dennis-tra opened this issue Dec 8, 2021 · 0 comments
Open

RPC Hooks or ProtocolMessenger configuration option #757

dennis-tra opened this issue Dec 8, 2021 · 0 comments

Comments

@dennis-tra
Copy link
Contributor

I'm interested in conducting some measurements around how the current DHT implementation performs. Therefore, I wanted to hook into the RPC calls and track when which RPC is performed and how long it took.

In my concrete case, I'm measuring the different steps of the provide process. While I'm able to subscribe to query events via routing.RegisterForQueryEvents, I haven't found a way to know when the actual ADD_PROVIDER RPCs are performed.

My first idea was to implement the dht_pb.MessageSender interface which would just wrap the actual dht_pb.ProtocolMessenger and enrich it with some tracking code. However, I didn't see an option to actually pass my implementation to the IpfsDHT as it's an unexported field (IpfsDHT.protoMessenger) and only initialized here.

Then I thought, I'll just provide my own MessageSenderImpl and wrap the one that's used by the ProtocolMessenger. Unfortunately, the messageSenderImpl is in an internal package. Even if it weren't in an internal package I wouldn't be able to pass it to the IpfsDHT either (afaict).

Now the ugly part: I ended up copying the messageSenderImpl code, enriching it with my tracking code, passing the updated implementation to dht_pb.NewProtocolMessenger and then monkey patching the dht_pb.NewProtocolMessenger package method to return my own implementation when dht.New is called.

The code can be found here. Just for the record, it works :D.

  • Is there another way to track the RPCs that I'm missing?
  • If not, would it be possible...
    • to add a configuration option where one can provide one's own ProtocolMessenger or
    • to provide a similar hook to RegisterForQueryEvents like RegisterForRPCEvents?
@dennis-tra dennis-tra changed the title Adding RPC Hooks or allow configuration of own MessageSender Adding RPC Hooks or allow configuration of own ProtocolMessenger Dec 8, 2021
@dennis-tra dennis-tra changed the title Adding RPC Hooks or allow configuration of own ProtocolMessenger RPC Hooks or ProtocolMessenger configuration option Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant