Validate validates the NodeHostConfig instance and return an error when the configuration is considered as invalid.
()
| 510 | // Validate validates the NodeHostConfig instance and return an error when |
| 511 | // the configuration is considered as invalid. |
| 512 | func (c *NodeHostConfig) Validate() error { |
| 513 | if c.RTTMillisecond == 0 { |
| 514 | return errors.New("invalid RTTMillisecond") |
| 515 | } |
| 516 | if len(c.NodeHostDir) == 0 { |
| 517 | return errors.New("NodeHostConfig.NodeHostDir is empty") |
| 518 | } |
| 519 | if !c.MutualTLS && |
| 520 | (len(c.CAFile) > 0 || len(c.CertFile) > 0 || len(c.KeyFile) > 0) { |
| 521 | plog.Warningf("CAFile/CertFile/KeyFile specified when MutualTLS is disabled") |
| 522 | } |
| 523 | if c.MutualTLS { |
| 524 | if len(c.CAFile) == 0 { |
| 525 | return errors.New("CA file not specified") |
| 526 | } |
| 527 | if len(c.CertFile) == 0 { |
| 528 | return errors.New("cert file not specified") |
| 529 | } |
| 530 | if len(c.KeyFile) == 0 { |
| 531 | return errors.New("key file not specified") |
| 532 | } |
| 533 | } |
| 534 | if c.MaxSendQueueSize > 0 && |
| 535 | c.MaxSendQueueSize < settings.EntryNonCmdFieldsSize+1 { |
| 536 | return errors.New("MaxSendQueueSize value is too small") |
| 537 | } |
| 538 | if c.MaxReceiveQueueSize > 0 && |
| 539 | c.MaxReceiveQueueSize < settings.EntryNonCmdFieldsSize+1 { |
| 540 | return errors.New("MaxReceiveSize value is too small") |
| 541 | } |
| 542 | if c.RaftRPCFactory != nil && c.Expert.TransportFactory != nil { |
| 543 | return errors.New("both TransportFactory and RaftRPCFactory specified") |
| 544 | } |
| 545 | if c.LogDBFactory != nil && c.Expert.LogDBFactory != nil { |
| 546 | return errors.New("both LogDBFactory and Expert.LogDBFactory specified") |
| 547 | } |
| 548 | if c.AddressByNodeHostID && c.Gossip.IsEmpty() { |
| 549 | return errors.New("gossip service not configured") |
| 550 | } |
| 551 | validate := c.GetRaftAddressValidator() |
| 552 | if !validate(c.RaftAddress) { |
| 553 | return errors.New("invalid NodeHost address") |
| 554 | } |
| 555 | if len(c.ListenAddress) > 0 && !validate(c.ListenAddress) { |
| 556 | return errors.New("invalid ListenAddress") |
| 557 | } |
| 558 | if !c.Gossip.IsEmpty() { |
| 559 | if err := c.Gossip.Validate(); err != nil { |
| 560 | return err |
| 561 | } |
| 562 | } |
| 563 | if !c.Expert.Engine.IsEmpty() { |
| 564 | if err := c.Expert.Engine.Validate(); err != nil { |
| 565 | return err |
| 566 | } |
| 567 | } |
| 568 | return nil |
| 569 | } |