Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the {F=>f}iltersConnectionGater private. #946

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,20 @@ func AutoNATServiceRateLimit(global, perPeer int, interval time.Duration) Option
// Deprecated: Please use ConnectionGater() instead.
func FilterAddresses(addrs ...*net.IPNet) Option {
return func(cfg *Config) error {
var f *FiltersConnectionGater
var f *filtersConnectionGater

// preserve backwards compatibility.
// if we have a connection gater, try to cast it to a *FiltersConnectionGater.
// if we have a connection gater, try to cast it to a *filtersConnectionGater.
if cfg.ConnectionGater != nil {
var ok bool
if f, ok = cfg.ConnectionGater.(*FiltersConnectionGater); !ok {
if f, ok = cfg.ConnectionGater.(*filtersConnectionGater); !ok {
return errors.New("cannot configure both Filters and Connection Gater. " +
"\n Please consider configuring just a ConnectionGater instead.")
}
}

if f == nil {
f = (*FiltersConnectionGater)(ma.NewFilters())
f = (*filtersConnectionGater)(ma.NewFilters())
cfg.ConnectionGater = f
}

Expand Down Expand Up @@ -374,7 +374,7 @@ func Filters(filters *ma.Filters) Option {
"\n Please consider configuring just a ConnectionGater instead.")

}
cfg.ConnectionGater = (*FiltersConnectionGater)(filters)
cfg.ConnectionGater = (*filtersConnectionGater)(filters)
return nil
}
}
Expand Down
19 changes: 9 additions & 10 deletions options_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ import (
ma "github.com/multiformats/go-multiaddr"
)

// FiltersConnectionGater is an adapter that turns multiaddr.Filter into a
// connmgr.ConnectionGater. It's not intended to be used directly by the user,
// but it can.
type FiltersConnectionGater ma.Filters
// filtersConnectionGater is an adapter that turns multiaddr.Filter into a
// connmgr.ConnectionGater.
type filtersConnectionGater ma.Filters

var _ connmgr.ConnectionGater = (*FiltersConnectionGater)(nil)
var _ connmgr.ConnectionGater = (*filtersConnectionGater)(nil)

func (f *FiltersConnectionGater) InterceptAddrDial(_ peer.ID, addr ma.Multiaddr) (allow bool) {
func (f *filtersConnectionGater) InterceptAddrDial(_ peer.ID, addr ma.Multiaddr) (allow bool) {
return !(*ma.Filters)(f).AddrBlocked(addr)
}

func (f *FiltersConnectionGater) InterceptPeerDial(p peer.ID) (allow bool) {
func (f *filtersConnectionGater) InterceptPeerDial(p peer.ID) (allow bool) {
return true
}

func (f *FiltersConnectionGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool) {
func (f *filtersConnectionGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool) {
return true
}

func (f *FiltersConnectionGater) InterceptSecured(_ network.Direction, _ peer.ID, _ network.ConnMultiaddrs) (allow bool) {
func (f *filtersConnectionGater) InterceptSecured(_ network.Direction, _ peer.ID, _ network.ConnMultiaddrs) (allow bool) {
return true
}

func (f *FiltersConnectionGater) InterceptUpgraded(_ network.Conn) (allow bool, reason control.DisconnectReason) {
func (f *filtersConnectionGater) InterceptUpgraded(_ network.Conn) (allow bool, reason control.DisconnectReason) {
return true, 0
}