Bugfix for larger manifests
continuous-integration/drone/pr Build is pending Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-09-02 16:55:47 -07:00
parent 9bff4cef26
commit 5ba1410a3b
3 changed files with 6 additions and 4 deletions

View File

@ -77,12 +77,14 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, handl
wrapperJSON, _ := json.Marshal(wrapper)
key := fmt.Sprintf("%x.%x", manifest.RootHash, nonce)
serializedManifest, _ := json.Marshal(manifest)
profile.ShareFile(key, string(serializedManifest))
// Store the size of the manifest (in chunks) as part of the public scope so contacts who we share the file with
// can fetch the manifest as if it were a file.
profile.SetAttribute(attr.GetPublicScope(fmt.Sprintf("%s.manifest.size", key)), strconv.Itoa(int(math.Ceil(float64(len(serializedManifest))/float64(files.DefaultChunkSize)))))
profile.ShareFile(key, string(serializedManifest))
profile.SendMessageToPeer(handle, string(wrapperJSON))
return nil

View File

@ -80,8 +80,8 @@ func (fsss *FileSharingSubSystem) RequestManifestParts(fileKey string) []model.P
serializedManifest := manifest.Serialize()
log.Debugf("found serialized manifest: %s", serializedManifest)
for i := 0; i < len(serializedManifest); i += DefaultChunkSize {
offset := i * DefaultChunkSize
end := (i + 1) * DefaultChunkSize
offset := i
end := (i + 1) + DefaultChunkSize
// truncate end
if end > len(serializedManifest) {
end = len(serializedManifest)

View File

@ -108,7 +108,7 @@ func TestFileSharing(t *testing.T) {
err := json.Unmarshal([]byte(messageWrapper.Data), &fileMessageOverlay)
if err == nil {
filesharingFunctionality.DownloadFile(bob, alice.GetOnion(), "cwtch.out.png", fmt.Sprintf("%x.%x", fileMessageOverlay.Hash, fileMessageOverlay.Nonce))
filesharingFunctionality.DownloadFile(bob, alice.GetOnion(), "cwtch.out.png", fmt.Sprintf("%s.%s", fileMessageOverlay.Hash, fileMessageOverlay.Nonce))
}
}