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

Function genConfigs

polyamide/device/device_test.go:53–92  ·  view source on GitHub ↗

genConfigs generates a pair of configs that connect to each other. The configs use distinct, probably-usable ports.

(tb testing.TB)

Source from the content-addressed store, hash-verified

51// genConfigs generates a pair of configs that connect to each other.
52// The configs use distinct, probably-usable ports.
53func genConfigs(tb testing.TB) (cfgs, endpointCfgs [2]string) {
54 var key1, key2 NoisePrivateKey
55 _, err := rand.Read(key1[:])
56 if err != nil {
57 tb.Errorf("unable to generate private key random bytes: %v", err)
58 }
59 _, err = rand.Read(key2[:])
60 if err != nil {
61 tb.Errorf("unable to generate private key random bytes: %v", err)
62 }
63 pub1, pub2 := key1.publicKey(), key2.publicKey()
64
65 cfgs[0] = uapiCfg(
66 "private_key", hex.EncodeToString(key1[:]),
67 "listen_port", "0",
68 "replace_peers", "true",
69 "public_key", hex.EncodeToString(pub2[:]),
70 "protocol_version", "1",
71 "replace_allowed_ips", "true",
72 "allowed_ip", "1.0.0.2/32",
73 )
74 endpointCfgs[0] = uapiCfg(
75 "public_key", hex.EncodeToString(pub2[:]),
76 "endpoint", "127.0.0.1:%d",
77 )
78 cfgs[1] = uapiCfg(
79 "private_key", hex.EncodeToString(key2[:]),
80 "listen_port", "0",
81 "replace_peers", "true",
82 "public_key", hex.EncodeToString(pub1[:]),
83 "protocol_version", "1",
84 "replace_allowed_ips", "true",
85 "allowed_ip", "1.0.0.1/32",
86 )
87 endpointCfgs[1] = uapiCfg(
88 "public_key", hex.EncodeToString(pub1[:]),
89 "endpoint", "127.0.0.1:%d",
90 )
91 return
92}
93
94// A testPair is a pair of testPeers.
95type testPair [2]testPeer

Callers 1

genTestPairFunction · 0.85

Calls 3

publicKeyMethod · 0.95
uapiCfgFunction · 0.85
ReadMethod · 0.65

Tested by

no test coverage detected