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
package rtmirror
import (
routeapi "github.com/bio-routing/bio-rd/route/api"
"google.golang.org/grpc"
)
// routeContainer groups a route with one ore multiple source the route was received from
type routeContainer struct {
route *routeapi.Route
sources []*grpc.ClientConn
}
func newRouteContainer(route *routeapi.Route, source *grpc.ClientConn) *routeContainer {
return &routeContainer{
route: route,
sources: []*grpc.ClientConn{source},
}
}
func (rc *routeContainer) addSource(cc *grpc.ClientConn) {
rc.sources = append(rc.sources, cc)
}
func (rc *routeContainer) removeSource(cc *grpc.ClientConn) {
i := rc.getSourceIndex(cc)
if i < 0 {
return
}
rc.sources[i] = rc.sources[len(rc.sources)-1]
rc.sources = rc.sources[:len(rc.sources)-1]
}
func (rc *routeContainer) getSourceIndex(cc *grpc.ClientConn) int {
for i := range rc.sources {
if rc.sources[i] == cc {
return i
}
}
return -1
}
func (rc *routeContainer) srcCount() int {
return len(rc.sources)
}