Browse Source

versioning

pull/61/head
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
0e80059e79
4 changed files with 51 additions and 8 deletions
  1. +1
    -0
      node/node.go
  2. +0
    -6
      p2p/peer.go
  3. +3
    -2
      p2p/switch.go
  4. +47
    -0
      types/node.go

+ 1
- 0
node/node.go View File

@ -188,6 +188,7 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
nodeInfo := &types.NodeInfo{
Moniker: config.App().GetString("Moniker"),
Network: config.App().GetString("Network"),
Version: "0.0.1",
}
if !sw.IsListening() {
return nodeInfo


+ 0
- 6
p2p/peer.go View File

@ -12,12 +12,6 @@ import (
"github.com/tendermint/tendermint/types"
)
type nodeInfo struct {
Host string
RPCPort uint16
P2PPort uint16
}
type Peer struct {
outbound bool
mconn *MConnection


+ 3
- 2
p2p/switch.go View File

@ -161,9 +161,10 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
if err != nil {
return nil, err
}
if peerNodeInfo.Network != sw.nodeInfo.Network {
return nil, fmt.Errorf("Peer is on different network %v", peerNodeInfo.Network)
if err := sw.nodeInfo.CompatibleWith(peerNodeInfo); err != nil {
return nil, err
}
peer := newPeer(conn, peerNodeInfo, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError)
// Add the peer to .peers


+ 47
- 0
types/node.go View File

@ -1,9 +1,56 @@
package types
import (
"fmt"
"strings"
)
type NodeInfo struct {
Moniker string
Network string
Version string
Host string
P2PPort 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
}

Loading…
Cancel
Save