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

add support for IPLD over IPNS #5602

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions namesys/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ func resolve(ctx context.Context, r resolver, name string, options *opts.Resolve
}
log.Debugf("resolved %s to %s", name, p.String())

if strings.HasPrefix(p.String(), "/ipfs/") {
Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed this check to "is not /ipns/". That way, we continue resolving until we can no longer resolve.

// we've bottomed out with an IPFS path
return p, nil
}

if depth == 1 {
return p, ErrResolveRecursion
}

matched := false
for _, prefix := range prefixes {
if strings.HasPrefix(p.String(), prefix) {
Expand All @@ -45,10 +36,17 @@ func resolve(ctx context.Context, r resolver, name string, options *opts.Resolve
}
}

// Not something we can resolve, return it.
if !matched {
return p, nil
}

// No more depth left, return it.
if depth == 1 {
return p, ErrResolveRecursion
}

// Depth could be 0.
if depth > 1 {
depth--
}
Expand Down
8 changes: 4 additions & 4 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ const DefaultResolverCacheTTL = time.Minute

// Resolve implements Resolver.
func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
if strings.HasPrefix(name, "/ipfs/") {
return path.ParsePath(name)
if strings.HasPrefix(name, "/ipns/") {
return resolve(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
}

if !strings.HasPrefix(name, "/") {
return path.ParsePath("/ipfs/" + name)
}
// TODO: Forbid this case.
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't do this now but I'd rather require complete paths (forbidding a raw "Qm..."). However, that'll be a harder change.

return path.ParsePath("/ipfs/" + name)

return resolve(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
}

// resolveOnce implements resolver.
Expand Down
26 changes: 26 additions & 0 deletions test/sharness/t0100-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ test_expect_success "publish an explicit node ID as key name looks good" '
test_cmp expected_node_id_publish actual_node_id_publish
'

# test IPNS + IPLD

test_expect_success "'ipfs dag put' succeeds" '
HELLO_HASH="$(echo "\"hello world\"" | ipfs dag put)" &&
OBJECT_HASH="$(echo "{\"thing\": {\"/\": \"${HELLO_HASH}\" }}" | ipfs dag put)"
'

test_expect_success "'ipfs name publish --allow-offline /ipld/...' succeeds" '
PEERID=`ipfs id --format="<id>"` &&
test_check_peerid "${PEERID}" &&
ipfs name publish --allow-offline "/ipld/$OBJECT_HASH/thing" >publish_out
'

test_expect_success "publish a path looks good" '
echo "Published to ${PEERID}: /ipld/$OBJECT_HASH/thing" >expected3 &&
test_cmp expected3 publish_out
'

test_expect_success "'ipfs name resolve' succeeds" '
ipfs name resolve "$PEERID" >output
'

test_expect_success "resolve output looks good" '
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
test_cmp expected4 output
'

# test publishing nothing

Expand Down