@@ -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
@@ -562,18 +561,23 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
562
561
return pathRoots , lastPath , remainder , nil
563
562
}
564
563
565
- func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
564
+ func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , time. Duration , time. Time , error ) {
566
565
switch p .Namespace () {
567
566
case path .IPNSNamespace :
568
- p , err := resolve . ResolveIPNS (ctx , bb .namesys , p )
567
+ res , err := namesys . Resolve (ctx , bb .namesys , p )
569
568
if err != nil {
570
- return nil , err
569
+ return nil , 0 , time.Time {}, err
570
+ }
571
+ ip , err := path .NewImmutablePath (res .Path )
572
+ if err != nil {
573
+ return nil , 0 , time.Time {}, err
571
574
}
572
- return path . NewImmutablePath ( p )
575
+ return ip , res . TTL , res . LastMod , nil
573
576
case path .IPFSNamespace :
574
- return path .NewImmutablePath (p )
577
+ ip , err := path .NewImmutablePath (p )
578
+ return ip , 0 , time.Time {}, err
575
579
default :
576
- return nil , NewErrorStatusCode (fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ()), http .StatusNotImplemented )
580
+ return nil , 0 , time. Time {}, NewErrorStatusCode (fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ()), http .StatusNotImplemented )
577
581
}
578
582
}
579
583
@@ -582,28 +586,25 @@ func (bb *BlocksBackend) GetIPNSRecord(ctx context.Context, c cid.Cid) ([]byte,
582
586
return nil , NewErrorStatusCode (errors .New ("IPNS Record responses are not supported by this gateway" ), http .StatusNotImplemented )
583
587
}
584
588
585
- // Fails fast if the CID is not an encoded Libp2p Key, avoids wasteful
586
- // round trips to the remote routing provider.
587
- if mc .Code (c .Type ()) != mc .Libp2pKey {
588
- return nil , NewErrorStatusCode (errors .New ("cid codec must be libp2p-key" ), http .StatusBadRequest )
589
- }
590
-
591
- // The value store expects the key itself to be encoded as a multihash.
592
- id , err := peer .FromCid (c )
589
+ name , err := ipns .NameFromCid (c )
593
590
if err != nil {
594
- return nil , err
591
+ return nil , NewErrorStatusCode ( err , http . StatusBadRequest )
595
592
}
596
593
597
- return bb .routing .GetValue (ctx , "/ipns/" + string (id ))
594
+ return bb .routing .GetValue (ctx , string (name . RoutingKey () ))
598
595
}
599
596
600
597
func (bb * BlocksBackend ) GetDNSLinkRecord (ctx context.Context , hostname string ) (path.Path , error ) {
601
598
if bb .namesys != nil {
602
- p , err := bb .namesys .Resolve (ctx , "/ipns/" + hostname , nsopts .Depth (1 ))
599
+ p , err := path .NewPath ("/ipns/" + hostname )
600
+ if err != nil {
601
+ return nil , err
602
+ }
603
+ res , err := bb .namesys .Resolve (ctx , p , namesys .ResolveWithDepth (1 ))
603
604
if err == namesys .ErrResolveRecursion {
604
605
err = nil
605
606
}
606
- return p , err
607
+ return res . Path , err
607
608
}
608
609
609
610
return nil , NewErrorStatusCode (errors .New ("not implemented" ), http .StatusNotImplemented )
@@ -635,10 +636,11 @@ func (bb *BlocksBackend) ResolvePath(ctx context.Context, path path.ImmutablePat
635
636
func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , []string , error ) {
636
637
var err error
637
638
if p .Namespace () == path .IPNSNamespace {
638
- p , err = resolve . ResolveIPNS (ctx , bb .namesys , p )
639
+ res , err := namesys . Resolve (ctx , bb .namesys , p )
639
640
if err != nil {
640
641
return nil , nil , err
641
642
}
643
+ p = res .Path
642
644
}
643
645
644
646
if p .Namespace () != path .IPFSNamespace {
0 commit comments