-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode.go
More file actions
39 lines (34 loc) · 693 Bytes
/
node.go
File metadata and controls
39 lines (34 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package dht
import (
"crypto/rand"
"encoding/binary"
mrand "math/rand"
"net"
"time"
)
func init() {
s := make([]byte, 8)
rand.Read(s)
mrand.Seed(int64(binary.LittleEndian.Uint64(s)))
}
// node represents a node on the network
type node struct {
// the id of the node (default to 160 bits/20 bytes)
id []byte
// the udp address of the node
address *net.UDPAddr
// the last time an event was received from this node
seen time.Time
// the number of expected responses we are waiting on
pending int
}
func randomID() []byte {
id := make([]byte, KEY_BYTES)
rand.Read(id)
return id
}
func pseudorandomID() []byte {
id := make([]byte, KEY_BYTES)
mrand.Read(id)
return id
}