libp2p-v0.52.0 #4098
Replies: 3 comments 11 replies
-
Yay! I hope it is done better than in Go port. They have hardcoded network classes that are always considered private, regardless of the configuration (and forgot to mention it in the docs), including |
Beta Was this translation helpful? Give feedback.
-
|
Hey! After the merge of the Thanks! 🙇 |
Beta Was this translation helpful? Give feedback.
-
|
Hi, thanks for the Previously, I was using the enum variants to achieve this and they have been removed but it seems to me that I should be able to convert the ed25519 public key bytes into a Any thoughts on the best way to support this use case? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Automatic kademlia client/server mode
Let's get the biggest one out the way first, I promise the other points are easier explained but equally exciting.
The tl;dr is: Healthier Kademlia routing tables and an improved developer experience.
If you don't know about Kademlia's client/server mode, checkout the specs.
With the
v0.52release,rust-libp2pautomatically configures Kademlia in client or server mode depending on our external addresses.If we have a confirmed, external address, we will operate in server-mode, otherwise client-mode.
This is entirely configuration-free (yay!) although follow-up work is under-way to allow setting this manually in certain situations: #4074.
We can now do the following:
ConnectionEvent::LocalProtocolsChange.libp2p-identifypicks up this change and pushes it to all connected remote nodes.To implement this, several other features/issues had to be fixed.
If you are interested in the details, read on:
Simplify the scoring mechanism of external addresses: #3954
As a consequence, the observed address reported by identify is no longer considered an external address but just an address candidate.
Checkout the changelog-entry for a way of restoring the old behaviour.
Changes to the supported protocols are now detected at runtime and communicated to all protocols: #3651.
Previously, a protocol could retrieve the supported protocols via
PollParameters::supported_protocols.This list however was computed at start-up and was static.
Now,
ConnectionEventhas two new variants:ProtocolsAddedandProtocolsRemovedare iterators over a (new) type calledStreamProtocol.Protocols are now enforced to be valid UTF-8 strings: #3746.
This was always the case in the specs but the
rust-libp2pimplementation was lagging behind here and improperly represented them as bytes internally.Local changes to our protocols (i.e. a node going from Kademlia server to client mode) are now immediately pushed to the remote via the
/ipfs/id/push/1.0.0protocol: #3980.Not only does this work out-of-the-box and thus improves the developer experience of
rust-libp2p, it should also result in a much more useful and up-to-date routing table for all nodes on a Kademlia DHT.Type-safe
/p2pmultiaddressesThe
/p2pprotocol of multiaddresses specifies the identity of a peer in the form of aPeerIdsuch as12D3KooWETLZBFBfkzvH3BQEtA1TJZPmjb4a18ss5TpwNU7DHDX6.Yet for the longest time, the type-definition of the
/p2pprotocol looked like this:Every
PeerIdis a validMultihashbut not vice-versa.Dang!
That is a lot of "impossible" errors that the type-system should avoid.
Thanks to a lot of work, it now looks like this:
More consistent event/command naming
Naming is hard and humans are creatures of habit.
Thus, once familiar with certain names, it is often hard to see how they make absolutely no sense at all to newcomers.
In the
v0.52release we renamed several associated types and enums which hopefully make the message-passing system implemented inrust-libp2peasier to grasp.A quick recap:
NetworkBehaviourrepresent a protocol's state across all peers and connections.ConnectionHandlerrepresents a protocol's state for a single connection to a peer.NetworkBehaviours are composed into a tree using#[derive(NetworkBehaviour)]and run inside aSwarmNetworkBehaviours can emit events to theSwarm.This used to be called
OutEvent.Now, its aptly named
ToSwarm:Returning one of these events was previously done with a
NetworkBehaviourAction::GenerateEvent, a type-name so long you were grateful for autocomplete.These actions are essentially commands that are issued to the swarm.
What could possibly be a good name for that?
I present:
We followed the same strategy for
ConnectionHandler.A
ConnectionHandlercan receive messages from aNetworkBehaviourviaToSwarm::NotifyHandler(gosh, that was so much easier to write, why didn't we do this earlier?) and send message to itsNetworkBehaviour.The associated types defining these messages are now called
ToBehaviourandFromBehaviour, representing where the message is going / coming from.Previously, they carried the generic names
InEventandOutEventwhich had me utterly confused when I first started working onrust-libp2p.To wrap it all up, the
ConnectionHandlerEvent::Customvariant is now calledConnectionHandlerEvent::NotifyBehaviour, making it clear what happens to types returned here.Improved ergonomics around stream errors
Oh, isn't this one of my favourites!
Ever wondered why
ConnectionHandlerUpgrErrhad what felt like 10 layers of nested enums?So did we and went ahead and fixed this in #3882.
This is what it looked like before:
Now, it looks like this:
But that is not it!
Previously, we would give you one of these
ConnectionHandlerUpgrErrwhen an inbound stream failed.But, what exactly does
ProtocolError::InvalidMessagefor example mean for an inbound stream?How would we even figure out, which protocol (read
ConnectionHandler) this should be dispatched to if we failed to negotiate the protocols?Well, you might have guessed it.
It is impossible to dispatch this to the correct one, so we just informed all protocols.
But that was pretty useless.
If we don't know, which stream a protocol belongs to, we shouldn't just inform all of them.
Thus, in #3605 we stopped this which removes several "impossible" error paths.
Simpler noise interface
Since its introduction, the
libp2p-noisecrate supported a wide range of handshake patterns.The libp2p specs however only documents the
XXhandshake: libp2p/specs/noise.Supporting additional patterns introduced significant complexity to the codebase.
We decided to deprecate and remove them.
This significantly reduced the complexity of the
libp2p-noiseimplementation (-1000 LoC!).Additionally, it allowed us to finally adopt the naming conventions we have been pursuing across the workspace for
libp2p-noise.Using the noise handshake is now as simple as:
Request-response protocols using serde
A simple, yet impactful contribution was made by @dgarus in #3952:
libp2p::request_response::cbor::Behaviour<Req, Res>libp2p::request_response::json::Behaviour<Req, Res>These two, new type-aliases come with a pre-configured CBOR/JSON codec and only need to be parameterised by the
ReqandRestypes.The only requirement is that the types implement
serde::{Serialize,Deserialize}.Defining a request-response protocol has never been easier in
rust-libp2p!As with any code that serializes data structures, be aware that any changes to it can easily be breaking and thus not backwards-compatible with older versions.
Hole-punching for QUIC
Despite still being in alpha, our QUIC implementation can now establish direct connections across certain NATs, i.e. hole-punching!
This was contributed by @arpankapoor in #3964.
You don't need to configure anything special besides the
dcutrbehaviour.See the dcutr-example in our repository for details.
Thanks!
A big thanks to all people that contributed to this release.
In alphabetical order:
Closing
Well done for making it to the end!
As always, a detailed log of changes for every release can be found in our repository: CHANGELOG.md.
If you are struggling with an upgrade, feel free to tag Max (@mxinden) or myself (@thomaseizinger) in a PR and we'll try to help.
Happy coding!
This discussion was created from the release libp2p-v0.52.0.
Beta Was this translation helpful? Give feedback.
All reactions