Skip to content

Commit

Permalink
Add Filters option (#717)
Browse files Browse the repository at this point in the history
The new `Filters` option allows users to take ownership of the `Filters` struct, and is suitable for cases where the addresses you want to accept/deny change dynamically.
  • Loading branch information
albrow authored and raulk committed Sep 5, 2019
1 parent 51950e4 commit 1b9b84b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func EnableAutoRelay() Option {
}

// FilterAddresses configures libp2p to never dial nor accept connections from
// the given addresses.
// the given addresses. FilterAddresses should be used for cases where the
// addresses you want to deny are known ahead of time.
func FilterAddresses(addrs ...*net.IPNet) Option {
return func(cfg *Config) error {
if cfg.Filters == nil {
Expand All @@ -259,6 +260,17 @@ func FilterAddresses(addrs ...*net.IPNet) Option {
}
}

// Filters configures libp2p to use the given filters for accepting/denying
// certain addresses. Filters offers more control and should be use when the
// addresses you want to accept/deny are not known ahead of time and can
// dynamically change.
func Filters(filters *filter.Filters) Option {
return func(cfg *Config) error {
cfg.Filters = filters
return nil
}
}

// NATPortMap configures libp2p to use the default NATManager. The default
// NATManager will attempt to open a port in your network's firewall using UPnP.
func NATPortMap() Option {
Expand Down

0 comments on commit 1b9b84b

Please sign in to comment.