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.

67 lines
1.7 KiB

10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 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. Host string `json:"host"`
  12. P2PPort uint16 `json:"p2p_port"`
  13. RPCPort uint16 `json:"rpc_port"`
  14. Version Versions `json:"versions"`
  15. }
  16. type Versions struct {
  17. Revision string `json:"revision"`
  18. Tendermint string `json:"tendermint"`
  19. P2P string `json:"p2p"`
  20. RPC string `json:"rpc"`
  21. Wire string `json:"wire"`
  22. }
  23. // CONTRACT: two nodes with the same Tendermint major and minor version and with the same ChainID are compatible
  24. func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {
  25. iM, im, _, ie := splitVersion(ni.Version.Tendermint)
  26. oM, om, _, oe := splitVersion(no.Version.Tendermint)
  27. // if our own version number is not formatted right, we messed up
  28. if ie != nil {
  29. return ie
  30. }
  31. // version number must be formatted correctly ("x.x.x")
  32. if oe != nil {
  33. return oe
  34. }
  35. // major version must match
  36. if iM != oM {
  37. return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oM, iM)
  38. }
  39. // minor version must match
  40. if im != om {
  41. return fmt.Errorf("Peer is on a different minor version. Got %v, expected %v", om, im)
  42. }
  43. // nodes must be on the same chain_id
  44. if ni.ChainID != no.ChainID {
  45. return fmt.Errorf("Peer is on a different chain_id. Got %v, expected %v", no.ChainID, ni.ChainID)
  46. }
  47. return nil
  48. }
  49. func splitVersion(version string) (string, string, string, error) {
  50. spl := strings.Split(version, ".")
  51. if len(spl) != 3 {
  52. return "", "", "", fmt.Errorf("Invalid version format %v", version)
  53. }
  54. return spl[0], spl[1], spl[2], nil
  55. }