提交 ad14d6c5 作者: Brian Tiger Chow

refac(bitswap:interface) GetBlock, HaveBlock -> Block, HasBlock

上级 d91955b4
...@@ -85,7 +85,7 @@ func NewSession(parent context.Context, p *peer.Peer, d ds.Datastore, r routing. ...@@ -85,7 +85,7 @@ func NewSession(parent context.Context, p *peer.Peer, d ds.Datastore, r routing.
} }
// GetBlock attempts to retrieve a particular block from peers, within timeout. // GetBlock attempts to retrieve a particular block from peers, within timeout.
func (bs *BitSwap) GetBlock(k u.Key, timeout time.Duration) ( func (bs *BitSwap) Block(k u.Key, timeout time.Duration) (
*blocks.Block, error) { *blocks.Block, error) {
u.DOut("Bitswap GetBlock: '%s'\n", k.Pretty()) u.DOut("Bitswap GetBlock: '%s'\n", k.Pretty())
begin := time.Now() begin := time.Now()
...@@ -139,9 +139,9 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc ...@@ -139,9 +139,9 @@ func (bs *BitSwap) getBlock(k u.Key, p *peer.Peer, timeout time.Duration) (*bloc
return &block, nil return &block, nil
} }
// HaveBlock announces the existance of a block to BitSwap, potentially sending // HasBlock announces the existance of a block to BitSwap, potentially sending
// it to peers (Partners) whose WantLists include it. // it to peers (Partners) whose WantLists include it.
func (bs *BitSwap) HaveBlock(blk *blocks.Block) error { func (bs *BitSwap) HasBlock(blk *blocks.Block) error {
go func() { go func() {
for _, ledger := range bs.partners { for _, ledger := range bs.partners {
if ledger.WantListContains(blk.Key()) { if ledger.WantListContains(blk.Key()) {
......
...@@ -11,13 +11,12 @@ type Exchange interface { ...@@ -11,13 +11,12 @@ type Exchange interface {
// Block returns the block associated with a given key. // Block returns the block associated with a given key.
// TODO(brian): pass a context instead of a timeout // TODO(brian): pass a context instead of a timeout
// TODO(brian): rename -> Block Block(k u.Key, timeout time.Duration) (*blocks.Block, error)
GetBlock(k u.Key, timeout time.Duration) (*blocks.Block, error)
// HasBlock asserts the existence of this block // HasBlock asserts the existence of this block
// TODO(brian): rename -> HasBlock // TODO(brian): rename -> HasBlock
// TODO(brian): accept a value, not a pointer // TODO(brian): accept a value, not a pointer
// TODO(brian): remove error return value. Should callers be concerned with // TODO(brian): remove error return value. Should callers be concerned with
// whether the block was made available on the network? // whether the block was made available on the network?
HaveBlock(*blocks.Block) error HasBlock(*blocks.Block) error
} }
...@@ -42,7 +42,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) { ...@@ -42,7 +42,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
return k, err return k, err
} }
if s.Remote != nil { if s.Remote != nil {
err = s.Remote.HaveBlock(b) err = s.Remote.HasBlock(b)
} }
return k, err return k, err
} }
...@@ -65,7 +65,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) { ...@@ -65,7 +65,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
}, nil }, nil
} else if err == ds.ErrNotFound && s.Remote != nil { } else if err == ds.ErrNotFound && s.Remote != nil {
u.DOut("Blockservice: Searching bitswap.\n") u.DOut("Blockservice: Searching bitswap.\n")
blk, err := s.Remote.GetBlock(k, time.Second*5) blk, err := s.Remote.Block(k, time.Second*5)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论