@@ -7,10 +7,7 @@ import (
77 "net/http"
88 "strings"
99
10- "github.com/gogo/protobuf/proto"
1110 "github.com/ipfs/boxo/ipns"
12- ipns_pb "github.com/ipfs/boxo/ipns/pb"
13- "github.com/libp2p/go-libp2p/core/peer"
1411 "github.com/libp2p/go-libp2p/core/routing"
1512 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1613)
@@ -42,30 +39,28 @@ func (ps *proxyRouting) GetValue(ctx context.Context, k string, opts ...routing.
4239 return nil , routing .ErrNotSupported
4340 }
4441
45- k = strings .TrimPrefix (k , "/ipns/" )
46- id , err := peer .IDFromBytes ([]byte (k ))
42+ name , err := ipns .NameFromRoutingKey ([]byte (k ))
4743 if err != nil {
4844 return nil , err
4945 }
5046
51- return ps .fetch (ctx , id )
47+ return ps .fetch (ctx , name )
5248}
5349
5450func (ps * proxyRouting ) SearchValue (ctx context.Context , k string , opts ... routing.Option ) (<- chan []byte , error ) {
5551 if ! strings .HasPrefix (k , "/ipns/" ) {
5652 return nil , routing .ErrNotSupported
5753 }
5854
59- k = strings .TrimPrefix (k , "/ipns/" )
60- id , err := peer .IDFromBytes ([]byte (k ))
55+ name , err := ipns .NameFromRoutingKey ([]byte (k ))
6156 if err != nil {
6257 return nil , err
6358 }
6459
6560 ch := make (chan []byte )
6661
6762 go func () {
68- v , err := ps .fetch (ctx , id )
63+ v , err := ps .fetch (ctx , name )
6964 if err != nil {
7065 close (ch )
7166 } else {
@@ -77,8 +72,8 @@ func (ps *proxyRouting) SearchValue(ctx context.Context, k string, opts ...routi
7772 return ch , nil
7873}
7974
80- func (ps * proxyRouting ) fetch (ctx context.Context , id peer. ID ) ([]byte , error ) {
81- urlStr := fmt .Sprintf ("%s/ipns/ %s" , ps .gatewayURL , peer . ToCid ( id ) .String ())
75+ func (ps * proxyRouting ) fetch (ctx context.Context , name ipns. Name ) ([]byte , error ) {
76+ urlStr := fmt .Sprintf ("%s/%s" , ps .gatewayURL , name .String ())
8277 req , err := http .NewRequestWithContext (ctx , http .MethodGet , urlStr , nil )
8378 if err != nil {
8479 return nil , err
@@ -104,13 +99,12 @@ func (ps *proxyRouting) fetch(ctx context.Context, id peer.ID) ([]byte, error) {
10499 return nil , err
105100 }
106101
107- var entry ipns_pb.IpnsEntry
108- err = proto .Unmarshal (rb , & entry )
102+ rec , err := ipns .UnmarshalRecord (rb )
109103 if err != nil {
110104 return nil , err
111105 }
112106
113- err = ipns .ValidateWithPeerID ( id , & entry )
107+ err = ipns .ValidateWithName ( rec , name )
114108 if err != nil {
115109 return nil , err
116110 }
0 commit comments