aboutsummaryrefslogtreecommitdiff
path: root/peer/id.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-16 02:54:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-16 02:54:33 +0200
commit39decb03c0d3ff44f08cc4a587813e771f2d853b (patch)
treed597a672a439cd52a05efa5994775c56aa606617 /peer/id.go
parent36b8cd0ad32bcd967dc98e1ae91943355a5c388e (diff)
split
Diffstat (limited to 'peer/id.go')
-rw-r--r--peer/id.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/peer/id.go b/peer/id.go
new file mode 100644
index 0000000..197da5a
--- /dev/null
+++ b/peer/id.go
@@ -0,0 +1,16 @@
+package peer
+
+import (
+ "crypto/rand"
+ "fmt"
+ "math/big"
+)
+
+func NewID() (string, error) {
+ limit := new(big.Int).Lsh(big.NewInt(1), 80)
+ id, err := rand.Int(rand.Reader, limit)
+ if err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("%0.20x", id), nil
+}