blob: ef015cebb2cbe4524b38dea964c5209aab28a47f (
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
|
package bt
import (
"github.com/felix/dhtsearch/models"
"github.com/felix/logger"
)
type Option func(*Worker) error
// SetOnNewTorrent sets the callback
func SetOnNewTorrent(f func(models.Torrent)) Option {
return func(w *Worker) error {
w.OnNewTorrent = f
return nil
}
}
// SetOnBadPeer sets the callback
func SetOnBadPeer(f func(models.Peer)) Option {
return func(w *Worker) error {
w.OnBadPeer = f
return nil
}
}
// SetPort sets the port to listen on
func SetPort(p int) Option {
return func(w *Worker) error {
w.port = p
return nil
}
}
// SetIPv6 enables IPv6
func SetIPv6(b bool) Option {
return func(w *Worker) error {
if b {
w.family = "tcp6"
}
return nil
}
}
// SetLogger sets the logger
func SetLogger(l logger.Logger) Option {
return func(w *Worker) error {
w.log = l
return nil
}
}
|