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)
|
wrapperJSON, _ := json.Marshal(wrapper)
|
||||||
key := fmt.Sprintf("%x.%x", manifest.RootHash, nonce)
|
key := fmt.Sprintf("%x.%x", manifest.RootHash, nonce)
|
||||||
serializedManifest, _ := json.Marshal(manifest)
|
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
|
// 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.
|
// 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.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))
|
profile.SendMessageToPeer(handle, string(wrapperJSON))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -80,8 +80,8 @@ func (fsss *FileSharingSubSystem) RequestManifestParts(fileKey string) []model.P
|
||||||
serializedManifest := manifest.Serialize()
|
serializedManifest := manifest.Serialize()
|
||||||
log.Debugf("found serialized manifest: %s", serializedManifest)
|
log.Debugf("found serialized manifest: %s", serializedManifest)
|
||||||
for i := 0; i < len(serializedManifest); i += DefaultChunkSize {
|
for i := 0; i < len(serializedManifest); i += DefaultChunkSize {
|
||||||
offset := i * DefaultChunkSize
|
offset := i
|
||||||
end := (i + 1) * DefaultChunkSize
|
end := (i + 1) + DefaultChunkSize
|
||||||
// truncate end
|
// truncate end
|
||||||
if end > len(serializedManifest) {
|
if end > len(serializedManifest) {
|
||||||
end = len(serializedManifest)
|
end = len(serializedManifest)
|
||||||
|
|
|
@ -108,7 +108,7 @@ func TestFileSharing(t *testing.T) {
|
||||||
err := json.Unmarshal([]byte(messageWrapper.Data), &fileMessageOverlay)
|
err := json.Unmarshal([]byte(messageWrapper.Data), &fileMessageOverlay)
|
||||||
|
|
||||||
if err == nil {
|
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