Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
67e04f0d
提交
67e04f0d
authored
10月 16, 2014
作者:
Henry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changed message from SemVer to Handshake1
上级
6f8a89cd
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
81 行增加
和
49 行删除
+81
-49
semver.pb.go
net/handshake/semver.pb.go
+20
-25
semver.proto
net/handshake/semver.proto
+9
-5
version.go
net/handshake/version.go
+42
-11
version_test.go
net/handshake/version_test.go
+9
-7
conn.go
net/swarm/conn.go
+1
-1
没有找到文件。
net/handshake/semver.pb.go
浏览文件 @
67e04f0d
...
@@ -9,47 +9,42 @@ It is generated from these files:
...
@@ -9,47 +9,42 @@ It is generated from these files:
semver.proto
semver.proto
It has these top-level messages:
It has these top-level messages:
SemVer
Handshake1
*/
*/
package
handshake
package
handshake
import
proto
"code.google.com/p/gogoprotobuf/proto"
import
proto
"
github.com/jbenet/go-ipfs/Godeps/_workspace/src/
code.google.com/p/gogoprotobuf/proto"
import
math
"math"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
proto
.
Marshal
var
_
=
math
.
Inf
var
_
=
math
.
Inf
type
SemVer
struct
{
type
Handshake1
struct
{
Major
*
int64
`protobuf:"varint,1,opt,name=major" json:"major,omitempty"`
// protocolVersion determines compatibility between peers
Minor
*
int64
`protobuf:"varint,2,opt,name=minor" json:"minor,omitempty"`
ProtocolVersion
*
string
`protobuf:"bytes,1,opt,name=protocolVersion" json:"protocolVersion,omitempty"`
Patch
*
int64
`protobuf:"varint,3,opt,name=patch" json:"patch,omitempty"`
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
XXX_unrecognized
[]
byte
`json:"-"`
// includes the client name and client. e.g. "go-ipfs/0.1.0"
AgentVersion
*
string
`protobuf:"bytes,2,opt,name=agentVersion" json:"agentVersion,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
}
func
(
m
*
SemVer
)
Reset
()
{
*
m
=
SemVer
{}
}
func
(
m
*
Handshake1
)
Reset
()
{
*
m
=
Handshake1
{}
}
func
(
m
*
SemVer
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
m
*
Handshake1
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
SemVer
)
ProtoMessage
()
{}
func
(
*
Handshake1
)
ProtoMessage
()
{}
func
(
m
*
SemVer
)
GetMajor
()
int64
{
func
(
m
*
Handshake1
)
GetProtocolVersion
()
string
{
if
m
!=
nil
&&
m
.
Major
!=
nil
{
if
m
!=
nil
&&
m
.
ProtocolVersion
!=
nil
{
return
*
m
.
Major
return
*
m
.
ProtocolVersion
}
}
return
0
return
""
}
}
func
(
m
*
SemVer
)
GetMinor
()
int64
{
func
(
m
*
Handshake1
)
GetAgentVersion
()
string
{
if
m
!=
nil
&&
m
.
Minor
!=
nil
{
if
m
!=
nil
&&
m
.
AgentVersion
!=
nil
{
return
*
m
.
Minor
return
*
m
.
AgentVersion
}
}
return
0
return
""
}
func
(
m
*
SemVer
)
GetPatch
()
int64
{
if
m
!=
nil
&&
m
.
Patch
!=
nil
{
return
*
m
.
Patch
}
return
0
}
}
func
init
()
{
func
init
()
{
...
...
net/handshake/semver.proto
浏览文件 @
67e04f0d
package
handshake
;
package
handshake
;
message
SemVer
{
message
Handshake1
{
optional
int64
major
=
1
;
// protocolVersion determines compatibility between peers
optional
int64
minor
=
2
;
optional
string
protocolVersion
=
1
;
// semver
optional
int64
patch
=
3
;
// BUG(cryptix): do we need PreRelease and Metadata too?
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
// includes the client name and client. e.g. "go-ipfs/0.1.0"
optional
string
agentVersion
=
2
;
// semver
// we'll have more fields here later.
}
}
net/handshake/version.go
浏览文件 @
67e04f0d
package
handshake
package
handshake
import
(
"errors"
"fmt"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
)
// currentVersion holds the current protocol version for a client running this code
// currentVersion holds the current protocol version for a client running this code
var
currentVersion
=
NewSemVer
(
0
,
0
,
1
)
var
currentVersion
*
semver
.
Version
func
init
()
{
var
err
error
currentVersion
,
err
=
semver
.
NewVersion
(
"0.0.1"
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid protocol version: %v"
,
err
))
}
}
// Current returns the current protocol version as a protobuf message
// Current returns the current protocol version as a protobuf message
func
Current
()
*
SemVer
{
func
Current
()
*
semver
.
Version
{
return
currentVersion
return
currentVersion
}
}
// ErrVersionMismatch is returned when two clients don't share a protocol version
var
ErrVersionMismatch
=
errors
.
New
(
"protocol missmatch"
)
// Compatible checks wether two versions are compatible
// Compatible checks wether two versions are compatible
func
Compatible
(
a
,
b
*
SemVer
)
bool
{
// returns nil if they are fine
return
*
a
.
Major
==
*
b
.
Major
// protobuf fields are pointers
func
Compatible
(
handshakeA
,
handshakeB
*
Handshake1
)
error
{
a
,
err
:=
semver
.
NewVersion
(
*
handshakeA
.
ProtocolVersion
)
if
err
!=
nil
{
return
err
}
b
,
err
:=
semver
.
NewVersion
(
*
handshakeB
.
ProtocolVersion
)
if
err
!=
nil
{
return
err
}
if
a
.
Major
!=
b
.
Major
{
return
ErrVersionMismatch
}
return
nil
}
}
// NewSemVer constructs a new protobuf SemVer
// NewHandshake1 creates a new Handshake1 from the two strings
func
NewSemVer
(
major
,
minor
,
patch
int64
)
*
SemVer
{
func
NewHandshake1
(
protoVer
,
agentVer
string
)
*
Handshake1
{
s
:=
new
(
SemVer
)
return
&
Handshake1
{
s
.
Major
=
&
major
ProtocolVersion
:
&
protoVer
,
s
.
Minor
=
&
minor
AgentVersion
:
&
agentVer
,
s
.
Patch
=
&
patch
}
return
s
}
}
net/handshake/version_test.go
浏览文件 @
67e04f0d
...
@@ -4,17 +4,19 @@ import "testing"
...
@@ -4,17 +4,19 @@ import "testing"
func
TestCompatible
(
t
*
testing
.
T
)
{
func
TestCompatible
(
t
*
testing
.
T
)
{
tcases
:=
[]
struct
{
tcases
:=
[]
struct
{
a
,
b
*
SemVer
a
,
b
string
expected
bool
expected
error
}{
}{
{
NewSemVer
(
0
,
0
,
0
),
NewSemVer
(
0
,
0
,
0
),
true
},
{
"0.0.0"
,
"0.0.0"
,
nil
},
{
NewSemVer
(
0
,
0
,
0
),
NewSemVer
(
1
,
0
,
0
),
false
},
{
"1.0.0"
,
"1.1.0"
,
nil
},
{
NewSemVer
(
1
,
0
,
0
),
NewSemVer
(
0
,
0
,
0
),
false
},
{
"1.0.0"
,
"1.0.1"
,
nil
},
{
NewSemVer
(
1
,
0
,
0
),
NewSemVer
(
1
,
0
,
0
),
true
},
{
"0.0.0"
,
"1.0.0"
,
ErrVersionMismatch
},
{
"1.0.0"
,
"0.0.0"
,
ErrVersionMismatch
},
}
}
for
i
,
tcase
:=
range
tcases
{
for
i
,
tcase
:=
range
tcases
{
if
Compatible
(
tcase
.
a
,
tcase
.
b
)
!=
tcase
.
expected
{
if
Compatible
(
NewHandshake1
(
tcase
.
a
,
""
),
NewHandshake1
(
tcase
.
b
,
""
))
!=
tcase
.
expected
{
t
.
Fatalf
(
"case[%d] failed"
,
i
)
t
.
Fatalf
(
"case[%d] failed"
,
i
)
}
}
}
}
...
...
net/swarm/conn.go
浏览文件 @
67e04f0d
...
@@ -217,7 +217,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
...
@@ -217,7 +217,7 @@ func (s *Swarm) connVersionExchange(remote *conn.Conn) error {
if
!
handshake
.
Compatible
(
myVersion
,
remoteVersion
)
{
if
!
handshake
.
Compatible
(
myVersion
,
remoteVersion
)
{
remote
.
Close
()
remote
.
Close
()
return
errors
.
New
(
"protocol missmatch"
)
return
handshake
.
ErrVersionMismatch
}
}
log
.
Debug
(
"[peer: %s] Version compatible"
,
remote
.
Peer
)
log
.
Debug
(
"[peer: %s] Version compatible"
,
remote
.
Peer
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论