RPC: Implement a client bootstrap status method.
In our RPC system, we want a way to query the current client bootstrap status, and to watch for changes in bootstrap status. This example will shape some of our RPC design going forward.
I'm working on this now, and have hit a few design questions.
Q1: Is there a "status" method that's generic over objects?
As it stands, our code wants each defined RPC Method
to have a single Output
type that is the same for every implementation of that Method
. That means that we can't easily define a method whose output type is input-dependent.
This came up because I was thinking of making a "status" method. But I can't, since I want the method to returns a ClientBootstrapStatus
for TorClients, but an OnionBootStrapStatus for onion services and so on. Thus, those can't be the same method in our current system.
Instead I think it would make sense to say that "status" can be a generic object over many kinds of object, but its return type can depend on the type of object it's invoked on. So "status" on a client can let you know if client is bootstrapped; "status" on an onion service can let you know about the onion service's status, but they can return different types that get serialized to JSON differently. Does that seem plausible?
Q2: Should method behavior depend on whether there are update streams?
I see two ways to handle updates here.
Option 1 is to define a "status" method that returns a status immediately, and a separate "watch" method that runs forever (or until cancelled) and sends updates to the caller. Calling "watch" without requesting updates will run forever, but do nothing until it's cancelled.
Option 2 is to define the "status" method that returns a status immediately if no updates were requested, but which runs forever if updates were requested.
I think option 1 is maybe cleaner.