Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre download #1182

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zboxcore/fileref/fileref.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type FileRef struct {
ActualThumbnailHash string `json:"actual_thumbnail_hash" mapstructure:"actual_thumbnail_hash"`
MimeType string `json:"mimetype" mapstructure:"mimetype"`
EncryptedKey string `json:"encrypted_key" mapstructure:"encrypted_key"`
EncryptedKeyPoint string `json:"encrypted_key_point" mapstructure:"encrypted_key_point"`
Collaborators []Collaborator `json:"collaborators" mapstructure:"collaborators"`
}

Expand Down
2 changes: 1 addition & 1 deletion zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (a *Allocation) RepairFile(file sys.File, remotepath string,
WithChunkNumber(10),
WithStatusCallback(status),
WithEncrypt(true),
WithEncryptedPoint(ref.EncryptedKey),
WithEncryptedPoint(ref.EncryptedKeyPoint),
}
} else {
opts = []ChunkedUploadOption{
Expand Down
13 changes: 4 additions & 9 deletions zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ type ChunkedUpload struct {
ctxCncl context.CancelFunc
addConsensus int32
encryptedKeyPoint string
encryptedKey string
}

// progressID build local progress id with [allocationid]_[Hash(LocalPath+"_"+RemotePath)]_[RemoteName] format
Expand Down Expand Up @@ -432,7 +433,7 @@ func (su *ChunkedUpload) createEncscheme() encryption.EncryptionScheme {
encscheme.InitForEncryption("filetype:audio")
su.progress.EncryptedKeyPoint = encscheme.GetEncryptedKeyPoint()
}

su.encryptedKey = encscheme.GetEncryptedKey()
return encscheme
}

Expand Down Expand Up @@ -632,12 +633,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,

ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

encryptedKey := ""
if su.fileEncscheme != nil {
encryptedKey = su.progress.EncryptedKeyPoint
}

var errCount int32

wgErrors := make(chan error, len(su.blobbers))
Expand All @@ -663,7 +658,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,
defer wg.Done()
body, formData, err := su.formBuilder.Build(
&su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID,
su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, encryptedKey,
su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint,
fileShards[pos], thumbnailChunkData, su.shardSize)
if err != nil {
errC := atomic.AddInt32(&errCount, 1)
Expand All @@ -673,7 +668,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int,
return
}

err = b.sendUploadRequest(ctx, su, chunkEndIndex, isFinal, encryptedKey, body, formData, pos)
err = b.sendUploadRequest(ctx, su, chunkEndIndex, isFinal, su.encryptedKey, body, formData, pos)
if err != nil {
if strings.Contains(err.Error(), "duplicate") {
atomic.AddInt32(&su.addConsensus, 1)
Expand Down
20 changes: 10 additions & 10 deletions zboxcore/sdk/chunked_upload_form_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ChunkedUploadFormBuilder interface {
Build(
fileMeta *FileMeta, hasher Hasher, connectionID string,
chunkSize int64, chunkStartIndex, chunkEndIndex int,
isFinal bool, encryptedKey string, fileChunksData [][]byte,
isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte,
thumbnailChunkData []byte, shardSize int64,
) (*bytes.Buffer, ChunkedUploadFormMetadata, error)
}
Expand All @@ -47,7 +47,7 @@ type chunkedUploadFormBuilder struct {
func (b *chunkedUploadFormBuilder) Build(
fileMeta *FileMeta, hasher Hasher, connectionID string,
chunkSize int64, chunkStartIndex, chunkEndIndex int,
isFinal bool, encryptedKey string, fileChunksData [][]byte,
isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte,
thumbnailChunkData []byte, shardSize int64,
) (*bytes.Buffer, ChunkedUploadFormMetadata, error) {

Expand All @@ -73,12 +73,14 @@ func (b *chunkedUploadFormBuilder) Build(

MimeType: fileMeta.MimeType,

IsFinal: isFinal,
ChunkSize: chunkSize,
ChunkStartIndex: chunkStartIndex,
ChunkEndIndex: chunkEndIndex,
UploadOffset: chunkSize * int64(chunkStartIndex),
Size: shardSize,
IsFinal: isFinal,
ChunkSize: chunkSize,
ChunkStartIndex: chunkStartIndex,
ChunkEndIndex: chunkEndIndex,
UploadOffset: chunkSize * int64(chunkStartIndex),
Size: shardSize,
EncryptedKeyPoint: encryptedKeyPoint,
EncryptedKey: encryptedKey,
}

formWriter := multipart.NewWriter(body)
Expand Down Expand Up @@ -180,8 +182,6 @@ func (b *chunkedUploadFormBuilder) Build(

}

formData.EncryptedKey = encryptedKey

err = formWriter.WriteField("connection_id", connectionID)
if err != nil {
return nil, metadata, err
Expand Down
2 changes: 1 addition & 1 deletion zboxcore/sdk/chunked_upload_form_builder_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func BenchmarkChunkedUploadFormBuilder(b *testing.B) {

fileBytes := buf[begin:end]

_, _, err := builder.Build(fileMeta, hasher, "connectionID", int64(bm.ChunkSize), chunkIndex, chunkIndex, isFinal, "", [][]byte{fileBytes}, nil, getShardSize(fileMeta.ActualSize, 1, false))
_, _, err := builder.Build(fileMeta, hasher, "connectionID", int64(bm.ChunkSize), chunkIndex, chunkIndex, isFinal, "", "", [][]byte{fileBytes}, nil, getShardSize(fileMeta.ActualSize, 1, false))
if err != nil {
b.Fatal(err)
return
Expand Down
7 changes: 4 additions & 3 deletions zboxcore/sdk/chunked_upload_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ type UploadFormData struct {
// ActualThumbnailHash hash of original thumbnail (un-encoded, un-encrypted)
ActualThumbHash string `json:"actual_thumb_hash,omitempty"`

MimeType string `json:"mimetype,omitempty"`
CustomMeta string `json:"custom_meta,omitempty"`
EncryptedKey string `json:"encrypted_key,omitempty"`
MimeType string `json:"mimetype,omitempty"`
CustomMeta string `json:"custom_meta,omitempty"`
EncryptedKey string `json:"encrypted_key,omitempty"`
EncryptedKeyPoint string `json:"encrypted_key_point,omitempty"`

IsFinal bool `json:"is_final,omitempty"` // all of chunks are uploaded
ChunkStartIndex int `json:"chunk_start_index,omitempty"` // start index of chunks.
Expand Down
2 changes: 1 addition & 1 deletion zboxcore/sdk/downloadworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func (req *DownloadRequest) initEncryption() (err error) {
}
}

err = req.encScheme.InitForDecryptionWithPoint("filetype:audio", req.encryptedKey)
err = req.encScheme.InitForDecryption("filetype:audio", req.encryptedKey)
if err != nil {
return err
}
Expand Down
Loading