Skip to content

Commit

Permalink
Merge pull request #17 from 0chain/feat/enterprise-blobber
Browse files Browse the repository at this point in the history
Merge changes
  • Loading branch information
dabasov authored Dec 3, 2024
2 parents e8671f9 + d236c4a commit 6682df7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,10 @@ func downloadBlocks(allocId, remotePath, authTicket, lookupHash, writeChunkFuncN
fh = mf
defer sys.Files.Remove(pathHash) //nolint
} else {
fh = jsbridge.NewFileCallbackWriter(writeChunkFuncName)
fh = jsbridge.NewFileCallbackWriter(writeChunkFuncName, lookupHash)
if fh == nil {
return nil, fmt.Errorf("could not create file writer, callback function not found")
}
}

wg.Add(1)
Expand Down
11 changes: 8 additions & 3 deletions wasmsdk/jsbridge/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ type FileCallbackWriter struct {
writeChunk js.Value
buf []byte
offset int64
lookupHash string
}

const bufCallbackCap = 4 * 1024 * 1024 //4MB

func NewFileCallbackWriter(writeChunkFuncName string) *FileCallbackWriter {
func NewFileCallbackWriter(writeChunkFuncName, lookupHash string) *FileCallbackWriter {
writeChunk := js.Global().Get(writeChunkFuncName)
if !writeChunk.Truthy() {
return nil
}
return &FileCallbackWriter{
writeChunk: writeChunk,
lookupHash: lookupHash,
}
}

Expand All @@ -190,7 +195,7 @@ func (wc *FileCallbackWriter) Write(p []byte) (int, error) {
if len(wc.buf)+len(p) > cap(wc.buf) {
uint8Array := js.Global().Get("Uint8Array").New(len(wc.buf))
js.CopyBytesToJS(uint8Array, wc.buf)
_, err := Await(wc.writeChunk.Invoke(uint8Array, wc.offset))
_, err := Await(wc.writeChunk.Invoke(wc.lookupHash, uint8Array, wc.offset))
if len(err) > 0 && !err[0].IsNull() {
return 0, errors.New("file_writer: " + err[0].String())
}
Expand All @@ -205,7 +210,7 @@ func (wc *FileCallbackWriter) Close() error {
if len(wc.buf) > 0 {
uint8Array := js.Global().Get("Uint8Array").New(len(wc.buf))
js.CopyBytesToJS(uint8Array, wc.buf)
_, err := Await(wc.writeChunk.Invoke(uint8Array, wc.offset))
_, err := Await(wc.writeChunk.Invoke(wc.lookupHash, uint8Array, wc.offset))
if len(err) > 0 && !err[0].IsNull() {
return errors.New("file_writer: " + err[0].String())
}
Expand Down
5 changes: 5 additions & 0 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ type Allocation struct {

IsEnterprise bool `json:"is_enterprise"`

StorageVersion int `json:"storage_version"`

// Owner ecdsa public key
OwnerSigningPublicKey string `json:"owner_signing_public_key"`

// FileOptions to define file restrictions on an allocation for third-parties
// default 00000000 for all crud operations suggesting only owner has the below listed abilities.
// enabling option/s allows any third party to perform certain ops
Expand Down
2 changes: 1 addition & 1 deletion zboxcore/sdk/downloadworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func (req *DownloadRequest) processDownload() {
if startBlock+int64(j)*numBlocks+numBlocks > endBlock {
blocksToDownload = endBlock - (startBlock + int64(j)*numBlocks)
}
data, err := req.getBlocksData(startBlock+int64(j)*numBlocks, blocksToDownload, j == 0)
data, err := req.getBlocksData(startBlock+int64(j)*numBlocks, blocksToDownload, j == 0 && n > 1)
if req.isDownloadCanceled {
return errors.New("download_abort", "Download aborted by user")
}
Expand Down

0 comments on commit 6682df7

Please sign in to comment.