aboutsummaryrefslogtreecommitdiff
path: root/peer
diff options
context:
space:
mode:
Diffstat (limited to 'peer')
-rw-r--r--peer/id.go13
-rw-r--r--peer/id_test.go7
-rw-r--r--peer/port.go15
-rw-r--r--peer/port_test.go8
4 files changed, 8 insertions, 35 deletions
diff --git a/peer/id.go b/peer/id.go
index dd0ff1d..fa8c6a9 100644
--- a/peer/id.go
+++ b/peer/id.go
@@ -5,11 +5,10 @@ import (
"encoding/hex"
)
-func NewID() (string, error) {
- r := make([]byte, 10)
- _, err := rand.Read(r)
- if err != nil {
- return "", err
- }
- return hex.EncodeToString(r), nil
+func NewID() []byte {
+ src := make([]byte, 10)
+ dst := make([]byte, hex.EncodedLen(len(src)))
+ rand.Read(src)
+ hex.Encode(dst, src)
+ return dst
}
diff --git a/peer/id_test.go b/peer/id_test.go
index da80656..95297e1 100644
--- a/peer/id_test.go
+++ b/peer/id_test.go
@@ -3,12 +3,9 @@ package peer
import "testing"
func TestID(t *testing.T) {
- id, err := NewID()
- if err != nil {
- t.Error(err)
- }
+ id := NewID()
if len(id) != 20 {
t.Error("wrong length")
}
- t.Log(id)
+ t.Log(string(id))
}
diff --git a/peer/port.go b/peer/port.go
deleted file mode 100644
index 7aa1ed4..0000000
--- a/peer/port.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package peer
-
-const (
- minPort = 6881
- maxPort = 6889
-)
-
-func PortRange() []int {
- n := maxPort - minPort + 1
- r := make([]int, n)
- for i := 0; i < n; i++ {
- r[i] = minPort + i
- }
- return r
-}
diff --git a/peer/port_test.go b/peer/port_test.go
deleted file mode 100644
index ed849e2..0000000
--- a/peer/port_test.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package peer
-
-import "testing"
-
-func TestPortRange(t *testing.T) {
- r := PortRange()
- t.Log(r)
-}