It's heeeeere! After a very long road, and a lot of lessons learned, the Async Await refactor of js-libp2p has landed in the 0.27 release. If you're not familiar with the refactor you can read up more about the reasons and history in a recent blog post by the wonderful Alan Shaw, The Async Await Refactor. In addition to the efforts mentioned there, the refactor to js-libp2p includes a slew of additional improvements, the highlights of which you can read about below.
In addition to these highlights, we've consolidated many of the core modules of js-libp2p into js-libp2p itself in an effort to make it easier for community members to contribute. We've also consolidated our interface repositories into libp2p/js-interfaces (opens new window) and improved the documentation and test suites there.
And a wonderful bonus, we've measured memory usage improvements between 30-40% compared to the previous version, 0.26!
We're really excited for 2020 and the opportunities this HUGE effort has opened for js-libp2p, and we're looking forward to making it even better!
# π¦ Highlights
# π Improved docs
We've done an overhaul of our docs to make libp2p easier to use. Among other docs in the new doc (opens new window) folder, you can find a full list of exposed methods in the API.md (opens new window), and a guide on how to configure libp2p in CONFIGURATION.md (opens new window). We've also created a Getting Started guide (opens new window) for anyone starting out with libp2p.
# βοΈ Async/Await instead of Callbacks
All callback APIs have been changed to be async / await compliant. See the API.md (opens new window) readme for detailed usage. When migrating, you can leverage the migration guide (opens new window) to see samples on some of the common migrations you may need to make.
# π° Streaming Iterables instead of Pull Streams
Now that readable streams are async iterable, we can leverage Streaming Iterables (opens new window) instead of Pull Streams to greatly simplify the internal stream logic of libp2p. Among other things, this makes debugging streams much easier. You can check out the it-awesome repo (opens new window) for a list of an increasing number of modules built for the streaming iterables ecosystem. This also includes modules to convert to and from pull streams if you need to refactor your applications over time. If you're having trouble migrating, please feel free to reach out on the discuss forums (opens new window)!
# π Clearer Connections
We've created a whole new Connection Interface (opens new window)! Creating multiple streams off of a single connection is now much clearer, and every stream created is tracked in the Connection. This makes it much easier to keep track of every open stream, which greatly empowers resource management in js-libp2p.
// Was
libp2p.dialProtocol(remotePeerInfo, protocol, (error, stream) => {})
// Now
const connection = await libp2p.dial(remotePeerInfo)
const { stream, protocol } = await connection.newStream(protocols)
const allStreams = connection.streams
# βΉ Abortable Dials
We've reconstructed transports and connections from the ground up. This gives us the ability to pass an AbortSignal (opens new window) when dialing, so we can now properly terminate connections early. This also means we'll be able to add proper support for parallel dials to reduce connection times without running the risk of lingering dials.
const controller = new AbortController()
libp2p.dial(remotePeerInfo, { signal: controller.signal })
// after a short delay...
controller.abort()
# π The Identify Push Protocol
Identify Push (opens new window) is now available in js-libp2p. As a libp2p node changes its Multiaddrs (changes in networks) or protocols, it will broadcast those changes to all connected peers. Once support for AutoNAT and AutoRelay is added to js-libp2p, we will be able to broadcast those changes maximizing the effectiveness of those protocols.
# π Plaintext 2 for testing
We've upgraded from Plaintext 1 to 2 (opens new window). If you need to test things locally without encryption to see what's going on over the wire, Plaintext 2 makes this more viable. Public Keys are now exchanged, which is required by many protocols. This should NEVER be used in production, happy testing!
# π More polite connections
Currently when two nodes connect, they will actively ask each other what protocols they support. This ends up being multiple checks in parallel, rather than getting the information from a single Identify check. js-libp2p will now only use Identify. This greatly reduces network chatter. The peerStore
, formerly peerBook
to better match common libp2p terminology, will now emit change events for protocols. Applications that need to check for protocol support can now politely listen for updates, instead of actively checking every peer that connects.
libp2p.peerStore.on('change:protocols', ({ peerInfo, protocols }) => { ... })
# π Metrics (formerly Stats) can now be enabled/disabled
We're making stats
disabled by default and they are now available at libp2p.metrics
instead of libp2p.stats
. You can enable metrics if you need them, but for performance reasons we have disabled them by default. Good news, if you need to run them they're more performant as we've moved away from event emitting in metrics. This greatly reduces the amount of processing that happens until you explicitly request something! You can read more about Metrics at METRICS.md (opens new window).
# π API Changes
See the API.md (opens new window) readme for detailed usage on the new API. Significant breaking changes are detailed below.
- Callbacks are no longer supported, async / await is now used for all asynchronous methods. See API.md (opens new window) for a full list of methods.
- Pull streams have been replaced by Streaming Iterables (opens new window)
libp2p.peerBook
is nowlibp2p.peerStore
to match common libp2p terminology.libp2p.stats
is nowlibp2p.metrics
.libp2p.pubsub.ls
is nowlibp2p.pubsub.getTopics
.libp2p.pubsub.peers
is nowlibp2p.pubsub.getSubscribers
.libp2p.ping
now simply returns the latency of the ping. See the migration guide (opens new window) for more details.
# β€οΈ Huge thank you to everyone that made this release possible
In alphabetical order, here are the 60 humans that made 1241 contributions to this release:
- AgentJ-WR (opens new window) (1 PR, 1 issue)
- Akulich Paul (opens new window) (2 PRs, 1 issue, 2 reviews, 5 comments)
- Alan Shaw (opens new window) (16 PRs, 1 issue, 31 reviews, 14 comments)
- Alex Potsides (opens new window) (10 PRs, 6 issues, 7 reviews, 5 comments)
- Anton Nashatyrev (opens new window) (1 issue, 1 comment)
- Arve Knudsen (opens new window) (1 comment)
- Blake Byrnes (opens new window) (1 issue, 1 comment)
- bruinxs (opens new window) (1 PR, 1 issue, 1 comment)
- Carson Farmer (opens new window) (3 PRs, 1 issue, 3 reviews, 17 comments)
- Cayman (opens new window) (2 PRs, 1 issue, 17 reviews, 7 comments)
- Chadwick Dahlquist (opens new window) (1 comment)
- Christian M (opens new window) (1 PR)
- Christian Paul (opens new window) (1 PR)
- David Dias (opens new window) (2 PRs, 4 issues, 21 reviews, 21 comments)
- Didrik NordstrΓΆm (opens new window) (1 PR, 1 comment)
- Dietrich Ayala (opens new window) (1 comment)
- Dima (opens new window) (1 issue)
- dirkmc (opens new window) (5 PRs, 1 issue, 7 reviews, 2 comments)
- emclab (opens new window) (1 issue, 1 comment)
- Eric Tu (opens new window) (1 review)
- folex (opens new window) (1 comment)
- Friedel Ziegelmayer (opens new window) (1 review, 1 comment)
- George Farcasiu (opens new window) (1 comment)
- Gopalakrishna Palem (opens new window) (2 issues)
- Gregory Markou (opens new window) (4 reviews, 3 comments)
- Guo Liu (opens new window) (1 issue, 1 comment)
- Henrique Dias (opens new window) (1 review, 2 comments)
- Hugo Dias (opens new window) (2 reviews)
- Jacob Heun (opens new window) (59 PRs, 6 issues, 240 reviews, 80 comments)
- Jorropo (opens new window) (1 PR)
- kumavis (opens new window) (1 PR, 1 issue, 1 review, 6 comments)
- Maciej KrΓΌger (opens new window) (2 PRs, 2 issues, 17 reviews, 30 comments)
- Marcin Rataj (opens new window) (2 PRs, 13 reviews, 1 comment)
- Marcus Bernales (opens new window) (1 PR)
- Marin PetruniΔ (opens new window) (1 PR, 1 issue, 5 reviews, 3 comments)
- Maying(Matt) Shi (opens new window) (1 issue)
- mcclure (opens new window) (2 issues, 3 comments)
- Mikeal Rogers (opens new window) (1 review)
- Nate Foss (opens new window) (2 PRs)
- Oli Evans (opens new window) (2 comments)
- phillmac (opens new window) (1 PR, 1 comment)
- RaΓΊl Kripalani (opens new window) (1 comment)
- ridenaio (opens new window) (1 issue)
- Roman Proskuryakov (opens new window) (1 comment)
- Rui Fortes (opens new window) (2 issues)
- Ryan Bell (opens new window) (1 PR)
- shresthagrawal (opens new window) (1 PR, 1 issue)
- Stavros Charitakis (opens new window) (1 issue)
- swedneck (opens new window) (1 PR)
- Teri Chadbourne (opens new window) (1 comment)
- Tony Jin (opens new window) (1 PR, 1 issue, 2 comments)
- Topper Bowers (opens new window) (3 PRs, 2 issues, 13 comments)
- tuyennhv (opens new window) (1 review, 1 comment)
- Vasco Santos (opens new window) (91 PRs, 7 issues, 254 reviews, 79 comments)
- Yusef Napora (opens new window) (1 review)
- Ziwei_Wei (opens new window) (1 comment)
# ππ½ Want to contribute?
Would you like to contribute to the libp2p project and don't know how? Well, there are a few places you can get started:
- Check the issues with the
help wanted
label in the libp2p repo (opens new window) - Join an IPFS All Hands, introduce yourself and let us know where you would like to contribute - https://github.com/ipfs/team-mgmt#all-hands-call
- Hack with IPFS and show us what you made! The All Hands call is also the perfect venue for demos, join in and show us what you built
- Join the discussion at http://discuss.libp2p.io/ and help users finding their answers.
- Join the β‘οΈlibp2p Weekly Sync ππ½ (opens new window) and be part of the Sprint action!
# βοΈ Do you have questions?
The best place to ask your questions about libp2p, how it works and what you can do with it is at discuss.libp2p.io (opens new window). We are also available at the #libp2p channel on Freenode.