forked from filecoin-project/go-legs
/
option.go
51 lines (44 loc) · 1.18 KB
/
option.go
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
package announce
import (
pubsub "github.com/libp2p/go-libp2p-pubsub"
)
type Option func(*config) error
// config contains all options for configuring Subscriber.
type config struct {
allowPeer AllowPeerFunc
filterIPs bool
resend bool
topic *pubsub.Topic
}
// WithAllowPeer sets the function that determines whether to allow or reject
// messages from a peer.
func WithAllowPeer(allowPeer AllowPeerFunc) Option {
return func(c *config) error {
c.allowPeer = allowPeer
return nil
}
}
// WithFilterIPs sets whether or not IP filtering is enabled. When enabled it
// removes any private, loopback, or unspecified IP multiaddrs from addresses
// supplied in announce messages.
func WithFilterIPs(enable bool) Option {
return func(c *config) error {
c.filterIPs = enable
return nil
}
}
// WithResend determines whether to resend direct announce mesages (those that
// are not received via pubsub) over pubsub.
func WithResend(enable bool) Option {
return func(c *config) error {
c.resend = enable
return nil
}
}
// WithTopic provides an existing pubsub topic.
func WithTopic(topic *pubsub.Topic) Option {
return func(c *config) error {
c.topic = topic
return nil
}
}