diff --git a/namesys/namesys.go b/namesys/namesys.go index e341b63d7..d031064e6 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -20,7 +20,6 @@ import ( "time" lru "github.com/hashicorp/golang-lru" - iface "github.com/ipfs/boxo/coreiface" opts "github.com/ipfs/boxo/coreiface/options/namesys" "github.com/ipfs/boxo/path" "github.com/ipfs/go-cid" @@ -88,23 +87,6 @@ func WithDatastore(ds ds.Datastore) Option { } } -func loadStaticMap(list string) (map[string]path.Path, error) { - staticMap := make(map[string]path.Path) - for _, pair := range strings.Split(list, ",") { - mapping := strings.SplitN(pair, ":", 2) - key := mapping[0] - value := path.FromString(mapping[1]) - - ipnsKey, err := peer.Decode(key) - if err == nil { - key = iface.FormatKeyID(ipnsKey) - } - - staticMap[key] = value - } - return staticMap, nil -} - // NewNameSystem will construct the IPFS naming system based on Routing func NewNameSystem(r routing.ValueStore, opts ...Option) (NameSystem, error) { var staticMap map[string]path.Path @@ -114,11 +96,12 @@ func NewNameSystem(r routing.ValueStore, opts ...Option) (NameSystem, error) { // Example: // IPFS_NS_MAP="dnslink-test.example.com:/ipfs/bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am" if list := os.Getenv("IPFS_NS_MAP"); list != "" { - var err error - staticMap, err = loadStaticMap(list) - - if err != nil { - return nil, err + staticMap = make(map[string]path.Path) + for _, pair := range strings.Split(list, ",") { + mapping := strings.SplitN(pair, ":", 2) + key := mapping[0] + value := path.FromString(mapping[1]) + staticMap[key] = value } } @@ -232,7 +215,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. cacheKey := key if err == nil { - cacheKey = iface.FormatKeyID(ipnsKey) + cacheKey = string(ipnsKey) } if p, ok := ns.cacheGet(cacheKey); ok { diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index a3f9df01a..52fce6794 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -88,32 +88,6 @@ func TestNamesysResolution(t *testing.T) { testResolution(t, r, "/ipns/bafzbeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", 1, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion) } -func TestNamesysResolutionWithCache(t *testing.T) { - nsMap := "dnslink-test.example.com:/ipfs/bafyaaeykceeaeeqlgiydemzngazc2mrtbimaw,12D3KooWQbpsnyzdBcxw6GUMbijV8WgXE4L8EtfnbcQWLfyxBKho:/ipfs/bafyaagakcyeaeeqqgiydemzngazc2mrtfvuxa3ttbimba,k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s:/ipfs/bafyaahikdmeaeeqvgiydemzngazc2mrtfvuxa3ttfvsgk5lybimbk" - - staticMap, err := loadStaticMap(nsMap) - if err != nil { - t.Fatal(err) - } - - r := &mpns{ - ipnsResolver: mockResolverOne(), - dnsResolver: mockResolverTwo(), - staticMap: staticMap, - } - - testResolution(t, r, "/ipns/dnslink-test.example.com", opts.DefaultDepthLimit, "/ipfs/bafyaaeykceeaeeqlgiydemzngazc2mrtbimaw", nil) - - testResolution(t, r, "/ipns/bafzaajaiaejcbw5i6oyqsktsn36r2vxgl2jzosyao46rybqztxt4rx4tfa3hpogg", opts.DefaultDepthLimit, "/ipfs/bafyaagakcyeaeeqqgiydemzngazc2mrtfvuxa3ttbimba", nil) - testResolution(t, r, "/ipns/k51qzi5uqu5dlnojhwrggtpty9c0cp5hvnkdozowth4eqb726jvoros8k9niyu", opts.DefaultDepthLimit, "/ipfs/bafyaagakcyeaeeqqgiydemzngazc2mrtfvuxa3ttbimba", nil) - testResolution(t, r, "/ipns/12D3KooWQbpsnyzdBcxw6GUMbijV8WgXE4L8EtfnbcQWLfyxBKho", opts.DefaultDepthLimit, "/ipfs/bafyaagakcyeaeeqqgiydemzngazc2mrtfvuxa3ttbimba", nil) - - testResolution(t, r, "/ipns/bafzaajaiaejcbpltl72da5f3y7ojrtsa7hsfn5bbnkjbkwyesziqqtdry6vjilku", opts.DefaultDepthLimit, "/ipfs/bafyaahikdmeaeeqvgiydemzngazc2mrtfvuxa3ttfvsgk5lybimbk", nil) - testResolution(t, r, "/ipns/k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s", opts.DefaultDepthLimit, "/ipfs/bafyaahikdmeaeeqvgiydemzngazc2mrtfvuxa3ttfvsgk5lybimbk", nil) - testResolution(t, r, "/ipns/12D3KooWNZuG8phqhoNK9KWcUhwfzA3biDKNCUNVWEaJgigr6Acj", opts.DefaultDepthLimit, "/ipfs/bafyaahikdmeaeeqvgiydemzngazc2mrtfvuxa3ttfvsgk5lybimbk", nil) - -} - func TestPublishWithCache0(t *testing.T) { dst := dssync.MutexWrap(ds.NewMapDatastore()) priv, _, err := ci.GenerateKeyPair(ci.RSA, 2048)