Add Filters option
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.
@@ -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 {
@@ -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 {
