flutter_libp2p is implemented using rust-libp2p and FFI. Read more about rust-libp2p here
- Dart FFI
- flutter_rust_bridge
- Cbor/Json RPC using embedded websockets
To spawn a libp2p node in flutter_libp2p use the start method
flutter_libp2p.spawnNode();
Listen to Swarm events
EventBus swarmEvents = await flutter_libp2p.events();
swarmEvents.on<ConnectionEstablished>().listen((event) {
//Do something
print(event.peerID);
});
To use in your flutter app you can call flutter_libp2p.spawnNode()
in the initState method in main.dart like so
class _MyAppState extends State<MyApp> {
....
@override
void initState() {
super.initState();
flutter_libp2p.spawnNode();
}
.... //Proceeding Code
}
Get the current Local Peer Id
String pid = await flutter_libp2p.localPeerId();
Dial one or multiple from a list of Multi-Addresses
List<String> toDial = [
"/ip4/172.30.144.1/tcp/42006/p2p/12D3KooWDk4Dez7KeWi5Z6JMVgQdEateaBY26yBpasdUedn29GaA"
];
// Note dial will not return result, instead event is sent through event stream
await flutter_libp2p.dial(toDial);