forked from vanadium/go.lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
80 lines (66 loc) · 1.49 KB
/
util_test.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package netstate
import (
"net"
"v.io/x/lib/netconfig/route"
)
type ma struct {
n, a string
}
func (a *ma) Network() string {
return a.n
}
func (a *ma) String() string {
return a.a
}
func MkAddr(n, a string) net.Addr {
ip := net.ParseIP(a)
if ip == nil {
ip, _, _ = net.ParseCIDR(a)
}
return &ma{n: n, a: ip.String()}
}
func NewIPAddr(n, a string) Address {
ip := net.ParseIP(a)
return NewAddr(n, ip.String())
}
func NewAddr(n, a string) Address {
return &address{
addr: &ma{n: n, a: a},
}
}
func NewInterface(name string, index int, addrs []net.Addr, routes []route.IPRoute) NetworkInterface {
return &ipifc{
name: name,
index: index,
addrs: addrs,
ipRoutes: routes,
}
}
func AddRoute(ifc NetworkInterface, rt route.IPRoute) {
ii := ifc.(*ipifc)
ii.ipRoutes = append(ii.ipRoutes, rt)
}
func RemoveLastRoute(ifc NetworkInterface) {
ii := ifc.(*ipifc)
ii.ipRoutes = ii.ipRoutes[:len(ii.ipRoutes)-1]
}
func SetRoutes(ifc NetworkInterface, rt ...route.IPRoute) {
ii := ifc.(*ipifc)
ii.ipRoutes = rt
}
func CreateAndUseMockCache(ifcs []NetworkInterface, routetable RouteTable) func() {
prev := internalCache
internalCache = &netstateCache{
current: true,
interfaces: ifcs,
routes: routetable,
valid: make(chan struct{}),
}
return func() {
internalCache = prev
InvalidateCache()
}
}