swarm with ffi #4269
-
I am working with FFI. I created a function to run libp2p via FFI. everything is working perfectly. now I need to send a message to a peer via another FFI function(rust). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I am guessing your first FFI function spawns some kind of thread that drives the swarm with an event loop? I'd create channels to send data in and out of this loop. From your first FFI function, I'd return some opaque handle type that needs to be passed in on the other functions again. (This is typical for FFI and not specific to libp2p). On the Rust side, you can then use that handle to associate the ends of the channel with them and send data into them to the |
Beta Was this translation helpful? Give feedback.
My advice from above still stands:
You should extend your
listen_event
function to also poll the receiver-end of a channel. You can store the sender-end in astatic
variable like you do with some of the other state.You can then create an FFI function that accesses that
Sender
and sends the parameters as a message into it. The message will be received by theReceiver
within the event-loop where you can pass it to theSwarm
.See https://github.com/libp2p/rust-libp2p/blob…