Split ShareFile and SendMessage
This commit is contained in:
parent
dec2b7182c
commit
9621e294c2
|
@ -88,16 +88,16 @@ func (f *Functionality) DownloadFile(profile peer.CwtchPeer, conversationID int,
|
|||
|
||||
// ShareFile given a profile and a conversation handle, sets up a file sharing process to share the file
|
||||
// at filepath
|
||||
func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conversationID int) (string, error) {
|
||||
func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer) (string, string, error) {
|
||||
manifest, err := files.CreateManifest(filepath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
var nonce [24]byte
|
||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||
log.Errorf("Cannot read from random: %v\n", err)
|
||||
return "", err
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
message := OverlayMessage{
|
||||
|
@ -138,12 +138,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conve
|
|||
|
||||
profile.ShareFile(key, string(serializedManifest))
|
||||
|
||||
// non-specific conversation
|
||||
if conversationID != -1 {
|
||||
err = profile.SendMessage(conversationID, string(wrapperJSON))
|
||||
}
|
||||
|
||||
return key, err
|
||||
return key, string(wrapperJSON), err
|
||||
}
|
||||
|
||||
// GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem
|
||||
|
|
|
@ -132,7 +132,8 @@ func TestFileSharing(t *testing.T) {
|
|||
|
||||
filesharingFunctionality, _ := filesharing.FunctionalityGate(map[string]bool{constants.FileSharingExperiment: true})
|
||||
|
||||
_, err = filesharingFunctionality.ShareFile("cwtch.png", alice, 1)
|
||||
_, fileSharingMessage, err := filesharingFunctionality.ShareFile("cwtch.png", alice)
|
||||
alice.SendMessage(1, fileSharingMessage)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error!: %v", err)
|
||||
|
|
Loading…
Reference in New Issue