Break apart CwtchPeer interface to better support testing and analysis #342
|
@ -43,58 +43,127 @@ type cwtchPeer struct {
|
|||
eventBus event.Manager
|
||||
}
|
||||
|
||||
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to
|
||||
// directly implement a cwtchPeer.
|
||||
type CwtchPeer interface {
|
||||
Init(event.Manager)
|
||||
AutoHandleEvents(events []event.Type)
|
||||
PeerWithOnion(string)
|
||||
InviteOnionToGroup(string, string) error
|
||||
SendMessageToPeer(string, string) string
|
||||
SendGetValToPeer(string, string, string)
|
||||
StoreMessage(onion string, messageTxt string, sent time.Time)
|
||||
// ReadContacts is a meta-interface intended to restrict callers to read-only access to contacts
|
||||
type ReadContacts interface {
|
||||
GetContacts() []string
|
||||
GetContact(string) *model.PublicProfile
|
||||
GetContactAttribute(string, string) (string, bool)
|
||||
}
|
||||
|
||||
// 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
|
||||
ProcessInvite(string, string) (string, string, error)
|
||||
AcceptInvite(string) error
|
||||
RejectInvite(string)
|
||||
SetContactAttribute(string, string, 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)
|
||||
}
|
||||
|
||||
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
|
||||
ExportGroup(string) (string, error)
|
||||
// ModifyContactsAndPeers is a meta-interface intended to restrict a call to reading and modifying contacts
|
||||
// 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
|
||||
GetGroupState(string) (connections.ConnectionState, bool)
|
||||
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)
|
||||
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()
|
||||
StartPeersConnections()
|
||||
StartServerConnections()
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue