Ive been trying to use dht.PutValue but im struggling with the key… what is it exactly ? how do i generate it ?
I tried multihash.EncodeName([]byte(str), "hashing function") with sha2-256, sha2-512 … but i get the invalid record keytype error when i pass it to dht.PutValue…
When i search in the documentation, i find it evaluating this function record.SplitKey(mHash.B58string())
// SplitKey takes a key in the form
/$namespace/$pathand splits it into
//$namespaceand$path.
I dont know how to generate something with that form nor what namespace.
My code:
Creating the DHT
var dht *kaddht.IpfsDHT
newDHT := func(h host.Host) (routing.PeerRouting, error) {
var err error
ds, err := levelds.NewDatastore(“”, nil)
dht = kaddht.NewDHT(ctx, h, ds)
return dht, err
}
routing := libp2p.Routing(newDHT)
Creating the host
host, err := libp2p.New(ctx, transports ,listenAddrs ,muxers ,security , routing, )
Hashing the data
mBHash, err1 := mh.EncodeName(byte(str), “sha2-256”)
mHash, err2 := mh.Cast(mBHash)
Putting the data
dht.Validator(mHash.B58String(), byte(str))
Then i get
invalid record keytype