提交 2a5b3eaa 作者: Henry

compare versions for compatibility

上级 0075a352
...@@ -164,6 +164,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error { ...@@ -164,6 +164,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
var remoteVersion, myVersion *version.SemVer var remoteVersion, myVersion *version.SemVer
myVersion = version.Current() myVersion = version.Current()
// BUG(cryptix): do we need to use a NetMessage here?
myVersionMsg, err := msg.FromObject(s.local, myVersion) myVersionMsg, err := msg.FromObject(s.local, myVersion)
if err != nil { if err != nil {
return fmt.Errorf("connVersionExchange: could not prepare local version: %q", err) return fmt.Errorf("connVersionExchange: could not prepare local version: %q", err)
...@@ -215,7 +216,12 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error { ...@@ -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. // Handles the unwrapping + sending of messages to the right connection.
......
...@@ -2,7 +2,7 @@ package version ...@@ -2,7 +2,7 @@ package version
import semver "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver" 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, Major: 0,
Minor: 1, Minor: 1,
Patch: 0, Patch: 0,
...@@ -13,8 +13,16 @@ func Current() *SemVer { ...@@ -13,8 +13,16 @@ func Current() *SemVer {
return toPBSemVer(currentVersion) 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 // 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{ return &SemVer{
Major: &in.Major, Major: &in.Major,
Minor: &in.Minor, Minor: &in.Minor,
...@@ -23,7 +31,7 @@ func toPBSemVer(in semver.Version) (out *SemVer) { ...@@ -23,7 +31,7 @@ func toPBSemVer(in semver.Version) (out *SemVer) {
} }
// toPBSemVar converts our protobuf SemVer to a coreos/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{ return &semver.Version{
Major: *in.Major, Major: *in.Major,
Minor: *in.Minor, Minor: *in.Minor,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论