@@ -51,14 +51,14 @@ type BlockService interface {
51
51
Exchange () exchange.Interface
52
52
53
53
// AddBlock puts a given block to the underlying datastore
54
- AddBlock (o blocks.Block ) error
54
+ AddBlock (ctx context. Context , o blocks.Block ) error
55
55
56
56
// AddBlocks adds a slice of blocks at the same time using batching
57
57
// capabilities of the underlying datastore whenever possible.
58
- AddBlocks (bs []blocks.Block ) error
58
+ AddBlocks (ctx context. Context , bs []blocks.Block ) error
59
59
60
60
// DeleteBlock deletes the given block from the blockservice.
61
- DeleteBlock (o cid.Cid ) error
61
+ DeleteBlock (ctx context. Context , o cid.Cid ) error
62
62
}
63
63
64
64
type blockService struct {
@@ -130,35 +130,35 @@ func NewSession(ctx context.Context, bs BlockService) *Session {
130
130
131
131
// AddBlock adds a particular block to the service, Putting it into the datastore.
132
132
// TODO pass a context into this if the remote.HasBlock is going to remain here.
133
- func (s * blockService ) AddBlock (o blocks.Block ) error {
133
+ func (s * blockService ) AddBlock (ctx context. Context , o blocks.Block ) error {
134
134
c := o .Cid ()
135
135
// hash security
136
136
err := verifcid .ValidateCid (c )
137
137
if err != nil {
138
138
return err
139
139
}
140
140
if s .checkFirst {
141
- if has , err := s .blockstore .Has (c ); has || err != nil {
141
+ if has , err := s .blockstore .Has (ctx , c ); has || err != nil {
142
142
return err
143
143
}
144
144
}
145
145
146
- if err := s .blockstore .Put (o ); err != nil {
146
+ if err := s .blockstore .Put (ctx , o ); err != nil {
147
147
return err
148
148
}
149
149
150
150
log .Debugf ("BlockService.BlockAdded %s" , c )
151
151
152
152
if s .exchange != nil {
153
- if err := s .exchange .HasBlock (o ); err != nil {
153
+ if err := s .exchange .HasBlock (ctx , o ); err != nil {
154
154
log .Errorf ("HasBlock: %s" , err .Error ())
155
155
}
156
156
}
157
157
158
158
return nil
159
159
}
160
160
161
- func (s * blockService ) AddBlocks (bs []blocks.Block ) error {
161
+ func (s * blockService ) AddBlocks (ctx context. Context , bs []blocks.Block ) error {
162
162
// hash security
163
163
for _ , b := range bs {
164
164
err := verifcid .ValidateCid (b .Cid ())
@@ -170,7 +170,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
170
170
if s .checkFirst {
171
171
toput = make ([]blocks.Block , 0 , len (bs ))
172
172
for _ , b := range bs {
173
- has , err := s .blockstore .Has (b .Cid ())
173
+ has , err := s .blockstore .Has (ctx , b .Cid ())
174
174
if err != nil {
175
175
return err
176
176
}
@@ -186,15 +186,15 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
186
186
return nil
187
187
}
188
188
189
- err := s .blockstore .PutMany (toput )
189
+ err := s .blockstore .PutMany (ctx , toput )
190
190
if err != nil {
191
191
return err
192
192
}
193
193
194
194
if s .exchange != nil {
195
195
for _ , o := range toput {
196
196
log .Debugf ("BlockService.BlockAdded %s" , o .Cid ())
197
- if err := s .exchange .HasBlock (o ); err != nil {
197
+ if err := s .exchange .HasBlock (ctx , o ); err != nil {
198
198
log .Errorf ("HasBlock: %s" , err .Error ())
199
199
}
200
200
}
@@ -225,7 +225,7 @@ func getBlock(ctx context.Context, c cid.Cid, bs blockstore.Blockstore, fget fun
225
225
return nil , err
226
226
}
227
227
228
- block , err := bs .Get (c )
228
+ block , err := bs .Get (ctx , c )
229
229
if err == nil {
230
230
return block , nil
231
231
}
@@ -296,7 +296,7 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
296
296
297
297
var misses []cid.Cid
298
298
for _ , c := range ks {
299
- hit , err := bs .Get (c )
299
+ hit , err := bs .Get (ctx , c )
300
300
if err != nil {
301
301
misses = append (misses , c )
302
302
continue
@@ -332,8 +332,8 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
332
332
}
333
333
334
334
// DeleteBlock deletes a block in the blockservice from the datastore
335
- func (s * blockService ) DeleteBlock (c cid.Cid ) error {
336
- err := s .blockstore .DeleteBlock (c )
335
+ func (s * blockService ) DeleteBlock (ctx context. Context , c cid.Cid ) error {
336
+ err := s .blockstore .DeleteBlock (ctx , c )
337
337
if err == nil {
338
338
log .Debugf ("BlockService.BlockDeleted %s" , c )
339
339
}
0 commit comments