| 195 | } |
| 196 | |
| 197 | func 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 | |
| 232 | func Exists(ctx context.Context, tp Asker, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID, dst *blobcache.BitMap) error { |
| 233 | var resp ExistsResp |