· 2 min read

(Rust) Async state management, Multiplex p2p Networking, gRPC, Websockets

Notes of a conversation about the network architecture of a monolithic p2p service written in Rust.

Instead of my current approach of setting up the network using a set of rt::spawn threads, as well as in using the current actix-web ecosystem, I should consider setting up a Multiplex system that will allow communication via gRPC (setting up Protobuf) as well as Websockets and an HTTP(S) REST API.

Ultimately, I’ll be rewriting my monolithic application to remove the templated code I pulled from the libp2p examples so that I can structure the state management within it more appropriately (since that’s what triggered this whole discussion). I’ll also be switching to Axum instead of using Actix as it’s closer to the Tokio ecosystem, and I don’t see any real downsides for it, especially since I have some really good examples of how to structure it.

For handling the additional async threads, I’ll be switching to an architecture that creates the threads and pins them to be used in the tokio::select! macro rather than blindly spawning them, as is implemented in the websocket handler for disoxide. This should make the state management a lot more stable across the different threads. Something to note here is that this websocket handler is passing in a global state that contains the state given from the jedi temple, which seems to be including the redis pool as well as the mpsc/pubsub declarations and the JoinHandle for the tasks spawned from this thread. So it does have nested multithreading which is going all the way to the top and then shared with the Arc<Mutex<_>> which is nice.

So… a lot of work to do, but having any path forward is better than mindlessly grasping for stability.

Reference material:

Additional Misc. Reference Material:

Back to Datavault

Related Posts

View All Posts »