(ctx context.Context, bc blobcache.Service, u blobcache.URL)
| 60 | } |
| 61 | |
| 62 | func OpenURL(ctx context.Context, bc blobcache.Service, u blobcache.URL) (*blobcache.Handle, error) { |
| 63 | localEP, err := bc.Endpoint(ctx) |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | if localEP.Node == u.Node { |
| 68 | volh, err := bc.OpenFiat(ctx, u.OID, blobcache.Action_ALL) |
| 69 | if err != nil { |
| 70 | return nil, err |
| 71 | } |
| 72 | return volh, nil |
| 73 | } else { |
| 74 | // The Volume is not on the local peer. |
| 75 | // check if the URL has an IP and port. |
| 76 | if ep := u.Endpoint(); ep != nil { |
| 77 | return bc.CreateVolume(ctx, nil, blobcache.VolumeSpec{ |
| 78 | Remote: &blobcache.VolumeBackend_Remote{ |
| 79 | Endpoint: *ep, |
| 80 | Volume: u.OID, |
| 81 | HashAlgo: "", |
| 82 | }, |
| 83 | }) |
| 84 | } else { |
| 85 | // there was no IP and port, so we create a Peer Volume instead. |
| 86 | return bc.CreateVolume(ctx, nil, blobcache.VolumeSpec{ |
| 87 | Peer: &blobcache.VolumeBackend_Peer{ |
| 88 | Peer: u.Node, |
| 89 | Volume: u.OID, |
| 90 | HashAlgo: "", |
| 91 | }, |
| 92 | }) |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // URLFor produces a URL for a Volume. |
| 98 | // If the Volume is a remote Volume than the OID of the Volume on the remote Node |
no test coverage detected