Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
de9fcf5d
提交
de9fcf5d
authored
9月 18, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
style(bitswap) rename strategist -> strategy
上级
b7806947
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
17 行增加
和
17 行删除
+17
-17
bitswap.go
bitswap/bitswap.go
+11
-11
interface.go
bitswap/strategy/interface.go
+3
-3
strategy.go
bitswap/strategy/strategy.go
+3
-3
没有找到文件。
bitswap/bitswap.go
浏览文件 @
de9fcf5d
...
...
@@ -41,10 +41,10 @@ type bitswap struct {
notifications
notifications
.
PubSub
// strateg
ist
listens to network traffic and makes decisions about how to
// strateg
y
listens to network traffic and makes decisions about how to
// interact with partners.
// TODO(brian): save the strateg
ist
's state to the datastore
strateg
ist
strategy
.
Strategist
// TODO(brian): save the strateg
y
's state to the datastore
strateg
y
strategy
.
Strategy
}
// NewSession initializes a bitswap session.
...
...
@@ -55,7 +55,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
bs
:=
&
bitswap
{
blockstore
:
blockstore
.
NewBlockstore
(
d
),
notifications
:
notifications
.
New
(),
strateg
ist
:
strategy
.
New
(),
strateg
y
:
strategy
.
New
(),
peer
:
p
,
routing
:
directory
,
sender
:
bsnet
.
NewNetworkAdapter
(
s
,
&
receiver
),
...
...
@@ -112,7 +112,7 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
// that accounting is _always_ performed when SendMessage and
// ReceiveMessage are called
bs
.
sender
.
SendMessage
(
ctx
,
p
,
message
)
bs
.
strateg
ist
.
MessageSent
(
p
,
message
)
bs
.
strateg
y
.
MessageSent
(
p
,
message
)
block
,
ok
:=
<-
blockChannel
if
!
ok
{
...
...
@@ -122,9 +122,9 @@ func (bs *bitswap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
}
func
(
bs
*
bitswap
)
sendToPeersThatWant
(
block
blocks
.
Block
)
{
for
_
,
p
:=
range
bs
.
strateg
ist
.
Peers
()
{
if
bs
.
strateg
ist
.
IsWantedByPeer
(
block
.
Key
(),
p
)
{
if
bs
.
strateg
ist
.
ShouldSend
ToPeer
(
block
.
Key
(),
p
)
{
for
_
,
p
:=
range
bs
.
strateg
y
.
Peers
()
{
if
bs
.
strateg
y
.
Block
IsWantedByPeer
(
block
.
Key
(),
p
)
{
if
bs
.
strateg
y
.
ShouldSendBlock
ToPeer
(
block
.
Key
(),
p
)
{
go
bs
.
send
(
p
,
block
)
}
}
...
...
@@ -144,7 +144,7 @@ func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message
.
AppendBlock
(
b
)
// FIXME(brian): pass ctx
bs
.
sender
.
SendMessage
(
context
.
Background
(),
p
,
message
)
bs
.
strateg
ist
.
MessageSent
(
p
,
message
)
bs
.
strateg
y
.
MessageSent
(
p
,
message
)
}
// TODO(brian): handle errors
...
...
@@ -152,7 +152,7 @@ func (bs *bitswap) ReceiveMessage(
ctx
context
.
Context
,
sender
*
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
*
peer
.
Peer
,
bsmsg
.
BitSwapMessage
,
error
)
{
bs
.
strateg
ist
.
MessageReceived
(
sender
,
incoming
)
bs
.
strateg
y
.
MessageReceived
(
sender
,
incoming
)
if
incoming
.
Blocks
()
!=
nil
{
for
_
,
block
:=
range
incoming
.
Blocks
()
{
...
...
@@ -163,7 +163,7 @@ func (bs *bitswap) ReceiveMessage(
if
incoming
.
Wantlist
()
!=
nil
{
for
_
,
key
:=
range
incoming
.
Wantlist
()
{
if
bs
.
strateg
ist
.
ShouldSend
ToPeer
(
key
,
sender
)
{
if
bs
.
strateg
y
.
ShouldSendBlock
ToPeer
(
key
,
sender
)
{
block
,
errBlockNotFound
:=
bs
.
blockstore
.
Get
(
key
)
if
errBlockNotFound
!=
nil
{
// TODO(brian): log/return the error
...
...
bitswap/strategy/interface.go
浏览文件 @
de9fcf5d
...
...
@@ -6,17 +6,17 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
type
Strateg
ist
interface
{
type
Strateg
y
interface
{
Accountant
// Returns a slice of Peers that
Peers
()
[]
*
peer
.
Peer
// WantList returns the WantList for the given Peer
IsWantedByPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
Block
IsWantedByPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
// ShouldSendTo(Peer) decides whether to send data to this Peer
ShouldSendToPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
ShouldSend
Block
ToPeer
(
u
.
Key
,
*
peer
.
Peer
)
bool
// Seed initializes the decider to a deterministic state
Seed
(
int64
)
...
...
bitswap/strategy/strategy.go
浏览文件 @
de9fcf5d
...
...
@@ -9,7 +9,7 @@ import (
)
// TODO declare thread-safe datastore
func
New
()
Strateg
ist
{
func
New
()
Strateg
y
{
return
&
strategist
{
ledgerMap
:
ledgerMap
{},
strategyFunc
:
yesManStrategy
,
...
...
@@ -36,12 +36,12 @@ func (s *strategist) Peers() []*peer.Peer {
return
response
}
func
(
s
*
strategist
)
IsWantedByPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
func
(
s
*
strategist
)
Block
IsWantedByPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
ledger
:=
s
.
ledger
(
p
)
return
ledger
.
WantListContains
(
k
)
}
func
(
s
*
strategist
)
ShouldSendToPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
func
(
s
*
strategist
)
ShouldSend
Block
ToPeer
(
k
u
.
Key
,
p
*
peer
.
Peer
)
bool
{
ledger
:=
s
.
ledger
(
p
)
return
ledger
.
ShouldSend
()
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论