From 777d564ca467245eb3ef294caaaaa736bc7b06ac Mon Sep 17 00:00:00 2001 From: erinn Date: Tue, 2 Nov 2021 14:31:14 -0700 Subject: [PATCH 1/3] wip: file retries --- lib.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib.go b/lib.go index 437e1f0..c0cf511 100644 --- a/lib.go +++ b/lib.go @@ -713,13 +713,20 @@ func c_CheckDownloadStatus(profilePtr *C.char, profileLen C.int, fileKeyPtr *C.c func CheckDownloadStatus(profileOnion, fileKey string) { profile := application.GetPeer(profileOnion) - if path, exists := profile.GetAttribute(attr.GetLocalScope(fileKey)); exists { + if path, exists := profile.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%s.complete", fileKey))); exists { eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{ ProfileOnion: profileOnion, event.FileKey: fileKey, event.FilePath: path, event.TempFile: "", })) + } else if path, exists = profile.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%s.path", fileKey))); exists { + eventHandler.Push(event.NewEvent(event.FileDownloadProgressUpdate, map[event.Field]string{ + ProfileOnion: profileOnion, + event.FileKey: fileKey, + event.Progress: ??, + event.FileSizeInChunks: ??, + })) } } From 792e84d5f97d2ab7736ed71b78f7ddf86bcacb16 Mon Sep 17 00:00:00 2001 From: erinn Date: Thu, 4 Nov 2021 14:10:21 -0700 Subject: [PATCH 2/3] file resumption support --- lib.go | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/lib.go b/lib.go index c460921..91ddf66 100644 --- a/lib.go +++ b/lib.go @@ -208,6 +208,7 @@ func _startCwtch(appDir string, torPath string) { event.ProtocolEngineStopped, event.RetryServerRequest, event.ManifestReceived, + event.FileDownloaded, } settings := utils.ReadGlobalSettings() settingsJson, _ := json.Marshal(settings) @@ -590,9 +591,9 @@ func GetMessage(profileOnion, handle string, messageIndex int) string { message.ContactImage = ph.GetProfilePic(message.Message.PeerID) } else { eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{ - event.Identity: profileOnion, - event.GroupID: handle, - event.Data: strconv.Itoa(length), + event.Identity: profileOnion, + event.GroupID: handle, + event.Data: strconv.Itoa(length), })) log.Errorf("Couldn't find message in timeline %v / %v or unacked messages, probably transient threading issue, but logging for visibility..", messageIndex, length) } @@ -759,23 +760,48 @@ func c_CheckDownloadStatus(profilePtr *C.char, profileLen C.int, fileKeyPtr *C.c func CheckDownloadStatus(profileOnion, fileKey string) { profile := application.GetPeer(profileOnion) - if path, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists { + path, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + if _, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists { eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{ ProfileOnion: profileOnion, event.FileKey: fileKey, event.FilePath: path, event.TempFile: "", })) - } else if path, exists = profile.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%s.path", fileKey))); exists { + } else { + log.Infof("CheckDownloadStatus found .path but not .complete") eventHandler.Push(event.NewEvent(event.FileDownloadProgressUpdate, map[event.Field]string{ - ProfileOnion: profileOnion, - event.FileKey: fileKey, - event.Progress: ??, - event.FileSizeInChunks: ??, + ProfileOnion: profileOnion, + event.FileKey: fileKey, + event.Progress: "-1", + event.FileSizeInChunks: "-1", + event.FilePath: path, })) } } +//export c_VerifyOrResumeDownload +func c_VerifyOrResumeDownload(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, filekey_ptr *C.char, filekey_len C.int) { + profile := C.GoStringN(profile_ptr, profile_len) + handle := C.GoStringN(handle_ptr, handle_len) + filekey := C.GoStringN(filekey_ptr, filekey_len) + VerifyOrResumeDownload(profile, handle, filekey) +} + +func VerifyOrResumeDownload(profileOnion, handle, fileKey string) { + profile := application.GetPeer(profileOnion) + if manifestFilePath, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%v.manifest", fileKey)); exists { + if downloadfilepath, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)); exists { + log.Infof("resuming %s", fileKey) + DownloadFile(profileOnion, handle, downloadfilepath, manifestFilePath, fileKey) + } else { + log.Errorf("found manifest path but not download path for %s", fileKey) + } + } else { + log.Errorf("no stored manifest path found for %s", fileKey) + } +} + //export c_ResetTor func c_ResetTor() { ResetTor() @@ -1091,7 +1117,6 @@ func LaunchServer(onion string) { } } - //export c_StopServer func c_StopServer(onionPtr *C.char, onionLen C.int) { StopServer(C.GoStringN(onionPtr, onionLen)) From b56b821b19449b1e2d6e975998997ea4c6eb3be8 Mon Sep 17 00:00:00 2001 From: erinn Date: Thu, 4 Nov 2021 15:29:39 -0700 Subject: [PATCH 3/3] update cwtch --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0944f6e..1a2c3a0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go go 1.15 require ( - cwtch.im/cwtch v0.13.1 + cwtch.im/cwtch v0.13.2 git.openprivacy.ca/cwtch.im/server v1.3.2 git.openprivacy.ca/openprivacy/connectivity v1.5.0 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index a7e4e42..17ccadd 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ cwtch.im/cwtch v0.13.0 h1:9WhLG9czfyRceZnHSqfTAq0vfmDC/E20mziJb9+Skrg= cwtch.im/cwtch v0.13.0/go.mod h1:QpTkQK7MqNt0dQK9/pBk5VpkvFhy6xuoxJIn401B8fM= cwtch.im/cwtch v0.13.1 h1:k7CDr16ZLZ+uaRtic2Joooc8TzkO7BkgWXs8r9ilqDY= cwtch.im/cwtch v0.13.1/go.mod h1:QpTkQK7MqNt0dQK9/pBk5VpkvFhy6xuoxJIn401B8fM= +cwtch.im/cwtch v0.13.2 h1:qbKTQOUryvJpTzIf5iT49x6iAmeNxiz0doNb5phYVEQ= +cwtch.im/cwtch v0.13.2/go.mod h1:QpTkQK7MqNt0dQK9/pBk5VpkvFhy6xuoxJIn401B8fM= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= git.openprivacy.ca/cwtch.im/server v1.3.1 h1:Kt4TnlGxGPk1KTjvs1cXtnFWDx+hYqu8w+2eIaqt+F4=