Newer
Older
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
52
53
54
55
56
57
58
59
60
61
62
63
64
package filter
import (
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
)
type Filter struct {
routingtable.ClientManager
terms []*Term
}
func NewFilter(terms []*Term) *Filter {
f := &Filter{
terms: terms,
}
f.ClientManager = routingtable.NewClientManager(f)
return f
}
func (f *Filter) AddPath(p net.Prefix, pa *route.Path) error {
pa, rejected := f.processTerms(p, pa)
if rejected {
return nil
}
for _, c := range f.Clients() {
c.AddPath(p, pa)
}
return nil
}
func (f *Filter) RemovePath(p net.Prefix, pa *route.Path) bool {
pa, rejected := f.processTerms(p, pa)
if rejected {
return false
}
for _, c := range f.Clients() {
c.RemovePath(p, pa)
}
return true
}
func (f *Filter) UpdateNewClient(c routingtable.RouteTableClient) error {
return nil
}
func (f *Filter) processTerms(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
modPath = pa
for _, t := range f.terms {
modPath, reject = t.Process(p, modPath)
if reject {
return modPath, true
}
}
return modPath, false
}