Skip to content
pubscout

dart_libp2p

4.12.2, released 9 days ago by werkswinkel.com

A Dart implementation of the libp2p networking stack for peer-to-peer applications.

$ flutter pub add dart_libp2p
Source repository

What it does

Provides a modular networking stack supporting multiple transports like TCP and UDX, Noise security protocol, stream multiplexing via Yamux, and peer discovery. It enables building decentralized peer-to-peer applications and protocols in Dart.

AI-written summary of version 4.12.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are building a peer-to-peer application in Dart or Flutter.
  • You need encrypted and authenticated connections using the Noise protocol.
  • You require customizable transport layers like TCP or UDX.

Skip it when

  • You only need a simple client to talk to a traditional REST, GraphQL, or WebSocket backend.
  • You require built-in QUIC transport support.

Strengths

  • Modular architecture with pluggable transports, security, and multiplexers.
  • Built-in NAT traversal tools including hole punching and relay support.
  • Comprehensive suite of core libp2p protocols and event systems.

Weaknesses

  • Does not support the QUIC transport protocol.
  • Some advanced integration tests and features require external tools or separate packages.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
23

Add the dependency to pubspec.yaml and configure transports, security, and options in code when initializing the Libp2p host.

import 'package:dart_libp2p/dart_libp2p.dart';
import 'package:dart_libp2p/config/config.dart' as p2p_config;
import 'package:dart_libp2p/core/crypto/ed25519.dart' as crypto_ed25519;
import 'package:dart_libp2p/p2p/security/noise/noise_protocol.dart';
import 'package:dart_libp2p/p2p/transport/udx_transport.dart';
import 'package:dart_libp2p/p2p/transport/connection_manager.dart' as p2p_conn_manager;

void main() async {
  final keyPair = await crypto_ed25519.generateEd25519KeyPair();
  final connMgr = p2p_conn_manager.ConnectionManager();
  final options = [
    p2p_config.Libp2p.identity(keyPair),
    p2p_config.Libp2p.connManager(connMgr),
    p2p_config.Libp2p.transport(UDXTransport(connManager: connMgr)),
    p2p_config.Libp2p.security(await NoiseSecurity.create(keyPair)),
  ];
  final host = await p2p_config.Libp2p.new_(options);
  await host.start();
  print('Host ID: \${host.id}');
  await host.close();
}

Works with

Packages commonly used together with dart_libp2p: ones it builds on, ones built on it, and its own family.