blob: b7ded8a24930244a9aa8fff13c6ff986056f79d5 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package dht
import (
"github.com/felix/logger"
)
type Option func(*Node) error
func SetOnAnnouncePeer(f func(Peer)) Option {
return func(n *Node) error {
n.OnAnnouncePeer = f
return nil
}
}
// SetAddress sets the IP address to listen on
func SetAddress(ip string) Option {
return func(n *Node) error {
n.address = ip
return nil
}
}
// SetPort sets the port to listen on
func SetPort(p int) Option {
return func(n *Node) error {
n.port = p
return nil
}
}
// SetIPv6 enables IPv6
func SetIPv6(b bool) Option {
return func(n *Node) error {
if b {
n.family = "udp6"
}
return nil
}
}
// SetUDPTimeout sets the number of seconds to wait for UDP connections
func SetUDPTimeout(s int) Option {
return func(n *Node) error {
n.udpTimeout = s
return nil
}
}
// SetLogger sets the logger
func SetLogger(l logger.Logger) Option {
return func(n *Node) error {
n.log = l
return nil
}
}
|