Bugfix for larger manifests
This commit is contained in:
parent
9bff4cef26
commit
5ba1410a3b
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue