Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
78eb3493
Commit
78eb3493
authored
Oct 16, 2014
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed Compatible and added a small test case
parent
2a5b3eaa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
11 deletions
+34
-11
net/swarm/conn.go
net/swarm/conn.go
+4
-4
net/version/version.go
net/version/version.go
+5
-7
net/version/version_test.go
net/version/version_test.go
+25
-0
No files found.
net/swarm/conn.go
View file @
78eb3493
...
...
@@ -194,7 +194,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
remote
.
Secure
.
Out
<-
our
sendMine
=
true
close
(
outBuf
)
// only send local version once
log
.
Debug
(
"
[peer: %s]
Send my version(%s) to
%s"
,
s
.
local
,
myVersion
,
remote
.
Peer
)
log
.
Debug
(
"Send my version(%s)
[
to
= %s]"
,
myVersion
,
remote
.
Peer
)
}
case
data
,
ok
:=
<-
remote
.
Secure
.
In
:
...
...
@@ -202,8 +202,6 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
return
fmt
.
Errorf
(
"Error retrieving from conn: %v"
,
remote
.
Peer
)
}
log
.
Debug
(
"[peer: %s] Received message [from = %s]"
,
s
.
local
,
remote
.
Peer
)
remoteVersion
=
new
(
version
.
SemVer
)
err
=
proto
.
Unmarshal
(
data
,
remoteVersion
)
if
err
!=
nil
{
...
...
@@ -211,16 +209,18 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
return
fmt
.
Errorf
(
"connSetup: could not decode remote version: %q"
,
err
)
}
gotTheirs
=
true
log
.
Debug
(
"Received remote version(%s) [from = %s]"
,
remoteVersion
,
remote
.
Peer
)
// BUG(cryptix): could add another case here to trigger resending our version
}
}
if
!
version
.
Compatible
(
myVersion
,
remoteVersion
)
{
if
!
version
.
Compatible
(
myVersion
.
Convert
()
,
remoteVersion
.
Convert
()
)
{
remote
.
Close
()
return
errors
.
New
(
"protocol missmatch"
)
}
log
.
Debug
(
"[peer: %s] Version compatible"
,
remote
.
Peer
)
return
nil
}
...
...
net/version/version.go
View file @
78eb3493
...
...
@@ -14,10 +14,8 @@ func Current() *SemVer {
}
// Compatible checks wether two versions are compatible
func
Compatible
(
a
,
b
*
SemVer
)
bool
{
aConv
:=
fromPBSemVer
(
a
)
bConv
:=
fromPBSemVer
(
b
)
return
aConv
.
LessThan
(
*
bConv
)
func
Compatible
(
a
,
b
semver
.
Version
)
bool
{
return
!
a
.
LessThan
(
b
)
}
// toPBSemVar converts a coreos/semver to our protobuf SemVer
...
...
@@ -30,9 +28,9 @@ func toPBSemVer(in *semver.Version) (out *SemVer) {
}
}
//
toPBSemVar c
onvert
s
our protobuf SemVer to a coreos/semver
func
fromPBSemVer
(
in
*
SemVer
)
*
semver
.
Version
{
return
&
semver
.
Version
{
//
C
onvert our protobuf SemVer to a coreos/semver
func
(
in
SemVer
)
Convert
()
semver
.
Version
{
return
semver
.
Version
{
Major
:
*
in
.
Major
,
Minor
:
*
in
.
Minor
,
Patch
:
*
in
.
Patch
,
...
...
net/version/version_test.go
0 → 100644
View file @
78eb3493
package
version
import
(
"testing"
semver
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
)
func
TestCompatible
(
t
*
testing
.
T
)
{
tcases
:=
[]
struct
{
a
,
b
semver
.
Version
expected
bool
}{
{
semver
.
Version
{
Major
:
0
},
semver
.
Version
{
Major
:
0
},
true
},
{
semver
.
Version
{
Major
:
1
},
semver
.
Version
{
Major
:
0
},
true
},
{
semver
.
Version
{
Major
:
1
},
semver
.
Version
{
Major
:
1
},
true
},
{
semver
.
Version
{
Major
:
0
},
semver
.
Version
{
Major
:
1
},
false
},
}
for
i
,
tcase
:=
range
tcases
{
if
Compatible
(
tcase
.
a
,
tcase
.
b
)
!=
tcase
.
expected
{
t
.
Fatalf
(
"case[%d] failed"
,
i
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment