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

Function NodeConfigValidator

state/validation.go:23–64  ·  view source on GitHub ↗
(central *CentralCfg, node *LocalCfg)

Source from the content-addressed store, hash-verified

21}
22
23func NodeConfigValidator(central *CentralCfg, node *LocalCfg) error {
24 err := NameValidator(string(node.Id))
25 if err != nil {
26 return err
27 }
28 if node.Port == 0 {
29 return fmt.Errorf("port must be greater than 0")
30 }
31 if node.Key == [32]byte{} {
32 return fmt.Errorf("private key must not be empty")
33 }
34 if node.InterfaceName != "" {
35 err = NameValidator(node.InterfaceName)
36 if err != nil {
37 return fmt.Errorf("interface name is invalid: %v", err)
38 }
39 }
40 if node.Dist != nil {
41 _, err := url.Parse(node.Dist.Url)
42 if err != nil {
43 return err
44 }
45 }
46 if len(node.DnsResolvers) != 0 {
47 for _, resolver := range node.DnsResolvers {
48 if _, err := netip.ParseAddrPort(resolver); err != nil {
49 return fmt.Errorf("dns resolver %s is not a valid ip:port: %v", resolver, err)
50 }
51 }
52 }
53 // validate prefixes
54 for _, p := range append(node.UnexcludeIPs, node.ExcludeIPs...) {
55 if !p.IsValid() {
56 return fmt.Errorf("invalid prefix %s", p)
57 }
58 }
59 // check that node is in central config
60 if central != nil && !central.IsNode(node.Id) {
61 return fmt.Errorf("node %s is not in central config", node.Id)
62 }
63 return nil
64}
65
66func AddrToPrefix(addr netip.Addr) netip.Prefix {
67 res, err := addr.Prefix(addr.BitLen())

Callers 3

BootstrapFunction · 0.92
verify.goFile · 0.92

Calls 3

NameValidatorFunction · 0.85
ParseMethod · 0.80
IsNodeMethod · 0.80

Tested by 1