libp2p / go-libp2p-kad-dht

A Kademlia DHT implementation on go-libp2p
https://github.com/libp2p/specs/tree/master/kad-dht
MIT License
517 stars 221 forks source link

How to use dht.PutValue? #830

Closed cpeliciari closed 1 year ago

cpeliciari commented 1 year ago

I'm trying to create a p2p network without having to use the ipfs network, when doing a put I am not getting it, here is a snippet of the code.

    host, err := libp2p.New(
        libp2p.ListenAddrs(sourceMultiAddr),
        libp2p.Identity(prvKey),
        libp2p.EnableRelay(),
    )
    if err != nil {
        log.Fatalf("Error creating host: %v", err)
    }

    dhtOptions := []dht.Option{
        dht.Mode(dht.ModeServer),
        dht.ProtocolPrefix("/test"),
    }

    dht, err := dht.New(ctx, host, dhtOptions...)
    if err != nil {
        log.Fatalf("Error creating DHT: %v", err)
    }

    value := []byte("Hello World")

    hash, _ := multihash.Sum(value, multihash.SHA2_256, -1)

    cid := cid2.NewCidV1(cid2.Raw, hash)

    err = dht.PutValue(ctx, "/ipns/"+cid.String(), value)
    if err != nil {
        log.Infof("Error putting value in DHT: %v", err)
    }
guillaumemichel commented 1 year ago

without having to use the ipfs network

  1. Can you please give more details?
  2. What error are you getting?
  3. What are you trying to achieve exactly?
cpeliciari commented 1 year ago

without having to use the ipfs network

  1. Can you please give more details?
  2. What error are you getting?
  3. What are you trying to achieve exactly?
  1. I am setting up a cluster where the DHT.MODESERVER will be, the cluster will send the files to DHT, and the clients will operate the DHT.modeclient, when a customer makes a Get on the network for some file I want to get it a put To inform you that you also have that file.
  2. record could not be unmarshalled
  3. Set up a P2P network without using the IPFS network to store
guillaumemichel commented 1 year ago

Please use the forum to ask this question.