Skip to content

Commit

Permalink
Revert "feat: human-readable cache keys for IPFS_NS_MAP (#38)"
Browse files Browse the repository at this point in the history
This code is buggy because it incorrectly mixes the formating of code in the cache, saving same keys sometime as formated strings sometime as binary data.

This reverts commit fdfe12c.
  • Loading branch information
Jorropo committed Mar 28, 2023
1 parent 0f196b8 commit 1226276
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
31 changes: 7 additions & 24 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 0 additions & 26 deletions namesys/namesys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1226276

Please sign in to comment.