Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

peer.ID does not work as map key in JSON maps #79

Open
hsanjuan opened this issue Feb 27, 2019 · 2 comments
Open

peer.ID does not work as map key in JSON maps #79

hsanjuan opened this issue Feb 27, 2019 · 2 comments

Comments

@hsanjuan
Copy link

Since peer.IDs defines themselves as str, defining a map[peer.ID]<type> and marshaling that to JSON does not make use of the MarshalText() facility to encode the map keys. Somehow default encoding/decoding when doing it doesn't work (it decodes peers with different IDs but doesn't complain, which is worse).

See golang/go#28827

Probably doing the same thing as cids and switching to type ID struct { str string } would fix this.

However, this might be very breaking because people rely on doing pid1 == pid2 (and I think that would stop working, at least from outside this package? it is not clear from the Go documentation).

Thoughts?

@vyzo
Copy link
Contributor

vyzo commented Feb 28, 2019

Let's not change that, the pid1 == pid2 test is prevalent in the codebase.

@Stebalien
Copy link
Member

pid1 == pid2 would still work with type ID struct { str string }. The only issue would be pid1 == "" (which we do use) but I can live with that.

@Stebalien Stebalien transferred this issue from libp2p/go-libp2p-peer Dec 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants