mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-06 08:47:52 +08:00
compare versions for compatibility
This commit is contained in:
parent
0075a352da
commit
2a5b3eaa71
@ -164,6 +164,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
|
||||
var remoteVersion, myVersion *version.SemVer
|
||||
myVersion = version.Current()
|
||||
|
||||
// BUG(cryptix): do we need to use a NetMessage here?
|
||||
myVersionMsg, err := msg.FromObject(s.local, myVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("connVersionExchange: could not prepare local version: %q", err)
|
||||
@ -215,7 +216,12 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
|
||||
}
|
||||
}
|
||||
|
||||
return errors.New("not yet")
|
||||
if !version.Compatible(myVersion, remoteVersion) {
|
||||
remote.Close()
|
||||
return errors.New("protocol missmatch")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handles the unwrapping + sending of messages to the right connection.
|
||||
|
||||
@ -2,7 +2,7 @@ package version
|
||||
|
||||
import semver "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
|
||||
|
||||
var currentVersion = semver.Version{
|
||||
var currentVersion = &semver.Version{
|
||||
Major: 0,
|
||||
Minor: 1,
|
||||
Patch: 0,
|
||||
@ -13,8 +13,16 @@ func Current() *SemVer {
|
||||
return toPBSemVer(currentVersion)
|
||||
}
|
||||
|
||||
// Compatible checks wether two versions are compatible
|
||||
func Compatible(a, b *SemVer) bool {
|
||||
aConv := fromPBSemVer(a)
|
||||
bConv := fromPBSemVer(b)
|
||||
return aConv.LessThan(*bConv)
|
||||
}
|
||||
|
||||
// toPBSemVar converts a coreos/semver to our protobuf SemVer
|
||||
func toPBSemVer(in semver.Version) (out *SemVer) {
|
||||
func toPBSemVer(in *semver.Version) (out *SemVer) {
|
||||
|
||||
return &SemVer{
|
||||
Major: &in.Major,
|
||||
Minor: &in.Minor,
|
||||
@ -23,7 +31,7 @@ func toPBSemVer(in semver.Version) (out *SemVer) {
|
||||
}
|
||||
|
||||
// toPBSemVar converts our protobuf SemVer to a coreos/semver
|
||||
func fromPBSemVer(in SemVer) *semver.Version {
|
||||
func fromPBSemVer(in *SemVer) *semver.Version {
|
||||
return &semver.Version{
|
||||
Major: *in.Major,
|
||||
Minor: *in.Minor,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user