Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
97c66ddc
提交
97c66ddc
authored
10月 22, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handshake1 renaming
上级
cc5c181a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
88 行增加
和
37 行删除
+88
-37
handshake.go
net/conn/handshake.go
+5
-4
Makefile
net/handshake/Makefile
+0
-8
handshake1.go
net/handshake/handshake1.go
+12
-10
handshake1_test.go
net/handshake/handshake1_test.go
+2
-2
Makefile
net/handshake/pb/Makefile
+11
-0
handshake.pb.go
net/handshake/pb/handshake.pb.go
+30
-6
handshake.proto
net/handshake/pb/handshake.proto
+28
-7
没有找到文件。
net/conn/handshake.go
浏览文件 @
97c66ddc
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
handshake
"github.com/jbenet/go-ipfs/net/handshake"
hspb
"github.com/jbenet/go-ipfs/net/handshake/pb"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
...
...
@@ -16,8 +17,8 @@ func VersionHandshake(ctx context.Context, c Conn) error {
rpeer
:=
c
.
RemotePeer
()
lpeer
:=
c
.
LocalPeer
()
var
remoteH
,
localH
*
h
andshake
.
Handshake1
localH
=
handshake
.
CurrentHandshake
()
var
remoteH
,
localH
*
h
spb
.
Handshake1
localH
=
handshake
.
Handshake1Msg
()
myVerBytes
,
err
:=
proto
.
Marshal
(
localH
)
if
err
!=
nil
{
...
...
@@ -39,7 +40,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
return
fmt
.
Errorf
(
"error retrieving from conn: %v"
,
rpeer
)
}
remoteH
=
new
(
h
andshake
.
Handshake1
)
remoteH
=
new
(
h
spb
.
Handshake1
)
err
=
proto
.
Unmarshal
(
data
,
remoteH
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"could not decode remote version: %q"
,
err
)
...
...
@@ -48,7 +49,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
log
.
Debug
(
"Received remote version (%s) from %s"
,
remoteH
,
rpeer
)
}
if
err
:=
handshake
.
Compatible
(
localH
,
remoteH
);
err
!=
nil
{
if
err
:=
handshake
.
Handshake1
Compatible
(
localH
,
remoteH
);
err
!=
nil
{
log
.
Info
(
"%s (%s) incompatible version with %s (%s)"
,
lpeer
,
localH
,
rpeer
,
remoteH
)
return
err
}
...
...
net/handshake/Makefile
deleted
100644 → 0
浏览文件 @
cc5c181a
all
:
semver.pb.go
semver.pb.go
:
semver.proto
protoc
--gogo_out
=
.
--proto_path
=
../../../../../:/usr/local/opt/protobuf/include:.
$<
clean
:
rm semver.pb.go
net/handshake/
version
.go
→
net/handshake/
handshake1
.go
浏览文件 @
97c66ddc
...
...
@@ -4,33 +4,35 @@ import (
"errors"
"fmt"
pb
"github.com/jbenet/go-ipfs/net/handshake/pb"
updates
"github.com/jbenet/go-ipfs/updates"
semver
"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
var
currentVersion
*
semver
.
Version
// ipfsVersion holds the current protocol version for a client running this code
var
ipfsVersion
*
semver
.
Version
var
clientVersion
=
"go-ipfs/"
+
updates
.
Version
func
init
()
{
var
err
error
current
Version
,
err
=
semver
.
NewVersion
(
"0.0.1"
)
ipfs
Version
,
err
=
semver
.
NewVersion
(
"0.0.1"
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid protocol version: %v"
,
err
))
}
}
//
CurrentHandshake
returns the current protocol version as a protobuf message
func
CurrentHandshake
()
*
Handshake1
{
return
NewHandshake1
(
currentVersion
.
String
(),
"go-ipfs/"
+
updates
.
Version
)
//
Handshake1Msg
returns the current protocol version as a protobuf message
func
Handshake1Msg
()
*
pb
.
Handshake1
{
return
NewHandshake1
(
ipfsVersion
.
String
(),
client
Version
)
}
// 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
//
Handshake1
Compatible checks wether two versions are compatible
// returns nil if they are fine
func
Compatible
(
handshakeA
,
handshakeB
*
Handshake1
)
error
{
func
Handshake1Compatible
(
handshakeA
,
handshakeB
*
pb
.
Handshake1
)
error
{
a
,
err
:=
semver
.
NewVersion
(
*
handshakeA
.
ProtocolVersion
)
if
err
!=
nil
{
return
err
...
...
@@ -48,8 +50,8 @@ func Compatible(handshakeA, handshakeB *Handshake1) error {
}
// NewHandshake1 creates a new Handshake1 from the two strings
func
NewHandshake1
(
protoVer
,
agentVer
string
)
*
Handshake1
{
return
&
Handshake1
{
func
NewHandshake1
(
protoVer
,
agentVer
string
)
*
pb
.
Handshake1
{
return
&
pb
.
Handshake1
{
ProtocolVersion
:
&
protoVer
,
AgentVersion
:
&
agentVer
,
}
...
...
net/handshake/
version
_test.go
→
net/handshake/
handshake1
_test.go
浏览文件 @
97c66ddc
...
...
@@ -2,7 +2,7 @@ package handshake
import
"testing"
func
TestCompatible
(
t
*
testing
.
T
)
{
func
Test
H1
Compatible
(
t
*
testing
.
T
)
{
tcases
:=
[]
struct
{
a
,
b
string
expected
error
...
...
@@ -16,7 +16,7 @@ func TestCompatible(t *testing.T) {
for
i
,
tcase
:=
range
tcases
{
if
Compatible
(
NewHandshake1
(
tcase
.
a
,
""
),
NewHandshake1
(
tcase
.
b
,
""
))
!=
tcase
.
expected
{
if
Handshake1
Compatible
(
NewHandshake1
(
tcase
.
a
,
""
),
NewHandshake1
(
tcase
.
b
,
""
))
!=
tcase
.
expected
{
t
.
Fatalf
(
"case[%d] failed"
,
i
)
}
}
...
...
net/handshake/pb/Makefile
0 → 100644
浏览文件 @
97c66ddc
PB
=
$
(
wildcard
*
.proto
)
GO
=
$
(
PB:.proto
=
.pb.go
)
all
:
$(GO)
%.pb.go
:
%.proto
protoc
--gogo_out
=
.
--proto_path
=
../../../../../../:/usr/local/opt/protobuf/include:.
$<
clean
:
rm
*
.pb.go
net/handshake/
semver
.pb.go
→
net/handshake/
pb/handshake
.pb.go
浏览文件 @
97c66ddc
// Code generated by protoc-gen-gogo.
// source:
semver
.proto
// source:
handshake
.proto
// DO NOT EDIT!
/*
Package handshake is a generated protocol buffer package.
Package handshake
_pb
is a generated protocol buffer package.
It is generated from these files:
semver
.proto
handshake
.proto
It has these top-level messages:
Handshake1
Handshake3
*/
package
handshake
package
handshake
_pb
import
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
proto
"code.google.com/p/gogoprotobuf/proto"
import
json
"encoding/json"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
// discarding unused import mux "github.com/jbenet/go-ipfs/net/mux/mux.pb"
// Reference proto, json, and math imports to suppress error if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
&
json
.
SyntaxError
{}
var
_
=
math
.
Inf
// Handshake1 is delivered _before_ the secure channel is initialized
type
Handshake1
struct
{
// protocolVersion determines compatibility between peers
ProtocolVersion
*
string
`protobuf:"bytes,1,opt,name=protocolVersion" json:"protocolVersion,omitempty"`
...
...
@@ -47,5 +53,23 @@ func (m *Handshake1) GetAgentVersion() string {
return
""
}
// Handshake3 is delivered _after_ the secure channel is initialized
type
Handshake3
struct
{
// listenAddrs are the multiaddrs this node listens for open connections on
ListenAddrs
[][]
byte
`protobuf:"bytes,2,rep,name=listenAddrs" json:"listenAddrs,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
Handshake3
)
Reset
()
{
*
m
=
Handshake3
{}
}
func
(
m
*
Handshake3
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Handshake3
)
ProtoMessage
()
{}
func
(
m
*
Handshake3
)
GetListenAddrs
()
[][]
byte
{
if
m
!=
nil
{
return
m
.
ListenAddrs
}
return
nil
}
func
init
()
{
}
net/handshake/
semver
.proto
→
net/handshake/
pb/handshake
.proto
浏览文件 @
97c66ddc
package
handshake
;
package
handshake
.
pb
;
import
"github.com/jbenet/go-ipfs/net/mux/mux.proto"
;
// Handshake1 is delivered _before_ the secure channel is initialized
message
Handshake1
{
// protocolVersion determines compatibility between peers
optional
string
protocolVersion
=
1
;
// semver
// protocolVersion determines compatibility between peers
optional
string
protocolVersion
=
1
;
// semver
// 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.
}
// Handshake3 is delivered _after_ the secure channel is initialized
message
Handshake3
{
// publicKey is this node's public key (which also gives its node.ID)
// - may not need to be sent, as secure channel implies it has been sent.
// - then again, if we change / disable secure channel, may still want it.
// optional bytes publicKey = 1;
// listenAddrs are the multiaddrs this node listens for open connections on
repeated
bytes
listenAddrs
=
2
;
// 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
// TODO
// services list the services this node is running
// repeated mux.ProtocolID services = 3;
// we'll have more fields here later.
// we'll have more fields here later.
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论