Datastore Key conversion mixes namespaces prefix
iand opened this issue · comments
(Migrated from libp2p/go-libp2p-kad-dht#869)
When we receive a PUT_VALUE
RPC from a remote peer, the key will contain a namespace prefix (e.g., pk
or ipns
) followed by a binary key. In the case of IPNS the key follows the spec:
Key format:
/ipns/BINARY_ID
This is in line with how the IPNS key gets generated here:
func (n Name) RoutingKey() []byte {
var buffer bytes.Buffer
buffer.WriteString(NamespacePrefix)
buffer.Write(n.src) // Note: we append raw multihash bytes (no multibase)
return buffer.Bytes()
}
NamespacePrefix
is set to /ipns/
. In the handlePutValue
method the key parameter will be set to the above /ipns/BINARY_ID
format. Later in that handler we're generating the datastore key via convertToDsKey(rec.GetKey())
:
func convertToDsKey(s []byte) ds.Key {
return ds.NewKey(base32.RawStdEncoding.EncodeToString(s))
}
This means we're taking the bytes of the string /ipns/BINARY_ID
and encode them as base32. This means we're losing the capability of proper namespacing. The /ipns
prefix will still be the same in base32 for all keys but still this seems like a coincidence. In the ProviderManager
, we're properly encoding each component separately here.
Changing this key format will be incompatible with any persistent stores out there. We'd need to support both types of keys (everything base32 encoded and only BINARY_ID encoded) for some time.
With go-libp2p-kad-dht v2 we could take the liberty to introduce a breaking change here.