Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
59858540
提交
59858540
authored
1月 19, 2015
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: return pointer
@whyrusleeping
上级
60e288ed
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
9 行增加
和
6 行删除
+9
-6
bitswap.go
exchange/bitswap/bitswap.go
+4
-1
engine.go
exchange/bitswap/decision/engine.go
+5
-5
没有找到文件。
exchange/bitswap/bitswap.go
浏览文件 @
59858540
...
@@ -281,7 +281,10 @@ func (bs *bitswap) taskWorker(ctx context.Context) {
...
@@ -281,7 +281,10 @@ func (bs *bitswap) taskWorker(ctx context.Context) {
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
case
envelope
:=
<-
nextEnvelope
:
case
envelope
,
ok
:=
<-
nextEnvelope
:
if
!
ok
{
continue
}
bs
.
send
(
ctx
,
envelope
.
Peer
,
envelope
.
Message
)
bs
.
send
(
ctx
,
envelope
.
Peer
,
envelope
.
Message
)
}
}
}
}
...
...
exchange/bitswap/decision/engine.go
浏览文件 @
59858540
...
@@ -71,7 +71,7 @@ type Engine struct {
...
@@ -71,7 +71,7 @@ type Engine struct {
// outbox contains outgoing messages to peers. This is owned by the
// outbox contains outgoing messages to peers. This is owned by the
// taskWorker goroutine
// taskWorker goroutine
outbox
chan
(
<-
chan
Envelope
)
outbox
chan
(
<-
chan
*
Envelope
)
bs
bstore
.
Blockstore
bs
bstore
.
Blockstore
...
@@ -85,7 +85,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
...
@@ -85,7 +85,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
ledgerMap
:
make
(
map
[
peer
.
ID
]
*
ledger
),
ledgerMap
:
make
(
map
[
peer
.
ID
]
*
ledger
),
bs
:
bs
,
bs
:
bs
,
peerRequestQueue
:
newPRQ
(),
peerRequestQueue
:
newPRQ
(),
outbox
:
make
(
chan
(
<-
chan
Envelope
),
outboxChanBuffer
),
outbox
:
make
(
chan
(
<-
chan
*
Envelope
),
outboxChanBuffer
),
workSignal
:
make
(
chan
struct
{}),
workSignal
:
make
(
chan
struct
{}),
}
}
go
e
.
taskWorker
(
ctx
)
go
e
.
taskWorker
(
ctx
)
...
@@ -95,7 +95,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
...
@@ -95,7 +95,7 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
func
(
e
*
Engine
)
taskWorker
(
ctx
context
.
Context
)
{
func
(
e
*
Engine
)
taskWorker
(
ctx
context
.
Context
)
{
defer
close
(
e
.
outbox
)
// because taskWorker uses the channel exclusively
defer
close
(
e
.
outbox
)
// because taskWorker uses the channel exclusively
for
{
for
{
oneTimeUse
:=
make
(
chan
Envelope
,
1
)
// buffer to prevent blocking
oneTimeUse
:=
make
(
chan
*
Envelope
,
1
)
// buffer to prevent blocking
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
...
@@ -108,7 +108,7 @@ func (e *Engine) taskWorker(ctx context.Context) {
...
@@ -108,7 +108,7 @@ func (e *Engine) taskWorker(ctx context.Context) {
close
(
oneTimeUse
)
close
(
oneTimeUse
)
return
// ctx cancelled
return
// ctx cancelled
}
}
oneTimeUse
<-
*
envelope
// buffered. won't block
oneTimeUse
<-
envelope
// buffered. won't block
close
(
oneTimeUse
)
close
(
oneTimeUse
)
}
}
}
}
...
@@ -141,7 +141,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
...
@@ -141,7 +141,7 @@ func (e *Engine) nextEnvelope(ctx context.Context) (*Envelope, error) {
}
}
// Outbox returns a channel of one-time use Envelope channels.
// Outbox returns a channel of one-time use Envelope channels.
func
(
e
*
Engine
)
Outbox
()
<-
chan
(
<-
chan
Envelope
)
{
func
(
e
*
Engine
)
Outbox
()
<-
chan
(
<-
chan
*
Envelope
)
{
return
e
.
outbox
return
e
.
outbox
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论