2019-06-29 09:19:06 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
mh "github.com/multiformats/go-multihash"
|
|
|
|
)
|
|
|
|
|
2019-07-02 13:05:43 +00:00
|
|
|
// RandomPeerID generates random peer id
|
2019-06-29 09:19:06 +00:00
|
|
|
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
|
2019-07-01 20:00:22 +00:00
|
|
|
}
|