erinn makes changes
This commit is contained in:
parent
a28896c293
commit
2bd170fb85
|
@ -2,19 +2,20 @@ package filesharing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"cwtch.im/cwtch/model"
|
|
||||||
"cwtch.im/cwtch/model/attr"
|
|
||||||
"cwtch.im/cwtch/peer"
|
|
||||||
"cwtch.im/cwtch/protocol/files"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"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...
|
// 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
|
// DownloadFile given a profile, a conversation handle and a file sharing key, start off a download process
|
||||||
// to downloadFilePath
|
// to downloadFilePath
|
||||||
func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, key string) {
|
func (f *Functionality) DownloadFile(profile peer.CwtchPeer, handle string, downloadFilePath string, manifestFilePath string, key string) {
|
||||||
profile.SetAttribute(attr.GetLocalScope(key), downloadFilePath)
|
profile.SetAttribute(attr.GetLocalScope(key), manifestFilePath)
|
||||||
profile.SendGetValToPeer(handle, attr.PublicScope, fmt.Sprintf("%s.manifest.size", key))
|
profile.SendGetValToPeer(handle, attr.PublicScope, fmt.Sprintf("%s.manifest.size", key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
package peer
|
package peer
|
||||||
|
|
||||||
import (
|
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/base32"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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"
|
const lastKnownSignature = "LastKnowSignature"
|
||||||
|
@ -159,7 +160,6 @@ type ModifyServers interface {
|
||||||
|
|
||||||
// SendMessages enables a caller to sender messages to a contact
|
// SendMessages enables a caller to sender messages to a contact
|
||||||
type SendMessages interface {
|
type SendMessages interface {
|
||||||
|
|
||||||
SendMessage(handle string, message string) error
|
SendMessage(handle string, message string) error
|
||||||
|
|
||||||
SendGetValToPeer(string, string, string)
|
SendGetValToPeer(string, string, string)
|
||||||
|
@ -837,22 +837,27 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
fileKey := ev.Data[event.FileKey]
|
fileKey := ev.Data[event.FileKey]
|
||||||
serializedManifest := ev.Data[event.SerializedManifest]
|
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 {
|
if exists {
|
||||||
log.Debugf("downloading file to %v", downloadFilePath)
|
downloadFilePath, exists := cp.GetAttribute(attr.GetLocalScope(fileKey))
|
||||||
var manifest files.Manifest
|
if exists {
|
||||||
err := json.Unmarshal([]byte(serializedManifest), &manifest)
|
log.Debugf("downloading manifest to %v, file to %v", manifestFilePath, downloadFilePath)
|
||||||
if err == nil {
|
var manifest files.Manifest
|
||||||
manifest.FileName = downloadFilePath
|
err := json.Unmarshal([]byte(serializedManifest), &manifest)
|
||||||
log.Debugf("saving manifest")
|
if err == nil {
|
||||||
err = manifest.Save(fmt.Sprintf("%v.manifest", downloadFilePath))
|
manifest.FileName = downloadFilePath
|
||||||
if err != nil {
|
log.Debugf("saving manifest")
|
||||||
log.Errorf("could not save 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 {
|
} 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 {
|
} else {
|
||||||
log.Errorf("error saving manifest: %v", err)
|
log.Errorf("found manifest path but not download path for %v", fileKey)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("no download path found for manifest: %v", fileKey)
|
log.Errorf("no download path found for manifest: %v", fileKey)
|
||||||
|
|
Loading…
Reference in New Issue