Skip to content

Commit 8060ee6

Browse files
committed
netbs: Address review
1 parent a47fdbb commit 8060ee6

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

blockstore/net.go

+23-18
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ import (
1919
type NetRPCReqType byte
2020

2121
const (
22-
NRpcHas NetRPCReqType = iota
23-
NRpcGet NetRPCReqType = iota
24-
NRpcGetSize NetRPCReqType = iota
25-
NRpcPut NetRPCReqType = iota
26-
NRpcDelete NetRPCReqType = iota
27-
NRpcList NetRPCReqType = iota
22+
NRpcHas NetRPCReqType = iota
23+
NRpcGet
24+
NRpcGetSize
25+
NRpcPut
26+
NRpcDelete
27+
NRpcList
2828

2929
// todo cancel req
3030
)
3131

3232
type NetRPCRespType byte
3333

3434
const (
35-
NRpcOK NetRPCRespType = iota
36-
NRpcErr NetRPCRespType = iota
37-
NRpcMore NetRPCRespType = iota
35+
NRpcOK NetRPCRespType = iota
36+
NRpcErr
37+
NRpcMore
3838
)
3939

4040
type NetRPCErrType byte
4141

4242
const (
43-
NRpcErrGeneric NetRPCErrType = iota
44-
NRpcErrNotFound NetRPCErrType = iota
43+
NRpcErrGeneric NetRPCErrType = iota
44+
NRpcErrNotFound
4545
)
4646

4747
type NetRpcReq struct {
@@ -87,7 +87,7 @@ type NetworkStore struct {
8787
closed chan struct{}
8888

8989
closeLk sync.Mutex
90-
onClose func()
90+
onClose []func()
9191
}
9292

9393
func NewNetworkStore(mss msgio.ReadWriteCloser) *NetworkStore {
@@ -143,7 +143,7 @@ func (n *NetworkStore) OnClose(cb func()) {
143143
case <-n.closed:
144144
cb()
145145
default:
146-
n.onClose = cb
146+
n.onClose = append(n.onClose, cb)
147147
}
148148
}
149149

@@ -154,7 +154,9 @@ func (n *NetworkStore) receive() {
154154

155155
close(n.closed)
156156
if n.onClose != nil {
157-
n.onClose()
157+
for _, f := range n.onClose {
158+
f()
159+
}
158160
}
159161
}()
160162

@@ -203,6 +205,7 @@ func (n *NetworkStore) sendRpc(rt NetRPCReqType, cids []cid.Cid, data [][]byte)
203205

204206
n.respLk.Lock()
205207
if n.respMap == nil {
208+
n.respLk.Unlock()
206209
return 0, nil, xerrors.Errorf("netstore closed")
207210
}
208211
n.respMap[rid] = respCh
@@ -218,22 +221,24 @@ func (n *NetworkStore) sendRpc(rt NetRPCReqType, cids []cid.Cid, data [][]byte)
218221
var rbuf bytes.Buffer // todo buffer pool
219222
if err := req.MarshalCBOR(&rbuf); err != nil {
220223
n.respLk.Lock()
224+
defer n.respLk.Unlock()
225+
221226
if n.respMap == nil {
222227
return 0, nil, xerrors.Errorf("netstore closed")
223228
}
224229
delete(n.respMap, rid)
225-
n.respLk.Unlock()
226230

227231
return 0, nil, err
228232
}
229233

230234
if err := n.msgStream.WriteMsg(rbuf.Bytes()); err != nil {
231235
n.respLk.Lock()
236+
defer n.respLk.Unlock()
237+
232238
if n.respMap == nil {
233239
return 0, nil, xerrors.Errorf("netstore closed")
234240
}
235241
delete(n.respMap, rid)
236-
n.respLk.Unlock()
237242

238243
return 0, nil, err
239244
}
@@ -260,10 +265,10 @@ func (n *NetworkStore) waitResp(ctx context.Context, rch <-chan NetRpcResp, rid
260265
} else {
261266
err = xerrors.Errorf("block not found, but cid was null")
262267
}
263-
default:
264-
err = xerrors.Errorf("unknown error type")
265268
case NRpcErrGeneric:
266269
err = xerrors.Errorf("generic error")
270+
default:
271+
err = xerrors.Errorf("unknown error type")
267272
}
268273

269274
return NetRpcResp{}, xerrors.Errorf("netstore error response: %s (%w)", e.Msg, err)

blockstore/net_serve.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type NetworkStoreHandler struct {
1919
bs Blockstore
2020
}
2121

22+
// NOTE: This code isn't yet hardened to accept untrusted input. See TODOs here and in net.go
2223
func HandleNetBstoreStream(ctx context.Context, bs Blockstore, mss msgio.ReadWriteCloser) *NetworkStoreHandler {
2324
ns := &NetworkStoreHandler{
2425
msgStream: mss,

node/impl/client/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ func (a *API) outputCAR(ctx context.Context, ds format.DAGService, bs bstore.Blo
10301030
root,
10311031
dagSpec.selector,
10321032
func(node format.Node) error {
1033+
// if we're exporting merkle proofs for this dag, export all nodes read by the traversal
10331034
if dagSpec.exportAll {
10341035
lk.Lock()
10351036
defer lk.Unlock()

0 commit comments

Comments
 (0)