-
Notifications
You must be signed in to change notification settings - Fork 75
feat: support encoding/decoding peer IDs as CIDs in text #41
Conversation
Why don't we change this default now already? |
This change makes sense to me. If we change the default now we wouldn't give the network any time to upgrade. This would cause the node to announce its peer id as a cid hash wouldn't it? One question, right now we're using the |
Compatibility.
We're not changing the wire format, just the format in text.
The key already specifies that internally. libp2p-key just means that we're pointing to a protobuf with the structure |
Great, thanks for clarifying. 👍 |
OK, but is there an upgrade timeline? It says If we are supposed to move from IDB58Encode to Encode all over our code, and libp2p will one day flip the switch for us, then it may just flip the switch now in the Encode function. Why not making the move from |
This is a two step upgrade:
If we start encoding as CIDs now, peers using the old version won't be able to understand peer IDs encoded by the new version. This won't break the network but it will confuse users.
Sure. How about 3 months after the last libp2p implementation upgrades and releases? |
PSA: proposed change to libp2p specs to default text representation to CID in Base32:
|
d6d45cb
to
3c85be0
Compare
4cc27af
to
0bdeee6
Compare
@@ -155,10 +158,66 @@ func IDHexDecode(s string) (ID, error) { | |||
} | |||
|
|||
// IDHexEncode returns the hex-encoded multihash representation of the ID. | |||
// | |||
// Deprecated: Don't raw-hex encode peer IDs, use base16 CIDs. | |||
func IDHexEncode(id ID) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really remove these. But that's a breaking change and we can do that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just two nits about usage of acronyms which I'd like addressed. Since these two methods are in the public API, let's try to be as idiomatic as possible.
// ToCid encodes a peer ID as a CID of the public key. | ||
// | ||
// If the peer ID is invalid (e.g., empty), this will return the empty CID. | ||
func ToCid(id ID) cid.Cid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: go style is to capitalise acronyms. We should create an alias cid.CID => cid.Cid
.
func ToCid(id ID) cid.Cid { | |
func ToCID(id ID) cid.Cid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raulk I don't think we should introduce new convention here.
All our codebases already use things like NewCidV1
and FromCid
.
If we choose to change them to use capitalization, that needs to happen across all repos (in separate, coordinated PRs), otherwise we just introduce noise by mixing conventions.
} | ||
|
||
// FromCid converts a CID to a peer ID, if possible. | ||
func FromCid(c cid.Cid) (ID, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func FromCid(c cid.Cid) (ID, error) { | |
func FromCID(c cid.Cid) (ID, error) { |
I'm fine with those changes but they are inconsistent with the rest of go-ipfs/go-libp2p which we're not going to change as following a style guideline isn't worth the confusion of having two ways to do the same thing. |
@raulk Would it be ok to rebase it on master and merge as-is? 🙏 |
Go ahead! |
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
@raulk @Stebalien I am missing permission to push to this branch – mind adding me, or rebasing and applying below fix yourself?
The only conflict with - - 1.12.x
+ - 1.13.x |
Welcome to the go-libp2p team!
|
What:
Why:
pids-as-cids on the wire down the road but that's something we can revisit if it ever becomes relevant.
See libp2p/specs#111 for context.
Deviations from that issue:
Alternative: Hack this into go-ipfs and make it only valid in
/ipns
links. Honestly, we can do that first and then merge this later.