Skip to content

Commit

Permalink
Feat: offloading bandwidth to client side for Pull operations
Browse files Browse the repository at this point in the history
Signed-off-by: guacamole <[email protected]>
  • Loading branch information
guacamole committed Nov 21, 2021
1 parent d814435 commit 292433c
Showing 1 changed file with 12 additions and 43 deletions.
55 changes: 12 additions & 43 deletions registry/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,52 +551,21 @@ func (r *registry) PullLayer(ctx echo.Context) error {
}
}

if layerRef.Skylink == "" {
detail := map[string]interface{}{
"error": "skylink is empty",
}
e := fmt.Errorf("skylink is empty").Error()
errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, e, detail)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}

resp, err := r.skynet.Download(layerRef.Skylink)
if err != nil {
detail := map[string]interface{}{
"error": err.Error(),
}
errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, err.Error(), detail)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}

bz, err := io.ReadAll(resp)
if err != nil {
errMsg := r.errorResponse(RegistryErrorCodeBlobUploadInvalid, err.Error(), nil)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusInternalServerError, errMsg)
size, ok := r.skynet.Metadata(layerRef.Skylink)
if ok {
url := fmt.Sprintf("https://siasky.net/%s",strings.Replace(layerRef.Skylink,"sia://","",1))
ctx.Response().Header().Set("Content-Length", fmt.Sprintf("%d", size))
http.Redirect(ctx.Response(), ctx.Request(), url, http.StatusTemporaryRedirect)
return nil
}
_ = resp.Close()

dig := digest(bz)
if dig != clientDigest {
details := map[string]interface{}{
"clientDigest": clientDigest,
"computedDigest": dig,
}
errMsg := r.errorResponse(
RegistryErrorCodeBlobUploadUnknown,
"client digest is different than computed digest",
details,
)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
detail := map[string]interface{}{
"error": "skylink is empty",
}

ctx.Response().Header().Set("Content-Length", fmt.Sprintf("%d", len(bz)))
ctx.Response().Header().Set("Docker-Content-Digest", dig)
return ctx.Blob(http.StatusOK, "application/octet-stream", bz)
e := fmt.Errorf("skylink is empty").Error()
errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, e, detail)
ctx.Set(types.HttpEndpointErrorKey, errMsg)
return ctx.JSONBlob(http.StatusNotFound, errMsg)
}

//BlobMount to be implemented by guacamole at a later stage
Expand Down

0 comments on commit 292433c

Please sign in to comment.