Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 319cdba

Browse files
committed
[#1800] Clarify difference between IPFS prefix and OB prefix
1 parent 2e50b24 commit 319cdba

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ipfs/resolve.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
const (
2020
persistentCacheDbPrefix = "/ipns/persistentcache/"
2121
pubkeyCacheDbPrefix = "/pubkey/"
22+
ipnsCacheDbPrefix = "/ipns/"
2223
)
2324

2425
// Resolve an IPNS record. This is a multi-step process.
@@ -74,7 +75,7 @@ func resolve(n *core.IpfsNode, p peer.ID, timeout time.Duration, quorum uint) (i
7475

7576
// TODO [cp]: we should load the record count from our config and set it here. We'll need a
7677
// migration for this.
77-
pth, err := n.Namesys.Resolve(cctx, "/ipns/"+p.Pretty(), nameopts.DhtRecordCount(quorum))
78+
pth, err := n.Namesys.Resolve(cctx, string(obIPNSCacheKey(p.Pretty())), nameopts.DhtRecordCount(quorum))
7879
if err != nil {
7980
return pth, err
8081
}
@@ -85,7 +86,7 @@ func ResolveAltRoot(n *core.IpfsNode, p peer.ID, altRoot string, timeout time.Du
8586
cctx, cancel := context.WithTimeout(context.Background(), timeout)
8687
defer cancel()
8788

88-
pth, err := n.Namesys.Resolve(cctx, "/ipns/"+p.Pretty()+":"+altRoot)
89+
pth, err := n.Namesys.Resolve(cctx, obIPNSCacheKey(p.Pretty()+":"+altRoot))
8990
if err != nil {
9091
return "", err
9192
}
@@ -98,7 +99,7 @@ func ResolveAltRoot(n *core.IpfsNode, p peer.ID, altRoot string, timeout time.Du
9899
// under /ipns/persistentcache/<peerID> which returns only the value (the path)
99100
// inside the protobuf record.
100101
func getFromDatastore(datastore ds.Datastore, p peer.ID) (ipath.Path, error) {
101-
ival, err := datastore.Get(ipnsRecordCacheKey(p))
102+
ival, err := datastore.Get(nativeIPNSRecordCacheKey(p))
102103
if err != nil {
103104
pth, err := datastore.Get(persistentCacheKey(p))
104105
if err != nil {
@@ -142,6 +143,12 @@ func persistentCacheKey(id peer.ID) ds.Key {
142143
return ds.NewKey(persistentCacheDbPrefix + base32.RawStdEncoding.EncodeToString([]byte(id)))
143144
}
144145

145-
func ipnsRecordCacheKey(id peer.ID) ds.Key {
146+
// nativeIPNSRecordCacheKey applies native IPFS key: "/ipns/" + encoded(id)
147+
func nativeIPNSRecordCacheKey(id peer.ID) ds.Key {
146148
return namesys.IpnsDsKey(id)
147149
}
150+
151+
// obIPNSCacheKey applies custom IPNS prefix key: "/ipns/" + id
152+
func obIPNSCacheKey(id string) string {
153+
return ipnsCacheDbPrefix + id
154+
}

0 commit comments

Comments
 (0)