Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
/ flutter_libp2p Public archive

Flutter Libp2p port with FFI (experimental) Foreign Function Interface

License

Notifications You must be signed in to change notification settings

KickedDroid/flutter_libp2p

Repository files navigation

Flutter/Dart Libp2p

flutter_libp2p is implemented using rust-libp2p and FFI. Read more about rust-libp2p here

How it works

  • Dart FFI
  • flutter_rust_bridge
  • Cbor/Json RPC using embedded websockets

Usage

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);

About

Flutter Libp2p port with FFI (experimental) Foreign Function Interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published