Commit 1c1e389d authored by Jeromy's avatar Jeromy
Browse files

add command to manipulate address filters and a sharness test for them



License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent c5cdd981
...@@ -9,11 +9,17 @@ import ( ...@@ -9,11 +9,17 @@ import (
) )
type Filters struct { type Filters struct {
filters []*net.IPNet filters map[string]*net.IPNet
}
func NewFilters() *Filters {
return &Filters{
filters: make(map[string]*net.IPNet),
}
} }
func (fs *Filters) AddDialFilter(f *net.IPNet) { func (fs *Filters) AddDialFilter(f *net.IPNet) {
fs.filters = append(fs.filters, f) fs.filters[f.String()] = f
} }
func (f *Filters) AddrBlocked(a ma.Multiaddr) bool { func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
...@@ -32,3 +38,15 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool { ...@@ -32,3 +38,15 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
} }
return false return false
} }
func (f *Filters) Filters() []*net.IPNet {
var out []*net.IPNet
for _, ff := range f.filters {
out = append(out, ff)
}
return out
}
func (f *Filters) Remove(ff *net.IPNet) {
delete(f.filters, ff.String())
}
...@@ -84,7 +84,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, ...@@ -84,7 +84,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
dialT: DialTimeout, dialT: DialTimeout,
notifs: make(map[inet.Notifiee]ps.Notifiee), notifs: make(map[inet.Notifiee]ps.Notifiee),
bwc: bwc, bwc: bwc,
Filters: new(filter.Filters), Filters: filter.NewFilters(),
} }
// configure Swarm // configure Swarm
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment