-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
peering.go
80 lines (68 loc) · 2.18 KB
/
peering.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
package structs
// PeeringToken identifies a peer in order for a connection to be established.
type PeeringToken struct {
CA []string
ManualServerAddresses []string
ServerAddresses []string
ServerName string
PeerID string
EstablishmentSecret string
Remote PeeringTokenRemote
}
type PeeringTokenRemote struct {
Partition string
Datacenter string
}
type IndexedExportedServiceList struct {
Services map[string]ServiceList
QueryMeta
}
// NOTE: this is not serialized via msgpack so it can be changed without concern.
type ExportedServiceList struct {
// Services is a list of exported services that apply to both standard
// service discovery and service mesh.
Services []ServiceName
// DiscoChains is a map of service names to their exported discovery chains
// for service mesh purposes as defined in the exported-services
// configuration entry.
DiscoChains map[ServiceName]ExportedDiscoveryChainInfo
}
// NOTE: this is not serialized via msgpack so it can be changed without concern.
type ExportedDiscoveryChainInfo struct {
// Protocol is the overall protocol associated with this discovery chain.
Protocol string
// TCPTargets is the list of discovery chain targets that are reachable by
// this discovery chain.
//
// NOTE: this is only populated if Protocol=tcp.
TCPTargets []*DiscoveryTarget
}
func (i ExportedDiscoveryChainInfo) Equal(o ExportedDiscoveryChainInfo) bool {
switch {
case i.Protocol != o.Protocol:
return false
case len(i.TCPTargets) != len(o.TCPTargets):
return false
}
for j := 0; j < len(i.TCPTargets); j++ {
if i.TCPTargets[j].ID != o.TCPTargets[j].ID {
return false
}
}
return true
}
// ListAllDiscoveryChains returns all discovery chains (union of Services and
// DiscoChains).
func (list *ExportedServiceList) ListAllDiscoveryChains() map[ServiceName]ExportedDiscoveryChainInfo {
chainsByName := make(map[ServiceName]ExportedDiscoveryChainInfo)
if list == nil {
return chainsByName
}
for _, svc := range list.Services {
chainsByName[svc] = list.DiscoChains[svc]
}
for chainName, info := range list.DiscoChains {
chainsByName[chainName] = info
}
return chainsByName
}