mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-24 02:01:43 +00:00
versioning
This commit is contained in:
@ -188,6 +188,7 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
|
|||||||
nodeInfo := &types.NodeInfo{
|
nodeInfo := &types.NodeInfo{
|
||||||
Moniker: config.App().GetString("Moniker"),
|
Moniker: config.App().GetString("Moniker"),
|
||||||
Network: config.App().GetString("Network"),
|
Network: config.App().GetString("Network"),
|
||||||
|
Version: "0.0.1",
|
||||||
}
|
}
|
||||||
if !sw.IsListening() {
|
if !sw.IsListening() {
|
||||||
return nodeInfo
|
return nodeInfo
|
||||||
|
@ -12,12 +12,6 @@ import (
|
|||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type nodeInfo struct {
|
|
||||||
Host string
|
|
||||||
RPCPort uint16
|
|
||||||
P2PPort uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
outbound bool
|
outbound bool
|
||||||
mconn *MConnection
|
mconn *MConnection
|
||||||
|
@ -161,9 +161,10 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if peerNodeInfo.Network != sw.nodeInfo.Network {
|
if err := sw.nodeInfo.CompatibleWith(peerNodeInfo); err != nil {
|
||||||
return nil, fmt.Errorf("Peer is on different network %v", peerNodeInfo.Network)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
peer := newPeer(conn, peerNodeInfo, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError)
|
peer := newPeer(conn, peerNodeInfo, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError)
|
||||||
|
|
||||||
// Add the peer to .peers
|
// Add the peer to .peers
|
||||||
|
@ -1,9 +1,56 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type NodeInfo struct {
|
type NodeInfo struct {
|
||||||
Moniker string
|
Moniker string
|
||||||
Network string
|
Network string
|
||||||
|
Version string
|
||||||
|
|
||||||
Host string
|
Host string
|
||||||
P2PPort uint16
|
P2PPort uint16
|
||||||
RPCPort uint16
|
RPCPort uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {
|
||||||
|
iM, im, _, ie := splitVersion(ni.Version)
|
||||||
|
oM, om, _, oe := splitVersion(no.Version)
|
||||||
|
|
||||||
|
// if our own version number is not formatted right, we messed up
|
||||||
|
if ie != nil {
|
||||||
|
return ie
|
||||||
|
}
|
||||||
|
|
||||||
|
// version number must be formatted correctly ("x.x.x")
|
||||||
|
if oe != nil {
|
||||||
|
return oe
|
||||||
|
}
|
||||||
|
|
||||||
|
// major version must match
|
||||||
|
if iM != oM {
|
||||||
|
return fmt.Errorf("Peer is on a different major version. Got %v, expected %v", oM, iM)
|
||||||
|
}
|
||||||
|
|
||||||
|
// minor version must match
|
||||||
|
if im != om {
|
||||||
|
return fmt.Errorf("Peer is on a different minor version. Got %v, expected %v", om, im)
|
||||||
|
}
|
||||||
|
|
||||||
|
// nodes must be on the same network
|
||||||
|
if ni.Network != no.Network {
|
||||||
|
return fmt.Errorf("Peer is on a different network. Got %v, expected %v", no.Network, ni.Network)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user