MCPcopy Create free account
hub / github.com/blobcache/blobcache / Get

Function Get

src/bcp/bcp.go:197–230  ·  view source on GitHub ↗
(ctx context.Context, tp Asker, ep blobcache.Endpoint, txh blobcache.Handle, hf blobcache.HashAlgo, cid blobcache.CID, salt *blobcache.CID, buf []byte)

Source from the content-addressed store, hash-verified

195}
196
197func Get(ctx context.Context, tp Asker, ep blobcache.Endpoint, txh blobcache.Handle, hf blobcache.HashAlgo, cid blobcache.CID, salt *blobcache.CID, buf []byte) (int, error) {
198 var body []byte
199 body = append(body, txh.OID[:]...)
200 body = append(body, txh.Secret[:]...)
201 var reqMsg Message
202 if salt != nil {
203 reqMsg.SetCode(MT_TX_GET_SALT)
204 body = append(body, salt[:]...)
205 } else {
206 reqMsg.SetCode(MT_TX_GET)
207 }
208 body = append(body, cid[:]...)
209 reqMsg.SetBody(body)
210
211 var respMsg Message
212 if err := tp.Ask(ctx, ep, reqMsg, &respMsg); err != nil {
213 return 0, err
214 }
215 if respMsg.Header().Code().IsError() {
216 return 0, parseWireError(respMsg.Header().Code(), respMsg.Body())
217 }
218 if !respMsg.Header().Code().IsOK() {
219 return 0, fmt.Errorf("reply message has non-OK code: %d", respMsg.Header().Code())
220 }
221 respBody := respMsg.Body()
222 if err := blobcache.CheckBlob(hf, salt, &cid, respBody); err != nil {
223 return 0, err
224 }
225 if len(respMsg.Body()) > len(buf) {
226 return 0, fmt.Errorf("buffer too short")
227 }
228 copy(buf, respMsg.Body())
229 return len(respMsg.Body()), nil
230}
231
232func Exists(ctx context.Context, tp Asker, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID, dst *blobcache.BitMap) error {
233 var resp ExistsResp

Callers 3

GetMethod · 0.92
GetMethod · 0.92
GetMethod · 0.92

Calls 10

SetCodeMethod · 0.95
SetBodyMethod · 0.95
HeaderMethod · 0.95
BodyMethod · 0.95
CheckBlobFunction · 0.92
parseWireErrorFunction · 0.85
IsErrorMethod · 0.80
CodeMethod · 0.80
IsOKMethod · 0.80
AskMethod · 0.65

Tested by

no test coverage detected