MCPcopy Create free account
hub / github.com/encodeous/nylon / SampleNetwork

Function SampleNetwork

state/utils_test.go:11–81  ·  view source on GitHub ↗
(t *testing.T, numClients, numRouters int, fullyConnected bool)

Source from the content-addressed store, hash-verified

9)
10
11func SampleNetwork(t *testing.T, numClients, numRouters int, fullyConnected bool) (CentralCfg, map[string]NyPrivateKey) {
12 t.Helper()
13 keyStore := make(map[string]NyPrivateKey)
14 keyStore["dist"] = GenerateKey()
15 cfg := CentralCfg{
16 Dist: &DistributionCfg{
17 Key: keyStore["dist"].Pubkey(),
18 Repos: []string{
19 "https://example.com",
20 "file:example.conf",
21 },
22 },
23 }
24
25 clients := make([]string, numClients)
26
27 for idx := range numClients {
28 client := fmt.Sprintf("client-%d", idx)
29 clients[idx] = client
30 keyStore[client] = GenerateKey()
31 cfg.Clients = append(cfg.Clients, ClientCfg{NodeCfg{
32 Id: NodeId(client),
33 PubKey: keyStore[client].Pubkey(),
34 Prefixes: []PrefixHealthWrapper{
35 {
36 &StaticPrefixHealth{
37 Prefix: netip.MustParsePrefix(fmt.Sprintf("10.1.0.%d/32", idx)),
38 Metric: 0,
39 },
40 },
41 },
42 }})
43 }
44
45 routers := make([]string, numRouters)
46
47 for idx := range numRouters {
48 router := fmt.Sprintf("router-%d", idx)
49 routers[idx] = router
50 keyStore[router] = GenerateKey()
51 cfg.Routers = append(cfg.Routers, RouterCfg{
52 NodeCfg: NodeCfg{
53 Id: NodeId(router),
54 PubKey: keyStore[router].Pubkey(),
55 Prefixes: []PrefixHealthWrapper{
56 {
57 &StaticPrefixHealth{
58 Prefix: netip.MustParsePrefix(fmt.Sprintf("10.1.0.%d/32", idx)),
59 Metric: 0,
60 },
61 },
62 },
63 },
64 Endpoints: []*DynamicEndpoint{
65 NewDynamicEndpoint(fmt.Sprintf("192.168.0.%d:25565", idx)),
66 },
67 })
68 }

Callers 1

TestSerializeFunction · 0.85

Calls 4

GenerateKeyFunction · 0.85
NodeIdTypeAlias · 0.85
NewDynamicEndpointFunction · 0.85
PubkeyMethod · 0.80

Tested by

no test coverage detected