-
Notifications
You must be signed in to change notification settings - Fork 77
/
factories.go
342 lines (284 loc) · 8.52 KB
/
factories.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package mesh
import (
"fmt"
"github.com/ansible/receptor/pkg/netceptor"
"github.com/ansible/receptor/pkg/workceptor"
"github.com/ansible/receptor/tests/utils"
)
func flatMesh(proto string) *LibMesh {
m := NewLibMesh()
// Controller has no peers, only a listener
controllerNodeID := "controller"
controller := m.NewLibNode(controllerNodeID)
controller.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
i := 1
// All nodes peer out to "controller"
for i <= 15 {
nodeID := fmt.Sprintf("node%d", i)
node := m.NewLibNode(nodeID)
node.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
}
i++
}
return &m
}
func randomMesh(proto string) *LibMesh {
m := NewLibMesh()
// Controller only has a listener
controller := m.NewLibNode("controller")
controller.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node1 := m.NewLibNode("node1")
node2 := m.NewLibNode("node2")
node3 := m.NewLibNode("node3")
node4 := m.NewLibNode("node4")
node5 := m.NewLibNode("node5")
node6 := m.NewLibNode("node6")
node7 := m.NewLibNode("node7")
node8 := m.NewLibNode("node8")
node9 := m.NewLibNode("node9")
node10 := m.NewLibNode("node10")
node11 := m.NewLibNode("node11")
node12 := m.NewLibNode("node12")
// node1 connects to controller
node1.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node1.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
}
// node2 connects to node1
node2.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node2.Connections = []Connection{
{RemoteNode: node1, Protocol: proto},
}
// node3 connects to node4 and node6
node3.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node3.Connections = []Connection{
{RemoteNode: node4, Protocol: proto},
{RemoteNode: node6, Protocol: proto},
}
// node4 connects to node2 and node7
node4.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node4.Connections = []Connection{
{RemoteNode: node2, Protocol: proto},
{RemoteNode: node7, Protocol: proto},
}
// node5 connects to node8 and node12
node5.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node5.Connections = []Connection{
{RemoteNode: node8, Protocol: proto},
{RemoteNode: node12, Protocol: proto},
}
// node6 connects to node10
node6.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node6.Connections = []Connection{
{RemoteNode: node10, Protocol: proto},
}
// node7 connects to node1 and node3
node7.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node7.Connections = []Connection{
{RemoteNode: node1, Protocol: proto},
{RemoteNode: node3, Protocol: proto},
}
// node8 connects to node1
node8.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node8.Connections = []Connection{
{RemoteNode: node1, Protocol: proto},
}
// node9 connects to node5 and node10
node9.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node9.Connections = []Connection{
{RemoteNode: node5, Protocol: proto},
{RemoteNode: node10, Protocol: proto},
}
// node10 connects to node4 and node12
node10.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node10.Connections = []Connection{
{RemoteNode: node4, Protocol: proto},
{RemoteNode: node12, Protocol: proto},
}
// node11 connects to node1
node11.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node11.Connections = []Connection{
{RemoteNode: node1, Protocol: proto},
}
// node12 connects to controller and node11
node12.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node12.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
{RemoteNode: node11, Protocol: proto},
}
return &m
}
func treeMesh(proto string) *LibMesh {
m := NewLibMesh()
// Controller only has a listener
controller := m.NewLibNode("controller")
controller.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
// node1 connects to controller
node1 := m.NewLibNode("node1")
node1.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node1.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
}
// nodes2-4 connects to node1
for _, id := range []int{2, 3, 4} {
node := m.NewLibNode(fmt.Sprintf("node%d", id))
node.Connections = []Connection{
{RemoteNode: node1, Protocol: proto},
}
}
// node5 connects to controller
node5 := m.NewLibNode("node5")
node5.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node5.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
}
// node6-8 connects to node5
for _, id := range []int{6, 7, 8} {
node := m.NewLibNode(fmt.Sprintf("node%d", id))
node.Connections = []Connection{
{RemoteNode: node5, Protocol: proto},
}
}
// node9 connects to controller
node9 := m.NewLibNode("node9")
node9.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName(proto): newListenerCfg(proto, "", 1, nil),
}
node9.Connections = []Connection{
{RemoteNode: controller, Protocol: proto},
}
// node10-12 connects to node9
for _, id := range []int{10, 11, 12} {
node := m.NewLibNode(fmt.Sprintf("node%d", id))
node.Connections = []Connection{
{RemoteNode: node9, Protocol: proto},
}
}
return &m
}
// used in work_test.go.
func workTestMesh(workPluginName workPlugin) *LibMesh {
caKey, caCrt, err := utils.GenerateCA("ca", "localhost")
if err != nil {
panic(err)
}
key1, crt1, err := utils.GenerateCertWithCA("node1", caKey, caCrt, "localhost", []string{"localhost"}, []string{"node1"})
if err != nil {
panic(err)
}
key2, crt2, err := utils.GenerateCertWithCA("node2", caKey, caCrt, "localhost", []string{"localhost"}, []string{"node2"})
if err != nil {
panic(err)
}
key3, crt3, err := utils.GenerateCertWithCA("node3", caKey, caCrt, "localhost", []string{"localhost"}, []string{"node3"})
if err != nil {
panic(err)
}
key4, crt4, err := utils.GenerateCertWithCA("node1wrongCN", caKey, caCrt, "node1wrongCN", nil, []string{"node1wrongCN"})
if err != nil {
panic(err)
}
m := NewLibMesh()
// node1 -> node2 <- node3
node1 := m.NewLibNode("node1")
node2 := m.NewLibNode("node2")
node3 := m.NewLibNode("node3")
// node1 dials out to node2
node1.Connections = []Connection{
{RemoteNode: node2, Protocol: "tcp", TLS: "client"},
}
node1.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName("tcp"): newListenerCfg("tcp", "", 1, nil),
}
node1.TLSClientConfigs = []*netceptor.TLSClientConfig{
{
Name: "client",
Key: key1,
Cert: crt1,
RootCAs: caCrt,
},
{
Name: "tlsclientwrongCN",
Key: key4,
Cert: crt4,
RootCAs: caCrt,
SkipReceptorNamesCheck: true,
},
}
// node2 has a listener
node2.workerConfigs = []workceptor.WorkerConfig{workTestConfigs[workPluginName]["echosleepshort"]}
node2.ListenerCfgs = map[listenerName]ListenerCfg{
listenerName("tcp"): newListenerCfg("tcp", "server", 1, nil),
}
node2.TLSServerConfigs = []*netceptor.TLSServerConfig{
{
Name: "server",
Key: key2,
Cert: crt2,
RequireClientCert: true,
ClientCAs: caCrt,
},
}
node2.TLSClientConfigs = []*netceptor.TLSClientConfig{
{
Name: "client",
Key: key2,
Cert: crt2,
RootCAs: caCrt,
},
}
node2.controlServerTLS = "server"
// node3 dials out to node2
node3.Connections = []Connection{
{RemoteNode: node2, Protocol: "tcp", TLS: "client"},
}
node3.workerConfigs = []workceptor.WorkerConfig{
workTestConfigs[workPluginName]["echosleepshort"],
workTestConfigs[workPluginName]["echosleeplong"],
workTestConfigs[workPluginName]["echosleeplong50"],
}
node3.TLSClientConfigs = []*netceptor.TLSClientConfig{
{
Name: "client",
Key: key3,
Cert: crt3,
RootCAs: caCrt,
},
}
return &m
}