Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swarm, api, main: RNS resolution #1939

Merged
merged 60 commits into from
Dec 2, 2019
Merged

swarm, api, main: RNS resolution #1939

merged 60 commits into from
Dec 2, 2019

Conversation

mortelli
Copy link
Contributor

@mortelli mortelli commented Nov 8, 2019

This PR adds the functionality to resolve .rsk addresses as content hashes for Swarm.

How it works

It works in a similar manner to ENS resolution—in fact, it uses a similar service called RIF Name Service (or RNS for short).

  • this implementation does not uses geth, but rather a go library which is included in the vendor folder.
    • the library in question is github.com/rnsdomains/rns-go-lib.
  • a rns-api flag is added, with a format of [contract-addr@]url in order to activate RNS resolution.
    • contract-addr is the address of the RNS resolver contract to use.
    • url is the network endpoint.
  • the test includes the marcelosdomain.rsk URI while we secure test.rsk (tagging @vojtechsimetka for this one)

Vendoring

There seems to be quite a few changes to vendor. While all the tests pass, @santicomp2014 and I are a bit suspicious of the changes to go.mod.

For the record, our steps were:

  • start from the same go.mod, go.sum and vendor files and folders as found in master.
  • go get github.com/rnsdomains/rns-go-lib
  • make vendor

In particular, we aren't sure why some lines from go.mod are being deleted.

tagging @janos for this one to see if it's possible to verify these steps were correct.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my comments.

@zelig
Copy link
Member

zelig commented Nov 27, 2019

I am ready to approve this if it is updated.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

LGTM. Maybe @skylenet can check also vendoring dependencies changes?

Copy link
Contributor

@Eknir Eknir left a comment

Choose a reason for hiding this comment

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

Good work, I left some comments.

api/api.go Outdated
@@ -185,15 +191,17 @@ type API struct {
feed *feed.Handler
fileStore *storage.FileStore
dns Resolver
rns Resolver
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be great to leave a comment there, explaining what rns is/does. Even better if you can also create those comments for all other fields, but that is not necessary for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a note on the resolvers.
The rest could be added in another PR.

api/api.go Outdated
@@ -225,6 +233,20 @@ func (a *API) Store(ctx context.Context, data io.Reader, size int64, toEncrypt b
// Resolve a name into a content-addressed hash
// where address could be an ENS name, or a content addressed hash
Copy link
Contributor

Choose a reason for hiding this comment

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

Update comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed

@@ -244,6 +266,14 @@ func (a *API) Resolve(ctx context.Context, address string) (storage.Address, err
return resolved[:], nil
}

func tld(address string) (tld string) {
splitAddress := strings.Split(address, ".")
Copy link
Contributor

Choose a reason for hiding this comment

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

What if an address has multiple dots?

Copy link
Contributor

Choose a reason for hiding this comment

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

This only retrieves the last portion of the address.
For example mydomain.subdomain.rsk
will return rsk as the TLD which is the expected functionality in order to resolve the name correctly.

func newRSKTestResolveValidator(addr string) *testResolveValidator {
r := &testResolveValidator{}
if addr == "swarm.rsk" {
hash := common.HexToHash("88ced8ba8e9396672840b47e332b33d6679d9962d80cf340d3cf615db23d4e07")
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this hash come from?

Copy link
Contributor

Choose a reason for hiding this comment

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

This content hash is a hash of a test image, we used it in a test domain, but the actual resolver is mocked right now, this avoids coupling between the rns resolution in Swarm and the actual resolver.
The resolver has its own test in the library that tests the concrete implementation.

// TestRNSResolve tests resolving content from RNS addresses
func TestRNSResolve(t *testing.T) {
rnsAddr := "swarm.rsk"
resolvedContent := "88ced8ba8e9396672840b47e332b33d6679d9962d80cf340d3cf615db23d4e07"
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem. Where does this hash come from?

Copy link
Contributor

Choose a reason for hiding this comment

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

Idem as above


// Resolve returns a resolver function
func (f ResolverFunc) Resolve(domain string) (common.Hash, error) { return f(domain) }

// Resolver interface resolve a domain name to a hash using ENS
Copy link
Contributor

Choose a reason for hiding this comment

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

Update comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed

@@ -75,6 +77,7 @@ type Swarm struct {
config *api.Config // swarm configuration
api *api.API // high level api layer (fs/manifest)
dns api.Resolver // DNS registrar
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between ens and dns?

Copy link
Contributor

Choose a reason for hiding this comment

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

dns is the wrapper, for resolving multiple tld resolvers, it applies for ens but could be used for other resolvers.
on the contrary rns only resolver rsk domains with one tld.
this could be addressed in this issue #1991

swarm.go Outdated
// parseRnsAPIAddress parses string according to format
// [contract-addr@]url and returns RNSClientConfig structure
// with endpoint and contract address
func parseRnsAPIAddress(s string) (endpoint string, addr common.Address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see, this function is exactly the same as parseEnsAPIAddress. I think it would be better to refactor those to avoid code multiplication

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree there is code duplication.
Fixed refactored for parseResolverAPIAddress

@skylenet
Copy link
Contributor

LGTM. Maybe @skylenet can check also vendoring dependencies changes?

I just tried to do a make vendor on the current master and it also seems to be deleting some vendored files. Seems like we got rid of some dependencies on previous PRs and forgot to run the vendor command there.

@skylenet skylenet self-requested a review November 28, 2019 08:11
Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

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

I would like to block this PR to be merged to master before we address some issues that we discovered in 0.5.3 by making a bugfix release. I will unblock as soon as we are done with the release, hopefully tomorrow. Thanks for understanding.

@acud acud added this to the 0.5.5 milestone Nov 29, 2019
@acud acud removed the do-not-merge label Nov 29, 2019
@mortelli mortelli merged commit fd3b095 into master Dec 2, 2019
@mortelli mortelli deleted the rns-resolution branch December 2, 2019 13:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants