Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider records use multihashes instead of CIDs #422

Merged
merged 3 commits into from
Jan 2, 2020

Conversation

aschmahmann
Copy link
Contributor

This makes it so that provider records use multihashes instead of CIDs, solving the most important part of libp2p/go-libp2p#755. This is effectively a wire protocol fix and does not change any of the external facing DHT APIs.

Note: This change will have a network breaking effect for users advertising provider records for CIDv1 CIDs, but should not effect anyone using CIDv0 CIDs.

@aschmahmann aschmahmann force-pushed the feat/advertise-multihash branch 2 times, most recently from db32365 to e589904 Compare December 12, 2019 00:11
handlers.go Outdated
@@ -356,13 +357,13 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
defer func() { logger.FinishWithErr(ctx, _err) }()
logger.SetTag(ctx, "peer", p)

c, err := cid.Cast([]byte(pmes.GetKey()))
_, h, err := mh.MHFromBytes(pmes.GetKey())
Copy link
Contributor Author

@aschmahmann aschmahmann Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raulk we'd like to switch from provider records using CIDs to Multihashes, to support finding peers with CIDv0 and CIDv1 of the same multihash. While this will break behavior for current users of CIDv1, since peers with an updated DHT will look for and advertise to the multihash instead of the CID, (CIDv0 users are protected since CIDv0 = Multihash SHA256), it will help the network longer term.

On the "server" end we previously checked that the key that we were adding providers for was a CID (the code change above). Initially I started just switching all the things associated with Providers to use Multihashes instead of CIDs. However, this does mean that a new server will reject advertisements from old users of CIDv1.

I was talking about this a bit with @Stebalien and we were wondering how would you feel about switching the provider records internals (e.g. ProviderManager) to work on []byte instead of on Multihashes or CIDs? We could then have the server check if the key is less than 80 bytes (640 bits) for DoS purposes, but otherwise not care about the content type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to use []byte instead of Multihashes and to limit the []byte size to 80 bytes. Can revert back if we want.

@aschmahmann aschmahmann marked this pull request as ready for review December 12, 2019 23:17
@aschmahmann
Copy link
Contributor Author

Before we do a release with these changes I'd like to run a Testground test that uses both new and old versions to test compatibility (without using go mod major versions >1 it's very difficult to test this with unit tests)

handlers.go Show resolved Hide resolved
@vyzo
Copy link
Contributor

vyzo commented Dec 13, 2019

Shouldn't we just make it arbitrary strings instead of multihashes though?

@Stebalien
Copy link
Member

Shouldn't we just make it arbitrary strings instead of multihashes though?

#422 (comment)

The remaining part is to change the local DHT (go) API but that issue is less pressing than changing the network.

@aschmahmann
Copy link
Contributor Author

aschmahmann commented Dec 13, 2019

@vyzo we actually do allow arbitrary strings instead of multihashes internally right now (as long as they're less than 80 bytes). However, in order to access that functionality we'd need to fix the external APIs. So one at a time 😄

@aschmahmann
Copy link
Contributor Author

It looks like our logging for the DHT assumes keys are of the form /namespace/CID (whether for DHT Puts/Gets or Provides/FindPeers).

c, err := cid.Cast([]byte(cstr))

func TestLoggableKey(t *testing.T) {
c, err := cid.Decode("QmfUvYQhL2GinafMbPDYz7VFoZv4iiuLuR33aRsPurXGag")

Do we want to impose any key restrictions at all for what we log? What about assuming the for is /namespace/X where X is a CID, Multihash or an arbitrary string/byte array? This would allow us to print in all cases, but not have to deal with non-base encoded CID/Multihashes.

@Stebalien
Copy link
Member

I've gotten a signoff from @raulk and the IPFS team so we should be good to go.

@aschmahmann WRT logging, we just need some reasonable key. We should just do the best we can but otherwise just base encode it.

@Stebalien
Copy link
Member

(or we can just base32 encode the entire key literally and call it a day)

@Stebalien
Copy link
Member

(lgtm modulo logging and merge conflict)

Stebalien added a commit to ipfs/kubo that referenced this pull request Dec 17, 2019
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
Comment on lines +63 to +65
return logging.LoggableMap{
"multihash": base32.RawStdEncoding.EncodeToString(mh),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is uppercase, but when we encode CIDs using b32 we use lowercase. Should I lowercase this?

lookup.go Show resolved Hide resolved
lookup.go Show resolved Hide resolved
@aschmahmann
Copy link
Contributor Author

aschmahmann commented Dec 19, 2019

Did some manual testing to confirm CIDv0 provider record compatibility (and CIDv1 record incompatibility) with current master. Would be nice to make this automated before a go-ipfs release, but this seems fine for now.

@Stebalien LMK if there's anything else blocking the merge (just noticed that dependencies were updated, will rebase on master and try again)

go.sum Show resolved Hide resolved
go.sum Show resolved Hide resolved
pontiyaraja pushed a commit to pontiyaraja/go-ipfs that referenced this pull request Dec 27, 2019
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
@Stebalien Stebalien merged commit 95964c0 into master Jan 2, 2020
@Stebalien Stebalien deleted the feat/advertise-multihash branch January 2, 2020 23:06
@lidel
Copy link
Member

lidel commented Jan 6, 2020

ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 6, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 6, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 8, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 8, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 8, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
ralendor pushed a commit to ralendor/go-ipfs that referenced this pull request Jun 8, 2020
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
hannahhoward pushed a commit to filecoin-project/kubo-api-client that referenced this pull request Jun 19, 2023
* Fixes a panic on close/write race in the websocket transport (libp2p/go-libp2p-kad-dht#422)
* Fixes recursive resolution of dnsaddrs (for bootstrapping).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants