diff --git a/functionality/filesharing/filesharing_functionality.go b/functionality/filesharing/filesharing_functionality.go index 022bded..633c010 100644 --- a/functionality/filesharing/filesharing_functionality.go +++ b/functionality/filesharing/filesharing_functionality.go @@ -2,19 +2,20 @@ package filesharing import ( "crypto/rand" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/files" "encoding/hex" "encoding/json" "errors" "fmt" - "git.openprivacy.ca/openprivacy/log" "io" "math" "path" "strconv" + + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/files" + "git.openprivacy.ca/openprivacy/log" ) // Functionality groups some common UI triggered functions for contacts... @@ -40,8 +41,8 @@ type OverlayMessage struct { // DownloadFile given a profile, a conversation handle and a file sharing key, start off a download process // to downloadFilePath -func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, key string) { - profile.SetAttribute(attr.GetLocalScope(key), downloadFilePath) +func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, manifestFilePath string, key string) { + profile.SetAttribute(attr.GetLocalScope(key), manifestFilePath) profile.SendGetValToPeer(handle, attr.PublicScope, fmt.Sprintf("%s.manifest.size", key)) } diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 34260cc..49eb219 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -1,22 +1,23 @@ package peer import ( - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/model" - "cwtch.im/cwtch/model/attr" - "cwtch.im/cwtch/protocol/connections" - "cwtch.im/cwtch/protocol/files" "encoding/base32" "encoding/base64" "encoding/json" "errors" "fmt" - "git.openprivacy.ca/openprivacy/connectivity/tor" - "git.openprivacy.ca/openprivacy/log" "strconv" "strings" "sync" "time" + + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/model" + "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/protocol/connections" + "cwtch.im/cwtch/protocol/files" + "git.openprivacy.ca/openprivacy/connectivity/tor" + "git.openprivacy.ca/openprivacy/log" ) const lastKnownSignature = "LastKnowSignature" @@ -159,7 +160,6 @@ type ModifyServers interface { // SendMessages enables a caller to sender messages to a contact type SendMessages interface { - SendMessage(handle string, message string) error SendGetValToPeer(string, string, string) @@ -837,22 +837,27 @@ func (cp *cwtchPeer) eventHandler() { fileKey := ev.Data[event.FileKey] serializedManifest := ev.Data[event.SerializedManifest] - downloadFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fileKey)) + manifestFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%v.manifest", fileKey))) if exists { - log.Debugf("downloading file to %v", downloadFilePath) - var manifest files.Manifest - err := json.Unmarshal([]byte(serializedManifest), &manifest) - if err == nil { - manifest.FileName = downloadFilePath - log.Debugf("saving manifest") - err = manifest.Save(fmt.Sprintf("%v.manifest", downloadFilePath)) - if err != nil { - log.Errorf("could not save manifest...") + downloadFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fileKey)) + if exists { + log.Debugf("downloading manifest to %v, file to %v", manifestFilePath, downloadFilePath) + var manifest files.Manifest + err := json.Unmarshal([]byte(serializedManifest), &manifest) + if err == nil { + manifest.FileName = downloadFilePath + log.Debugf("saving manifest") + err = manifest.Save(manifestFilePath) + if err != nil { + log.Errorf("could not save manifest: %v", err) + } else { + cp.eventBus.Publish(event.NewEvent(event.ManifestSaved, map[event.Field]string{event.FileKey: fileKey, event.Handle: handle, event.SerializedManifest: string(manifest.Serialize())})) + } } else { - cp.eventBus.Publish(event.NewEvent(event.ManifestSaved, map[event.Field]string{event.FileKey: fileKey, event.Handle: handle, event.SerializedManifest: string(manifest.Serialize())})) + log.Errorf("error saving manifest: %v", err) } } else { - log.Errorf("error saving manifest: %v", err) + log.Errorf("found manifest path but not download path for %v", fileKey) } } else { log.Errorf("no download path found for manifest: %v", fileKey)