Deprecated SendMessageToPeer and SendMessageToGroupTracks
New Generic SendMessage function that does basic handle checking and error reporting
This commit is contained in:
parent
62f0cfaad3
commit
e038da335e
|
@ -12,3 +12,12 @@ server/app/messages
|
|||
/storage/*/testing/
|
||||
/storage/testing/
|
||||
/testing/storage/
|
||||
ebusgraph.txt
|
||||
messages/
|
||||
serverMonitorReport.txt
|
||||
testing/cwtch.out.png
|
||||
testing/cwtch.out.png.manifest
|
||||
testing/tordir/
|
||||
tokens-bak.db
|
||||
tokens.db
|
||||
tokens1.db
|
|
@ -83,7 +83,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, handl
|
|||
|
||||
profile.ShareFile(key, string(serializedManifest))
|
||||
|
||||
profile.SendMessageToPeer(handle, string(wrapperJSON))
|
||||
profile.SendMessage(handle, string(wrapperJSON))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -15,3 +15,6 @@ require (
|
|||
golang.org/x/tools v0.1.2 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
)
|
||||
|
||||
|
||||
replace git.openprivacy.ca/cwtch.im/tapir => /home/sarah/workspace/src/cwtch.im/tapir
|
|
@ -11,6 +11,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -51,6 +52,26 @@ type cwtchPeer struct {
|
|||
eventBus event.Manager
|
||||
}
|
||||
|
||||
// SendMessage is a higher level that merges sending messages to contacts and group handles
|
||||
// If you try to send a message to a handle that doesn't exist, malformed or an incorrect type then
|
||||
// this function will error
|
||||
func (cp *cwtchPeer) SendMessage(handle string, message string) error {
|
||||
// Group Handles are always 32 bytes in length, but we forgo any further testing here
|
||||
// and delegate the group existence check to SendMessageToGroupTracked
|
||||
if len(handle) == 32 {
|
||||
_, err := cp.SendMessageToGroupTracked(handle, message)
|
||||
return err
|
||||
} else if tor.IsValidHostname(handle) {
|
||||
// We assume we are sending to a Contact.
|
||||
// (Servers are technically Contacts)
|
||||
cp.SendMessageToPeer(handle, message)
|
||||
// We assume this is always successful as it is always valid to attempt to
|
||||
// Contact a valid hostname
|
||||
return nil
|
||||
}
|
||||
return errors.New("malformed handle type")
|
||||
}
|
||||
|
||||
func (cp *cwtchPeer) UpdateMessageFlags(handle string, mIdx int, flags uint64) {
|
||||
cp.mutex.Lock()
|
||||
defer cp.mutex.Unlock()
|
||||
|
@ -137,9 +158,13 @@ type ModifyServers interface {
|
|||
}
|
||||
|
||||
// SendMessages enables a caller to sender messages to a contact
|
||||
// Note:
|
||||
type SendMessages interface {
|
||||
|
||||
SendMessage(handle string, message string) error
|
||||
|
||||
SendGetValToPeer(string, string, string)
|
||||
|
||||
// Deprecated
|
||||
SendMessageToPeer(string, string) string
|
||||
|
||||
// TODO This should probably not be exposed
|
||||
|
@ -151,6 +176,8 @@ type SendMessages interface {
|
|||
|
||||
// SendMessagesToGroup enables a caller to sender messages to a group
|
||||
type SendMessagesToGroup interface {
|
||||
|
||||
// Deprecated
|
||||
SendMessageToGroupTracked(string, string) (string, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -524,8 +524,8 @@ func (e *engine) handlePeerMessage(hostname string, eventID string, context stri
|
|||
} else if context == event.ContextRetVal {
|
||||
req, ok := e.getValRequests.Load(hostname + eventID)
|
||||
if ok {
|
||||
reqStr := req.(string)
|
||||
e.handlePeerRetVal(hostname, []byte(reqStr), message)
|
||||
reqStr := req.([]byte)
|
||||
e.handlePeerRetVal(hostname, reqStr, message)
|
||||
e.getValRequests.Delete(hostname + eventID)
|
||||
} else {
|
||||
log.Errorf("could not find val request for %v %s",hostname, eventID)
|
||||
|
@ -615,7 +615,7 @@ func (e *engine) sendPeerMessage(handle string, message model3.PeerMessage) erro
|
|||
if ok {
|
||||
return peerApp.SendMessage(message)
|
||||
}
|
||||
log.Errorf("could not send peer message: %v", err)
|
||||
log.Errorf("could not derive peer app: %v", err)
|
||||
return fmt.Errorf("could not find peer app to send message to: %v", handle)
|
||||
}
|
||||
log.Errorf("could not send peer message: %v", err)
|
||||
|
|
|
@ -86,6 +86,7 @@ func TestFileSharing(t *testing.T) {
|
|||
|
||||
bob.AddContact("alice?", alice.GetOnion(), model.AuthApproved)
|
||||
alice.PeerWithOnion(bob.GetOnion())
|
||||
bob.PeerWithOnion(alice.GetOnion())
|
||||
|
||||
fmt.Println("Waiting for alice and Bob to peer...")
|
||||
waitForPeerPeerConnection(t, alice, bob)
|
||||
|
|
Loading…
Reference in New Issue