mirror of https://github.com/poanetwork/gecko.git
Merge pull request #105 from StephenButtolph/update-version
Update version
This commit is contained in:
commit
d00fab49c6
|
@ -26,6 +26,10 @@ import (
|
||||||
"github.com/ava-labs/gecko/utils/wrappers"
|
"github.com/ava-labs/gecko/utils/wrappers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
dbVersion = "v0.1.0"
|
||||||
|
)
|
||||||
|
|
||||||
// Results of parsing the CLI
|
// Results of parsing the CLI
|
||||||
var (
|
var (
|
||||||
Config = node.Config{}
|
Config = node.Config{}
|
||||||
|
@ -143,7 +147,7 @@ func init() {
|
||||||
// DB:
|
// DB:
|
||||||
if *db && err == nil {
|
if *db && err == nil {
|
||||||
// TODO: Add better params here
|
// TODO: Add better params here
|
||||||
dbPath := path.Join(*dbDir, genesis.NetworkName(Config.NetworkID))
|
dbPath := path.Join(*dbDir, genesis.NetworkName(Config.NetworkID), dbVersion)
|
||||||
db, err := leveldb.New(dbPath, 0, 0, 0)
|
db, err := leveldb.New(dbPath, 0, 0, 0)
|
||||||
Config.DB = db
|
Config.DB = db
|
||||||
errs.Add(err)
|
errs.Add(err)
|
||||||
|
|
|
@ -19,6 +19,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -61,9 +63,23 @@ Attempt reconnections
|
||||||
node isn't connected to after awhile delete the connection.
|
node isn't connected to after awhile delete the connection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Version this avalanche instance is executing.
|
||||||
|
var (
|
||||||
|
VersionPrefix = "avalanche/"
|
||||||
|
VersionSeparator = "."
|
||||||
|
MajorVersion = 0
|
||||||
|
MinorVersion = 1
|
||||||
|
PatchVersion = 0
|
||||||
|
ClientVersion = fmt.Sprintf("%s%d%s%d%s%d",
|
||||||
|
VersionPrefix,
|
||||||
|
MajorVersion,
|
||||||
|
VersionSeparator,
|
||||||
|
MinorVersion,
|
||||||
|
VersionSeparator,
|
||||||
|
PatchVersion)
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CurrentVersion this avalanche instance is executing.
|
|
||||||
CurrentVersion = "avalanche/0.0.1"
|
|
||||||
// MaxClockDifference allowed between connected nodes.
|
// MaxClockDifference allowed between connected nodes.
|
||||||
MaxClockDifference = time.Minute
|
MaxClockDifference = time.Minute
|
||||||
// PeerListGossipSpacing is the amount of time to wait between pushing this
|
// PeerListGossipSpacing is the amount of time to wait between pushing this
|
||||||
|
@ -356,7 +372,7 @@ func (nm *Handshake) SendGetVersion(peer salticidae.PeerID) {
|
||||||
// SendVersion to the requested peer
|
// SendVersion to the requested peer
|
||||||
func (nm *Handshake) SendVersion(peer salticidae.PeerID) error {
|
func (nm *Handshake) SendVersion(peer salticidae.PeerID) error {
|
||||||
build := Builder{}
|
build := Builder{}
|
||||||
v, err := build.Version(nm.networkID, nm.clock.Unix(), toIPDesc(nm.myAddr), CurrentVersion)
|
v, err := build.Version(nm.networkID, nm.clock.Unix(), toIPDesc(nm.myAddr), ClientVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("packing Version failed due to %s", err)
|
return fmt.Errorf("packing Version failed due to %s", err)
|
||||||
}
|
}
|
||||||
|
@ -518,6 +534,59 @@ func (nm *Handshake) disconnectedFromPeer(peer salticidae.PeerID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkCompatibility Check to make sure that the peer and I speak the same language.
|
||||||
|
func (nm *Handshake) checkCompatibility(peerVersion string) bool {
|
||||||
|
if !strings.HasPrefix(peerVersion, VersionPrefix) {
|
||||||
|
nm.log.Warn("Peer attempted to connect with an invalid version prefix")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
peerVersion = peerVersion[len(VersionPrefix):]
|
||||||
|
splitPeerVersion := strings.SplitN(peerVersion, VersionSeparator, 3)
|
||||||
|
if len(splitPeerVersion) != 3 {
|
||||||
|
nm.log.Warn("Peer attempted to connect with an invalid number of subversions")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
major, err := strconv.Atoi(splitPeerVersion[0])
|
||||||
|
if err != nil {
|
||||||
|
nm.log.Warn("Peer attempted to connect with an invalid major version")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
minor, err := strconv.Atoi(splitPeerVersion[1])
|
||||||
|
if err != nil {
|
||||||
|
nm.log.Warn("Peer attempted to connect with an invalid minor version")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
patch, err := strconv.Atoi(splitPeerVersion[2])
|
||||||
|
if err != nil {
|
||||||
|
nm.log.Warn("Peer attempted to connect with an invalid patch version")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case major < MajorVersion:
|
||||||
|
// peers major version is too low
|
||||||
|
return false
|
||||||
|
case major > MajorVersion:
|
||||||
|
nm.log.Warn("Peer attempted to connect with a higher major version, this client may need to be updated")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case minor < MinorVersion:
|
||||||
|
// peers minor version is too low
|
||||||
|
return false
|
||||||
|
case minor > MinorVersion:
|
||||||
|
nm.log.Warn("Peer attempted to connect with a higher minor version, this client may need to be updated")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if patch > PatchVersion {
|
||||||
|
nm.log.Warn("Peer is connecting with a higher patch version, this client may need to be updated")
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// peerHandler notifies a change to the set of connected peers
|
// peerHandler notifies a change to the set of connected peers
|
||||||
// connected is true if a new peer is connected
|
// connected is true if a new peer is connected
|
||||||
// connected is false if a formerly connected peer has disconnected
|
// connected is false if a formerly connected peer has disconnected
|
||||||
|
@ -645,8 +714,8 @@ func version(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.P
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if peerVersion := pMsg.Get(VersionStr).(string); !checkCompatibility(CurrentVersion, peerVersion) {
|
if peerVersion := pMsg.Get(VersionStr).(string); !HandshakeNet.checkCompatibility(peerVersion) {
|
||||||
HandshakeNet.log.Warn("Bad version")
|
HandshakeNet.log.Debug("Dropping connection due to an incompatible version from peer")
|
||||||
|
|
||||||
HandshakeNet.net.DelPeer(peer)
|
HandshakeNet.net.DelPeer(peer)
|
||||||
return
|
return
|
||||||
|
@ -741,12 +810,6 @@ func getCert(cert salticidae.X509) ids.ShortID {
|
||||||
return certID
|
return certID
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkCompatibility Check to make sure that the peer and I speak the same language.
|
|
||||||
func checkCompatibility(myVersion string, peerVersion string) bool {
|
|
||||||
// At the moment, we are all compatible.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func toShortID(ip utils.IPDesc) ids.ShortID {
|
func toShortID(ip utils.IPDesc) ids.ShortID {
|
||||||
return ids.NewShortID(hashing.ComputeHash160Array([]byte(ip.String())))
|
return ids.NewShortID(hashing.ComputeHash160Array([]byte(ip.String())))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue