make NewSession in the blockservice be a function, not a method
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 5, 2017 at 12:31 UTC
1ffb44cd46c89b33cf9f9beb1d4e34f6fb132ff9
2 files changed
+7
-8
blockservice/blockservice.go
+6
-7
@@ -32,7 +32,6 @@ type BlockService interface {
32
GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error)
33
GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
34
DeleteBlock(o blocks.Block) error
35
- NewSession(context.Context) *Session
35
Close() error
36
}
37
@@ -79,18 +78,18 @@ func (bs *blockService) Exchange() exchange.Interface {
78
return bs.exchange
79
}
80
82
-func (bs *blockService) NewSession(ctx context.Context) *Session {
83
- bswap, ok := bs.Exchange().(*bitswap.Bitswap)
84
- if ok {
81
+func NewSession(ctx context.Context, bs BlockService) *Session {
82
+ exchange := bs.Exchange()
83
+ if bswap, ok := exchange.(*bitswap.Bitswap); ok {
84
ses := bswap.NewSession(ctx)
85
return &Session{
86
ses: ses,
88
- bs: bs.blockstore,
87
+ bs: bs.Blockstore(),
88
}
89
}
90
return &Session{
92
- ses: bs.exchange,
93
- bs: bs.blockstore,
91
+ ses: exchange,
92
+ bs: bs.Blockstore(),
93
}
94
}
95
merkledag/merkledag.go
+1
-1
@@ -182,7 +182,7 @@ func FetchGraph(ctx context.Context, root *cid.Cid, serv DAGService) error {
182
var ng node.NodeGetter = serv
183
ds, ok := serv.(*dagService)
184
if ok {
185
- ng = &sesGetter{ds.Blocks.NewSession(ctx)}
185
+ ng = &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
186
}
187
188
v, _ := ctx.Value("progress").(*ProgressTracker)