Documentation ¶
Index ¶
- Constants
- func GenerateRandomID() string
- type Group
- func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) (*Message, bool)
- func (g *Group) AddSentMessage(message *protocol.DecryptedGroupMessage, sig []byte) Message
- func (g *Group) Compromised()
- func (g *Group) DecryptMessage(ciphertext []byte) (bool, *protocol.DecryptedGroupMessage)
- func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error)
- func (g *Group) ErrorSentMessage(sig []byte, error string) bool
- func (g *Group) GetAttribute(name string) (value string, exists bool)
- func (g *Group) GetInitialMessage() []byte
- func (g *Group) GetTimeline() (timeline []Message)
- func (g *Group) Invite(initialMessage []byte) ([]byte, error)
- func (g *Group) SetAttribute(name string, value string)
- func (g *Group) SignGroup(signature []byte)
- type Message
- type Profile
- func (p *Profile) AcceptInvite(groupID string) (err error)
- func (p *Profile) AckSentMessageToPeer(onion string, eventID string)
- func (p *Profile) AddContact(onion string, profile *PublicProfile)
- func (p *Profile) AddGroup(group *Group)
- func (p *Profile) AddGroupSentMessageError(groupServer string, signature string, error string)
- func (p *Profile) AddMessageToContactTimeline(onion string, messageTxt string, sent time.Time) (message *Message)
- func (p *Profile) AddSentMessageToContactTimeline(onion string, messageTxt string, sent time.Time, eventID string) *Message
- func (p *Profile) AttemptDecryption(ciphertext []byte, signature []byte) (bool, string, *Message, bool)
- func (p *Profile) BlockPeer(onion string) (err error)
- func (p *Profile) BlockedPeers() []string
- func (p *Profile) DeleteContact(onion string)
- func (p *Profile) DeleteGroup(groupID string)
- func (p *Profile) EncryptMessageToGroup(message string, groupID string) ([]byte, []byte, error)
- func (p *Profile) ErrorSentMessageToPeer(onion string, eventID string, error string)
- func (p *Profile) GetContact(onion string) (*PublicProfile, bool)
- func (p *Profile) GetContacts() []string
- func (p *Profile) GetCopy(timeline bool) *Profile
- func (p *Profile) GetGroup(groupID string) (g *Group)
- func (p *Profile) GetGroups() []string
- func (p *Profile) IsBlocked(onion string) bool
- func (p *Profile) ProcessInvite(invite string, peerHostname string) (string, error)
- func (p *Profile) RejectInvite(groupID string)
- func (p *Profile) SignMessage(message string) []byte
- func (p *Profile) StartGroup(server string) (groupID string, invite []byte, err error)
- func (p *Profile) StartGroupWithMessage(server string, initialMessage []byte) (groupID string, invite []byte, err error)
- func (p *Profile) TrustPeer(onion string) (err error)
- func (p *Profile) UnblockPeer(onion string) (err error)
- func (p *Profile) VerifyGroupMessage(onion string, groupID string, message string, timestamp int32, ...) bool
- type PublicProfile
- type Timeline
- func (t *Timeline) GetCopy() *Timeline
- func (t *Timeline) GetMessages() []Message
- func (t *Timeline) Insert(mi *Message) bool
- func (t *Timeline) Len() int
- func (t *Timeline) Less(i, j int) bool
- func (t *Timeline) SetMessages(messages []Message)
- func (t *Timeline) Sort()
- func (t *Timeline) Swap(i, j int)
Constants ¶
const MaxGroupMessageLength = 1800
MaxGroupMessageLength is the maximum length of a message posted to a server group. TODO: Should this be per server?
const MessageBaseSize = 104
MessageBaseSize is a rough estimate of the base number of bytes the struct uses before strings are populated
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomID ¶ added in v0.3.7
func GenerateRandomID() string
GenerateRandomID generates a random 16 byte hex id code
Types ¶
type Group ¶
type Group struct { GroupID string SignedGroupID []byte GroupKey [32]byte GroupServer string Timeline Timeline `json:"-"` Accepted bool Owner string IsCompromised bool InitialMessage []byte Attributes map[string]string LocalID string State string `json:"-"` // contains filtered or unexported fields }
Group defines and encapsulates Cwtch's conception of group chat. Which are sessions tied to a server under a given group key. Each group has a set of Messages.
func (*Group) AddMessage ¶
AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline
func (*Group) AddSentMessage ¶
func (g *Group) AddSentMessage(message *protocol.DecryptedGroupMessage, sig []byte) Message
AddSentMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline
func (*Group) Compromised ¶
func (g *Group) Compromised()
Compromised should be called if we detect a a groupkey leak.
func (*Group) DecryptMessage ¶
func (g *Group) DecryptMessage(ciphertext []byte) (bool, *protocol.DecryptedGroupMessage)
DecryptMessage takes a ciphertext and returns true and the decrypted message if the cipher text can be successfully decrypted,else false.
func (*Group) EncryptMessage ¶
func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error)
EncryptMessage takes a message and encrypts the message under the group key.
func (*Group) ErrorSentMessage ¶ added in v0.3.2
ErrorSentMessage removes a sent message from the unacknowledged list and sets its error flag if found, otherwise returns false
func (*Group) GetAttribute ¶
GetAttribute returns the value of a value set with SetAttribute. If no such value has been set exists is set to false.
func (*Group) GetInitialMessage ¶
GetInitialMessage returns the first message of the group, if one was sent with the invite.
func (*Group) GetTimeline ¶
GetTimeline provides a safe copy of the timeline
func (*Group) SetAttribute ¶
SetAttribute allows applications to store arbitrary configuration info at the group level.
type Message ¶
type Message struct { Timestamp time.Time Received time.Time PeerID string Message string Signature []byte PreviousMessageSig []byte ReceivedByServer bool // messages sent to a server Acknowledged bool // peer to peer Error string `json:",omitempty"` }
Message is a local representation of a given message sent over a group chat channel.
type Profile ¶
type Profile struct { PublicProfile Contacts map[string]*PublicProfile Ed25519PrivateKey ed25519.PrivateKey Groups map[string]*Group }
Profile encapsulates all the attributes necessary to be a Cwtch Peer.
func GenerateNewProfile ¶
GenerateNewProfile creates a new profile, with new encryption and signing keys, and a profile name.
func (*Profile) AcceptInvite ¶
AcceptInvite accepts a group invite
func (*Profile) AckSentMessageToPeer ¶ added in v0.3.2
AckSentMessageToPeer sets mesage to a peer as acknowledged
func (*Profile) AddContact ¶
func (p *Profile) AddContact(onion string, profile *PublicProfile)
AddContact allows direct manipulation of cwtch contacts
func (*Profile) AddGroupSentMessageError ¶ added in v0.3.2
AddGroupSentMessageError searches matching groups for the message by sig and marks it as an error
func (*Profile) AddMessageToContactTimeline ¶ added in v0.3.2
func (p *Profile) AddMessageToContactTimeline(onion string, messageTxt string, sent time.Time) (message *Message)
AddMessageToContactTimeline allows the saving of a message sent via a direct connection chat to the profile.
func (*Profile) AddSentMessageToContactTimeline ¶ added in v0.3.2
func (p *Profile) AddSentMessageToContactTimeline(onion string, messageTxt string, sent time.Time, eventID string) *Message
AddSentMessageToContactTimeline allows the saving of a message sent via a direct connection chat to the profile.
func (*Profile) AttemptDecryption ¶
func (p *Profile) AttemptDecryption(ciphertext []byte, signature []byte) (bool, string, *Message, bool)
AttemptDecryption takes a ciphertext and signature and attempts to decrypt it under known groups. If successful, adds the message to the group's timeline
func (*Profile) BlockedPeers ¶
BlockedPeers calculates a list of Peers who have been Blocked.
func (*Profile) DeleteContact ¶
DeleteContact deletes a peer contact
func (*Profile) DeleteGroup ¶
DeleteGroup deletes a group
func (*Profile) EncryptMessageToGroup ¶
EncryptMessageToGroup when given a message and a group, encrypts and signs the message under the group and profile
func (*Profile) ErrorSentMessageToPeer ¶ added in v0.3.2
ErrorSentMessageToPeer sets a sent message's error message and removes it from the unacknowledged list
func (*Profile) GetContact ¶
func (p *Profile) GetContact(onion string) (*PublicProfile, bool)
GetContact returns a contact if the profile has it
func (*Profile) GetContacts ¶
GetContacts returns an unordered list of contact onions associated with this profile.
func (*Profile) GetCopy ¶
GetCopy returns a full deep copy of the Profile struct and its members (timeline inclusion control by arg)
func (*Profile) GetGroup ¶ added in v0.3.3
GetGroup a pointer to a Group by the group Id, returns nil if no group found.
func (*Profile) GetGroups ¶
GetGroups returns an unordered list of group IDs associated with this profile.
func (*Profile) ProcessInvite ¶
ProcessInvite adds a new group invite to the profile. returns the new group ID
func (*Profile) RejectInvite ¶
RejectInvite rejects and removes a group invite
func (*Profile) SignMessage ¶
SignMessage takes a given message and returns an Ed21159 signature
func (*Profile) StartGroup ¶
StartGroup when given a server, creates a new Group under this profile and returns the group id an a precomputed invite which can be sent on the wire.
func (*Profile) StartGroupWithMessage ¶
func (p *Profile) StartGroupWithMessage(server string, initialMessage []byte) (groupID string, invite []byte, err error)
StartGroupWithMessage when given a server, and an initial message creates a new Group under this profile and returns the group id an a precomputed invite which can be sent on the wire.
func (*Profile) UnblockPeer ¶
UnblockPeer unblocks a contact
type PublicProfile ¶
type PublicProfile struct { Name string Ed25519PublicKey ed25519.PublicKey Trusted bool Blocked bool Onion string Attributes map[string]string Timeline Timeline `json:"-"` LocalID string // used by storage engine State string `json:"-"` // contains filtered or unexported fields }
PublicProfile is a local copy of a CwtchIdentity
func (*PublicProfile) GetAttribute ¶
func (p *PublicProfile) GetAttribute(name string) (value string, exists bool)
GetAttribute returns the value of a value set with SetCustomAttribute. If no such value has been set exists is set to false.
func (*PublicProfile) SetAttribute ¶
func (p *PublicProfile) SetAttribute(name string, value string)
SetAttribute allows applications to store arbitrary configuration info at the profile level.
type Timeline ¶
type Timeline struct { Messages []Message SignedGroupID []byte // contains filtered or unexported fields }
Timeline encapsulates a collection of ordered Messages, and a mechanism to access them in a threadsafe manner.
func (*Timeline) GetMessages ¶
GetMessages returns a copy of the entire timeline
func (*Timeline) Less ¶
Less checks 2 Messages (i and j) in the timeline and returns true if i occurred before j, else false
func (*Timeline) SetMessages ¶
SetMessages sets the Messages of this timeline. Only to be used in loading/initialization