ConsenSysMesh / cava

ConsenSys core libraries for Java & Kotlin
Apache License 2.0
84 stars 34 forks source link

Add a scuttlebutt-mux module for multiplexing RPC requests into futures and streams #202

Closed Happy0 closed 5 years ago

Happy0 commented 5 years ago

There is still work to do in this pull request, but I wanted to open it early to make sure you are okay with the general direction before getting too deep into it. This depends on the commits from https://github.com/ConsenSys/cava/pull/201 , so the changes from that pull request are also in the 'files changed.'

This introduces functionality which allows you to make an RPC request and receive a future which will be completed when the server responses to the RPC message with the same request number or start a stream which will be updated on each arriving RPC message with the original stream's request number.

This will allow higher level libraries to expose RPC method calls building on these primitives. For example, we could have a whoAmI method with the signature Future<PublicKey> whoAmI() which uses these primitives under the hood.

Additionally, I modified the ClientHandlerFactory and associated classes in scuttlebutt-rpc to use generics so that they can be constructed with something which extends ClientFactory

Does this general approach make sense to you?

TODO:

- [ ] Make the corresponding changes for the Server classes (at the moment this PR focuses on the client functionality as this is what I'm going to be using for my project.)

atoulme commented 5 years ago

You will need to rebase this branch, sorry. I squashed the previous PR.

atoulme commented 5 years ago

Let me know if you can rebase and clean up and I'll take a good pass at it. I can also do it for you time depending.

Happy0 commented 5 years ago

Thanks @atoulme - I've just rebased this against master :).

Feel free to give it a review.

Happy0 commented 5 years ago

Thanks for the review, @atoulme .

I'll rework the following and then update this PR again:

atoulme commented 5 years ago

:+1: whatever helps you get the job done.

Happy0 commented 5 years ago

@atoulme , the pull request is ready for review again.

I made the following changes:

Happy0 commented 5 years ago

@atoulme - any idea when you'll get a chance to review this?

Happy0 commented 5 years ago

Thanks @atoulme !