Node builder structure

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Łukasz Magiera
2019-07-01 23:11:33 +02:00
committed by Jakub Sztandera
parent 5238872c02
commit 795621ed27
16 changed files with 268 additions and 26 deletions
+1
View File
@@ -0,0 +1 @@
package modules
+1
View File
@@ -0,0 +1 @@
package modules
+22
View File
@@ -0,0 +1,22 @@
package modules
import (
"crypto/rand"
"io"
"io/ioutil"
"github.com/libp2p/go-libp2p-core/peer"
mh "github.com/multiformats/go-multihash"
)
func RandomPeerID() (peer.ID, error) {
b, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32))
if err != nil {
return "", err
}
hash, err := mh.Sum(b, mh.SHA2_256, -1)
if err != nil {
return "", err
}
return peer.ID(hash), nil
}