@@ -8,18 +8,18 @@ import (
8
8
"io"
9
9
"net/http"
10
10
"strings"
11
+ "time"
11
12
12
13
"github.com/ipfs/boxo/blockservice"
13
14
blockstore "github.com/ipfs/boxo/blockstore"
14
- nsopts "github.com/ipfs/boxo/coreiface/options/namesys"
15
15
"github.com/ipfs/boxo/fetcher"
16
16
bsfetcher "github.com/ipfs/boxo/fetcher/impl/blockservice"
17
17
"github.com/ipfs/boxo/files"
18
18
"github.com/ipfs/boxo/ipld/merkledag"
19
19
ufile "github.com/ipfs/boxo/ipld/unixfs/file"
20
20
uio "github.com/ipfs/boxo/ipld/unixfs/io"
21
+ "github.com/ipfs/boxo/ipns"
21
22
"github.com/ipfs/boxo/namesys"
22
- "github.com/ipfs/boxo/namesys/resolve"
23
23
"github.com/ipfs/boxo/path"
24
24
"github.com/ipfs/boxo/path/resolver"
25
25
blocks "github.com/ipfs/go-block-format"
@@ -39,7 +39,6 @@ import (
39
39
"github.com/ipld/go-ipld-prime/traversal/selector"
40
40
selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse"
41
41
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
42
- "github.com/libp2p/go-libp2p/core/peer"
43
42
"github.com/libp2p/go-libp2p/core/routing"
44
43
mc "github.com/multiformats/go-multicodec"
45
44
@@ -615,18 +614,23 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
615
614
return pathRoots , lastPath , remainder , nil
616
615
}
617
616
618
- func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
617
+ func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , time. Duration , time. Time , error ) {
619
618
switch p .Namespace () {
620
619
case path .IPNSNamespace :
621
- p , err := resolve . ResolveIPNS (ctx , bb .namesys , p )
620
+ res , err := namesys . Resolve (ctx , bb .namesys , p )
622
621
if err != nil {
623
- return path.ImmutablePath {}, err
622
+ return path.ImmutablePath {}, 0 , time. Time {}, err
624
623
}
625
- return path .NewImmutablePath (p )
624
+ ip , err := path .NewImmutablePath (res .Path )
625
+ if err != nil {
626
+ return path.ImmutablePath {}, 0 , time.Time {}, err
627
+ }
628
+ return ip , res .TTL , res .LastMod , nil
626
629
case path .IPFSNamespace :
627
- return path .NewImmutablePath (p )
630
+ ip , err := path .NewImmutablePath (p )
631
+ return ip , 0 , time.Time {}, err
628
632
default :
629
- return path.ImmutablePath {}, NewErrorStatusCode (fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ()), http .StatusNotImplemented )
633
+ return path.ImmutablePath {}, 0 , time. Time {}, NewErrorStatusCode (fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ()), http .StatusNotImplemented )
630
634
}
631
635
}
632
636
@@ -635,28 +639,25 @@ func (bb *BlocksBackend) GetIPNSRecord(ctx context.Context, c cid.Cid) ([]byte,
635
639
return nil , NewErrorStatusCode (errors .New ("IPNS Record responses are not supported by this gateway" ), http .StatusNotImplemented )
636
640
}
637
641
638
- // Fails fast if the CID is not an encoded Libp2p Key, avoids wasteful
639
- // round trips to the remote routing provider.
640
- if mc .Code (c .Type ()) != mc .Libp2pKey {
641
- return nil , NewErrorStatusCode (errors .New ("cid codec must be libp2p-key" ), http .StatusBadRequest )
642
- }
643
-
644
- // The value store expects the key itself to be encoded as a multihash.
645
- id , err := peer .FromCid (c )
642
+ name , err := ipns .NameFromCid (c )
646
643
if err != nil {
647
- return nil , err
644
+ return nil , NewErrorStatusCode ( err , http . StatusBadRequest )
648
645
}
649
646
650
- return bb .routing .GetValue (ctx , "/ipns/" + string (id ))
647
+ return bb .routing .GetValue (ctx , string (name . RoutingKey () ))
651
648
}
652
649
653
650
func (bb * BlocksBackend ) GetDNSLinkRecord (ctx context.Context , hostname string ) (path.Path , error ) {
654
651
if bb .namesys != nil {
655
- p , err := bb .namesys .Resolve (ctx , "/ipns/" + hostname , nsopts .Depth (1 ))
652
+ p , err := path .NewPath ("/ipns/" + hostname )
653
+ if err != nil {
654
+ return nil , err
655
+ }
656
+ res , err := bb .namesys .Resolve (ctx , p , namesys .ResolveWithDepth (1 ))
656
657
if err == namesys .ErrResolveRecursion {
657
658
err = nil
658
659
}
659
- return p , err
660
+ return res . Path , err
660
661
}
661
662
662
663
return nil , NewErrorStatusCode (errors .New ("not implemented" ), http .StatusNotImplemented )
@@ -688,10 +689,11 @@ func (bb *BlocksBackend) ResolvePath(ctx context.Context, path path.ImmutablePat
688
689
func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , []string , error ) {
689
690
var err error
690
691
if p .Namespace () == path .IPNSNamespace {
691
- p , err = resolve . ResolveIPNS (ctx , bb .namesys , p )
692
+ res , err := namesys . Resolve (ctx , bb .namesys , p )
692
693
if err != nil {
693
694
return path.ImmutablePath {}, nil , err
694
695
}
696
+ p = res .Path
695
697
}
696
698
697
699
if p .Namespace () != path .IPFSNamespace {
0 commit comments