Break apart CwtchPeer interface to better support testing and analysis #342
|
@ -43,58 +43,127 @@ type cwtchPeer struct {
|
||||||
eventBus event.Manager
|
eventBus event.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
// ReadContacts is a meta-interface intended to restrict callers to read-only access to contacts
|
||||||
// directly implement a cwtchPeer.
|
type ReadContacts interface {
|
||||||
type CwtchPeer interface {
|
GetContacts() []string
|
||||||
Init(event.Manager)
|
GetContact(string) *model.PublicProfile
|
||||||
AutoHandleEvents(events []event.Type)
|
GetContactAttribute(string, string) (string, bool)
|
||||||
PeerWithOnion(string)
|
}
|
||||||
InviteOnionToGroup(string, string) error
|
|
||||||
SendMessageToPeer(string, string) string
|
|
||||||
SendGetValToPeer(string, string, string)
|
|
||||||
StoreMessage(onion string, messageTxt string, sent time.Time)
|
|
||||||
|
|
||||||
|
// ModifyContacts is a meta-interface intended to restrict callers to modify-only access to contacts
|
||||||
|
type ModifyContacts interface {
|
||||||
|
AddContact(nick, onion string, authorization model.Authorization)
|
||||||
SetContactAuthorization(string, model.Authorization) error
|
SetContactAuthorization(string, model.Authorization) error
|
||||||
ProcessInvite(string, string) (string, string, error)
|
SetContactAttribute(string, string, string)
|
||||||
AcceptInvite(string) error
|
|
||||||
RejectInvite(string)
|
|
||||||
DeleteContact(string)
|
DeleteContact(string)
|
||||||
DeleteGroup(string)
|
}
|
||||||
|
|
||||||
AddServer(string) error
|
|
||||||
JoinServer(string) error
|
|
||||||
GetServers() []string
|
|
||||||
SendMessageToGroupTracked(string, string) (string, error)
|
|
||||||
|
|
||||||
GetName() string
|
|
||||||
SetName(string)
|
|
||||||
GetOnion() string
|
|
||||||
|
|
||||||
|
// AccessPeeringState provides access to functions relating to the underlying connections of a peer.
|
||||||
|
type AccessPeeringState interface {
|
||||||
GetPeerState(string) (connections.ConnectionState, bool)
|
GetPeerState(string) (connections.ConnectionState, bool)
|
||||||
|
}
|
||||||
|
|
||||||
StartGroup(string) (string, []byte, error)
|
// ModifyPeeringState is a meta-interface intended to restrict callers to modify-only access to connection peers
|
||||||
|
type ModifyPeeringState interface {
|
||||||
|
PeerWithOnion(string)
|
||||||
|
JoinServer(string) error
|
||||||
|
}
|
||||||
|
|
||||||
ImportGroup(string) error
|
// ModifyContactsAndPeers is a meta-interface intended to restrict a call to reading and modifying contacts
|
||||||
ExportGroup(string) (string, error)
|
// and peers.
|
||||||
|
type ModifyContactsAndPeers interface {
|
||||||
|
ReadContacts
|
||||||
|
ModifyContacts
|
||||||
|
ModifyPeeringState
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadServers provides access to the servers
|
||||||
|
type ReadServers interface {
|
||||||
|
GetServers() []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadGroups provides read-only access to group state
|
||||||
|
type ReadGroups interface {
|
||||||
GetGroup(string) *model.Group
|
GetGroup(string) *model.Group
|
||||||
GetGroupState(string) (connections.ConnectionState, bool)
|
GetGroupState(string) (connections.ConnectionState, bool)
|
||||||
GetGroups() []string
|
GetGroups() []string
|
||||||
AddContact(nick, onion string, authorization model.Authorization)
|
|
||||||
GetContacts() []string
|
|
||||||
GetContact(string) *model.PublicProfile
|
|
||||||
|
|
||||||
SetAttribute(string, string)
|
|
||||||
GetAttribute(string) (string, bool)
|
|
||||||
SetContactAttribute(string, string, string)
|
|
||||||
GetContactAttribute(string, string) (string, bool)
|
|
||||||
SetGroupAttribute(string, string, string)
|
|
||||||
GetGroupAttribute(string, string) (string, bool)
|
GetGroupAttribute(string, string) (string, bool)
|
||||||
|
ExportGroup(string) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifyGroups provides write-only access add/edit/remove new groups
|
||||||
|
type ModifyGroups interface {
|
||||||
|
ImportGroup(string) error
|
||||||
|
StartGroup(string) (string, []byte, error)
|
||||||
|
AcceptInvite(string) error
|
||||||
|
RejectInvite(string)
|
||||||
|
DeleteGroup(string)
|
||||||
|
SetGroupAttribute(string, string, string)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifyServers provides write-only access to servers
|
||||||
|
type ModifyServers interface {
|
||||||
|
AddServer(string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMessages enables a caller to sender messages to a contact
|
||||||
|
// Note:
|
||||||
|
type SendMessages interface {
|
||||||
|
SendGetValToPeer(string, string, string)
|
||||||
|
SendMessageToPeer(string, string) string
|
||||||
|
|
||||||
|
// TODO This should probably not be exposed
|
||||||
|
StoreMessage(onion string, messageTxt string, sent time.Time)
|
||||||
|
|
||||||
|
// TODO Extract once groups are stable
|
||||||
|
InviteOnionToGroup(string, string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMessagesToGroup enables a caller to sender messages to a group
|
||||||
|
type SendMessagesToGroup interface {
|
||||||
|
SendMessageToGroupTracked(string, string) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
||||||
|
// directly implement a cwtchPeer.
|
||||||
|
type CwtchPeer interface {
|
||||||
|
|
||||||
|
// Core Cwtch Peer Functions that should not be exposed to
|
||||||
|
// most functions
|
||||||
|
Init(event.Manager)
|
||||||
|
AutoHandleEvents(events []event.Type)
|
||||||
Listen()
|
Listen()
|
||||||
StartPeersConnections()
|
StartPeersConnections()
|
||||||
StartServerConnections()
|
StartServerConnections()
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
|
||||||
|
// Relating to local attributes
|
||||||
|
GetOnion() string
|
||||||
|
SetAttribute(string, string)
|
||||||
|
GetAttribute(string) (string, bool)
|
||||||
|
|
||||||
|
ReadContacts
|
||||||
|
ModifyContacts
|
||||||
|
|
||||||
|
AccessPeeringState
|
||||||
|
ModifyPeeringState
|
||||||
|
|
||||||
|
ReadGroups
|
||||||
|
ModifyGroups
|
||||||
|
|
||||||
|
ReadServers
|
||||||
|
ModifyServers
|
||||||
|
|
||||||
|
SendMessages
|
||||||
|
SendMessagesToGroup
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
// TODO Should be removed
|
||||||
|
GetName() string
|
||||||
|
SetName(string)
|
||||||
|
|
||||||
|
// TODO Should not be exposed...
|
||||||
|
ProcessInvite(string, string) (string, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCwtchPeer creates and returns a new cwtchPeer with the given name.
|
// NewCwtchPeer creates and returns a new cwtchPeer with the given name.
|
||||||
|
@ -604,8 +673,8 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
case event.EncryptedGroupMessage:
|
case event.EncryptedGroupMessage:
|
||||||
// If successful, a side effect is the message is added to the group's timeline
|
// If successful, a side effect is the message is added to the group's timeline
|
||||||
cp.mutex.Lock()
|
cp.mutex.Lock()
|
||||||
ciphertext,_ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
|
ciphertext, _ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
|
||||||
signature,_ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])
|
||||||
ok, groupID, message, seen := cp.Profile.AttemptDecryption(ciphertext, signature)
|
ok, groupID, message, seen := cp.Profile.AttemptDecryption(ciphertext, signature)
|
||||||
cp.mutex.Unlock()
|
cp.mutex.Unlock()
|
||||||
if ok && !seen {
|
if ok && !seen {
|
||||||
|
|
Loading…
Reference in New Issue