"fmt"
"net"
"strconv"
- "strings"
crypto "github.com/tendermint/go-crypto"
+
+ "github.com/bytom/version"
)
const maxNodeInfoSize = 10240 // 10Kb
// CompatibleWith checks if two NodeInfo are compatible with eachother.
// CONTRACT: two nodes are compatible if the major version matches and network match
-// and they have at least one channel in common.
func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
- iMajor, _, _, err := splitVersion(info.Version)
- if err != nil {
- return err
- }
- oMajor, _, _, err := splitVersion(other.Version)
+ compatible, err := version.CompatibleWith(other.Version)
if err != nil {
return err
}
- if iMajor != oMajor {
- return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oMajor, iMajor)
+ if !compatible {
+ return fmt.Errorf("Peer is on a different major version. Peer version: %v, node version: %v.", other.Version, info.Version)
}
if info.Network != other.Network {
- return fmt.Errorf("Peer is on a different network. Got %v, expected %v", other.Network, info.Network)
+ return fmt.Errorf("Peer is on a different network. Peer network: %v, node network: %v.", other.Network, info.Network)
}
return nil
}
func (info NodeInfo) String() string {
return fmt.Sprintf("NodeInfo{pk: %v, moniker: %v, network: %v [listen %v], version: %v (%v)}", info.PubKey, info.Moniker, info.Network, info.ListenAddr, info.Version, info.Other)
}
-
-func splitVersion(version string) (string, string, string, error) {
- spl := strings.Split(version, ".")
- if len(spl) != 3 {
- return "", "", "", fmt.Errorf("Invalid version format %v", version)
- }
- return spl[0], spl[1], spl[2], nil
-}