You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. package types
  2. import (
  3. "fmt"
  4. acm "github.com/tendermint/tendermint/account"
  5. "strings"
  6. )
  7. type NodeInfo struct {
  8. PubKey acm.PubKeyEd25519 `json:"pub_key"`
  9. Moniker string `json:"moniker"`
  10. ChainID string `json:"chain_id"`
  11. Version string `json:"version"`
  12. Revision string `json:"revision"`
  13. Host string `json:"host"`
  14. P2PPort uint16 `json:"p2p_port"`
  15. RPCPort uint16 `json:"rpc_port"`
  16. }
  17. func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {
  18. iM, im, _, ie := splitVersion(ni.Version)
  19. oM, om, _, oe := splitVersion(no.Version)
  20. // if our own version number is not formatted right, we messed up
  21. if ie != nil {
  22. return ie
  23. }
  24. // version number must be formatted correctly ("x.x.x")
  25. if oe != nil {
  26. return oe
  27. }
  28. // major version must match
  29. if iM != oM {
  30. return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oM, iM)
  31. }
  32. // minor version must match
  33. if im != om {
  34. return fmt.Errorf("Peer is on a different minor version. Got %v, expected %v", om, im)
  35. }
  36. // nodes must be on the same chain_id
  37. if ni.ChainID != no.ChainID {
  38. return fmt.Errorf("Peer is on a different chain_id. Got %v, expected %v", no.ChainID, ni.ChainID)
  39. }
  40. return nil
  41. }
  42. func splitVersion(version string) (string, string, string, error) {
  43. spl := strings.Split(version, ".")
  44. if len(spl) != 3 {
  45. return "", "", "", fmt.Errorf("Invalid version format %v", version)
  46. }
  47. return spl[0], spl[1], spl[2], nil
  48. }