Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f743c7ab
提交
f743c7ab
authored
9月 13, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(identify) pass context to handshake
上级
6f6d79d6
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
48 行增加
和
7 行删除
+48
-7
Godeps.json
Godeps/Godeps.json
+5
-0
context.go
...workspace/src/code.google.com/p/go.net/context/context.go
+0
-0
context_test.go
...pace/src/code.google.com/p/go.net/context/context_test.go
+0
-0
withtimeout_test.go
.../src/code.google.com/p/go.net/context/withtimeout_test.go
+26
-0
identify.go
identify/identify.go
+5
-3
identify_test.go
identify/identify_test.go
+5
-2
swarm.go
swarm/swarm.go
+7
-2
没有找到文件。
Godeps/Godeps.json
浏览文件 @
f743c7ab
...
...
@@ -20,6 +20,11 @@
"Rev"
:
"00a7d3b31bbab5795b4a51933c04fc2768242970"
},
{
"ImportPath"
:
"code.google.com/p/go.net/context"
,
"Comment"
:
"null-144"
,
"Rev"
:
"ad01a6fcc8a19d3a4478c836895ffe883bd2ceab"
},
{
"ImportPath"
:
"code.google.com/p/gogoprotobuf/proto"
,
"Rev"
:
"6c980277330804e94257ac7ef70a3adbe1641059"
},
...
...
Godeps/_workspace/src/code.google.com/p/go.net/context/context.go
0 → 100644
浏览文件 @
f743c7ab
差异被折叠。
点击展开。
Godeps/_workspace/src/code.google.com/p/go.net/context/context_test.go
0 → 100644
浏览文件 @
f743c7ab
差异被折叠。
点击展开。
Godeps/_workspace/src/code.google.com/p/go.net/context/withtimeout_test.go
0 → 100644
浏览文件 @
f743c7ab
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
context_test
import
(
"fmt"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
func
ExampleWithTimeout
()
{
// Pass a context with a timeout to tell a blocking function that it
// should abandon its work after the timeout elapses.
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
100
*
time
.
Millisecond
)
select
{
case
<-
time
.
After
(
200
*
time
.
Millisecond
)
:
fmt
.
Println
(
"overslept"
)
case
<-
ctx
.
Done
()
:
fmt
.
Println
(
ctx
.
Err
())
// prints "context deadline exceeded"
}
// Output:
// context deadline exceeded
}
identify/identify.go
浏览文件 @
f743c7ab
...
...
@@ -16,6 +16,8 @@ import (
"crypto/sha512"
"hash"
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"
ci
"github.com/jbenet/go-ipfs/crypto"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -33,7 +35,7 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type")
// Performs initial communication with this peer to share node ID's and
// initiate communication. (secureIn, secureOut, error)
func
Handshake
(
self
,
remote
*
peer
.
Peer
,
in
<-
chan
[]
byte
,
out
chan
<-
[]
byte
)
(
<-
chan
[]
byte
,
chan
<-
[]
byte
,
error
)
{
func
Handshake
(
ctx
context
.
Context
,
self
,
remote
*
peer
.
Peer
,
in
<-
chan
[]
byte
,
out
chan
<-
[]
byte
)
(
<-
chan
[]
byte
,
chan
<-
[]
byte
,
error
)
{
encodedHello
,
err
:=
encodedProtoHello
(
self
)
if
err
!=
nil
{
...
...
@@ -84,7 +86,7 @@ func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-
}
var
handshake
bytes
.
Buffer
// Gather corpus to sign.
handshake
.
Write
(
encoded
)
handshake
.
Write
(
encoded
Hello
)
handshake
.
Write
(
resp
)
handshake
.
Write
(
epubkey
)
...
...
@@ -118,7 +120,7 @@ func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-
if
err
!=
nil
{
return
nil
,
nil
,
err
}
_
,
err
=
theirHandshake
.
Write
(
encoded
)
_
,
err
=
theirHandshake
.
Write
(
encoded
Hello
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
identify/identify_test.go
浏览文件 @
f743c7ab
...
...
@@ -3,6 +3,8 @@ package identify
import
(
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ci
"github.com/jbenet/go-ipfs/crypto"
"github.com/jbenet/go-ipfs/peer"
)
...
...
@@ -40,14 +42,15 @@ func TestHandshake(t *testing.T) {
PrivKey
:
skb
,
}
ctx
:=
context
.
Background
()
go
func
()
{
_
,
_
,
err
:=
Handshake
(
pa
,
pb
,
cha
,
chb
)
_
,
_
,
err
:=
Handshake
(
ctx
,
pa
,
pb
,
cha
,
chb
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
_
,
_
,
err
=
Handshake
(
pb
,
pa
,
chb
,
cha
)
_
,
_
,
err
=
Handshake
(
ctx
,
pb
,
pa
,
chb
,
cha
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
swarm/swarm.go
浏览文件 @
f743c7ab
...
...
@@ -6,6 +6,8 @@ import (
"net"
"sync"
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"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ident
"github.com/jbenet/go-ipfs/identify"
...
...
@@ -162,6 +164,7 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
}
// Handle getting ID from this peer and adding it into the map
// TODO(brian): impl a cancellable context
func
(
s
*
Swarm
)
handleNewConn
(
nconn
net
.
Conn
)
{
p
:=
new
(
peer
.
Peer
)
...
...
@@ -172,7 +175,7 @@ func (s *Swarm) handleNewConn(nconn net.Conn) {
}
newConnChans
(
conn
)
sin
,
sout
,
err
:=
ident
.
Handshake
(
s
.
local
,
p
,
conn
.
Incoming
.
MsgChan
,
conn
.
Outgoing
.
MsgChan
)
sin
,
sout
,
err
:=
ident
.
Handshake
(
context
.
Background
(),
s
.
local
,
p
,
conn
.
Incoming
.
MsgChan
,
conn
.
Outgoing
.
MsgChan
)
if
err
!=
nil
{
u
.
PErr
(
"%v
\n
"
,
err
.
Error
())
conn
.
Close
()
...
...
@@ -426,8 +429,10 @@ func (s *Swarm) GetConnection(id peer.ID, addr *ma.Multiaddr) (*peer.Peer, error
}
// Handle performing a handshake on a new connection and ensuring proper forward communication
// TODO(brian): impl a cancellable context
func
(
s
*
Swarm
)
handleDialedCon
(
conn
*
Conn
)
error
{
sin
,
sout
,
err
:=
ident
.
Handshake
(
s
.
local
,
conn
.
Peer
,
conn
.
Incoming
.
MsgChan
,
conn
.
Outgoing
.
MsgChan
)
sin
,
sout
,
err
:=
ident
.
Handshake
(
context
.
Background
(),
s
.
local
,
conn
.
Peer
,
conn
.
Incoming
.
MsgChan
,
conn
.
Outgoing
.
MsgChan
)
if
err
!=
nil
{
return
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论