-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable fast integrity check on bundle
- Loading branch information
1 parent
873152e
commit 0b40d8b
Showing
9 changed files
with
441 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package cmn | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const getObjectPath = "/greenfield/storage/head_object/%s/%s" // bucketName, objectName | ||
|
||
type ChainClient struct { | ||
hc *http.Client | ||
host string | ||
} | ||
|
||
func NewChainClient(host string) (*ChainClient, error) { | ||
transport := &http.Transport{ | ||
DisableCompression: true, | ||
MaxIdleConnsPerHost: 1000, | ||
MaxConnsPerHost: 1000, | ||
IdleConnTimeout: 90 * time.Second, | ||
} | ||
client := &http.Client{ | ||
Timeout: 10 * time.Minute, | ||
Transport: transport, | ||
} | ||
return &ChainClient{hc: client, host: host}, nil | ||
} | ||
|
||
func (c *ChainClient) GetObjectMeta(ctx context.Context, bucketName, objectName string) (*ObjectInfo, error) { | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.host+fmt.Sprintf(getObjectPath, bucketName, objectName), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := c.hc.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("received non-OK response status: %s", resp.Status) | ||
} | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
getObjectResp := GetObjectInfoResponse{} | ||
err = json.Unmarshal(body, &getObjectResp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &getObjectResp.ObjectInfo, nil | ||
} | ||
|
||
func (c *ChainClient) GetParams(ctx context.Context) (*VersionedParams, error) { | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.host+"/greenfield/storage/params", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := c.hc.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
getParamsResp := GetParamsResponse{} | ||
err = json.Unmarshal(body, &getParamsResp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &getParamsResp.Params.VersionedParams, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.