-
After some time of looking at various examples - especially the file sharing example - it struck me that for my own efforts, it'd be really convenient if I could wrap the swarm in an actix Actor type, since actors provide a convenient mechanism for associating request and response types (handling, for example, all the request and response channel stuff). After playing around with it a bit, though, I am not sure it is possible - the relevant Does anyone have any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @raptros, Like it is done in the file-sharing example, we polled the swarm in an event-loop in a background task. To execute commands on the swarm we had a mpsc channel to the event-loop. In your case, you could simply forward messages (that your actor receives) through this channel to the background task. Additionally, the event-loop got passed an I don't think there is a way to add the swarm itself as stream if you also want direct access. But maybe this still helps. Edit: I guess you could at least save the additional background task by implementing |
Beta Was this translation helpful? Give feedback.
Hi @raptros,
In a project that I used to work on we implemented an actix actor that managed our libp2p swarm.
However, we implemented the the
Actor
trait on top of an interface similar to theClient
in the file-sharing example, instead of integrating that logic in the actor implementation itself. So an additional background task was still needed.Like it is done in the file-sharing example, we polled the swarm in an event-loop in a background task. To execute commands on the swarm we had a mpsc channel to the event-loop. In your case, you could simply forward messages (that your actor receives) through this channel to the background task.
Additionally, the event-loop got passed an
mpsc::S…