Skip to content

Example of using DHT PutValue? #2609

Answered by master255
master255 asked this question in Q&A
Discussion options

You must be logged in to vote

Who's the best? I'm the best :) :

func (m *MobileLibp2p) DHTPutValue(publicKeyBytes []byte, privateKeyBytes []byte, value []byte) bool {
	privateKey, err := crypto.UnmarshalPrivateKey(privateKeyBytes)
	if err != nil {
		return false
	}
	publicKey, err := crypto.UnmarshalPublicKey(publicKeyBytes)
	if err != nil {
		return false
	}
	peerId, err := peer.IDFromPublicKey(publicKey)
	if err != nil {
		return false
	}
	entry, err := ipns.Create(privateKey, value, 1, time.Now().Add(time.Hour*5), 0)
	entry.PubKey = publicKeyBytes
	data, err := proto.Marshal(entry)
	err = m.kademlia.PutValue(m.ctx, ipns.RecordKey(peerId), data)
	if err != nil {
		return false
	} else {
		return true
	}
}

func (m *…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by master255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant