peer

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 34 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// TypeAttribute for Profile Scoped and Zoned Attributes
	TypeAttribute = StorageKeyType("Attribute")

	// TypePrivateKey for Profile Private Keys
	TypePrivateKey = StorageKeyType("PrivateKey")

	// TypePublicKey for Profile Public Keys
	TypePublicKey = StorageKeyType("PublicKey")
)
View Source
const SQLCreateTableConversations = `` /* 142-byte string literal not displayed */

SQLCreateTableConversations creates the Profile Key Value Table

View Source
const SQLCreateTableProfileKeyValue = `create table if not exists profile_kv (KeyType text, KeyName text, KeyValue blob, UNIQUE  (KeyType,KeyName));`

SQLCreateTableProfileKeyValue creates the Profile Key Value Table

Variables

DefaultEventsToHandle specifies which events will be subscribed to

when a peer has its Init() function called

Functions

func CreateKeySalt added in v0.14.0

func CreateKeySalt(password string) ([32]byte, [128]byte, error)

CreateKeySalt derives a key and salt from a password: returns key, salt, err

Types

type AccessPeeringState added in v0.6.3

type AccessPeeringState interface {
	GetPeerState(string) connections.ConnectionState
}

AccessPeeringState provides access to functions relating to the underlying connections of a peer.

type ChannelID added in v0.14.0

type ChannelID struct {
	Conversation int
	Channel      int
}

ChannelID encapsulates the data necessary to reference a channel structure.

type CwtchPeer

type CwtchPeer interface {

	// Core Cwtch Peer Functions that should not be exposed to
	// most functions
	Init(event.Manager)

	GenerateProtocolEngine(acn connectivity.ACN, bus event.Manager, engineHooks connections.EngineHooks) (connections.Engine, error)

	AutoHandleEvents(events []event.Type)
	Listen()
	StartConnections(doPeers, doServers bool)
	// Deprecated in 1.10
	StartPeersConnections()
	// Deprecated in 1.10
	StartServerConnections()

	Shutdown()

	// GetOnion is deprecated. If you find yourself needing to rely on this method it is time
	// to consider replacing this with a GetAddress(es) function that can fully expand cwtch beyond the boundaries
	// of tor v3 onion services.
	// Deprecated
	GetOnion() string

	// SetScopedZonedAttribute allows the setting of an attribute by scope and zone
	// scope.zone.key = value
	SetScopedZonedAttribute(scope attr.Scope, zone attr.Zone, key string, value string)

	// GetScopedZonedAttribute allows the retrieval of an attribute by scope and zone
	// scope.zone.key = value
	GetScopedZonedAttribute(scope attr.Scope, zone attr.Zone, key string) (string, bool)

	// GetScopedZonedAttributeKeys returns all keys associated with a given scope and zone
	GetScopedZonedAttributeKeys(scope attr.Scope, zone attr.Zone) ([]string, error)

	AccessPeeringState
	ModifyPeeringState

	ModifyGroups

	ReadServers
	ModifyServers

	SendMessages

	// Import Bundle
	ImportBundle(string) error
	EnhancedImportBundle(string) string

	// New Unified Conversation Interfaces
	NewContactConversation(handle string, acl model.AccessControl, accepted bool) (int, error)
	FetchConversations() ([]*model.Conversation, error)
	ArchiveConversation(conversation int)
	GetConversationInfo(conversation int) (*model.Conversation, error)
	FetchConversationInfo(handle string) (*model.Conversation, error)

	// API-level management of conversation access control
	UpdateConversationAccessControlList(id int, acl model.AccessControlList) error
	EnhancedUpdateConversationAccessControlList(conversation int, acjson string) error

	GetConversationAccessControlList(conversation int) (model.AccessControlList, error)
	EnhancedGetConversationAccessControlList(conversation int) (string, error)

	// Convieniance Functions for ACL Management
	AcceptConversation(conversation int) error
	BlockConversation(conversation int) error
	UnblockConversation(conversation int) error

	SetConversationAttribute(conversation int, path attr.ScopedZonedPath, value string) error
	GetConversationAttribute(conversation int, path attr.ScopedZonedPath) (string, error)
	DeleteConversation(conversation int) error

	// New Unified Conversation Channel Interfaces
	GetChannelMessage(conversation int, channel int, id int) (string, model.Attributes, error)
	GetChannelMessageCount(conversation int, channel int) (int, error)
	GetChannelMessageByContentHash(conversation int, channel int, contenthash string) (int, error)
	GetMostRecentMessages(conversation int, channel int, offset int, limit uint) ([]model.ConversationMessage, error)
	UpdateMessageAttribute(conversation int, channel int, id int, key string, value string) error
	SearchConversations(pattern string) string

	// EnhancedGetMessageById returns a json-encoded enhanced message, suitable for rendering in a UI
	EnhancedGetMessageById(conversation int, mid int) string

	// EnhancedGetMessageByContentHash returns a json-encoded enhanced message, suitable for rendering in a UI
	EnhancedGetMessageByContentHash(conversation int, hash string) string

	// EnhancedGetMessages returns a set of json-encoded enhanced messages, suitable for rendering in a UI
	EnhancedGetMessages(conversation int, index int, count uint) string

	// Server Token APIS
	// TODO move these to feature protected interfaces
	StoreCachedTokens(tokenServer string, tokens []*privacypass.Token)

	// Profile Management
	CheckPassword(password string) bool
	ChangePassword(oldpassword string, newpassword string, newpasswordAgain string) error
	ExportProfile(file string) error
	Delete()
	PublishEvent(resp event.Event)
	RegisterHook(hook ProfileHooks)
	UpdateExperiments(enabled bool, experiments map[string]bool)
	NotifySettingsUpdate(settings settings.GlobalSettings)
	IsFeatureEnabled(featureName string) bool
}

CwtchPeer provides us with a way of testing systems built on top of cwtch without having to directly implement a cwtchPeer.

func CreateEncryptedStorePeer added in v0.14.0

func CreateEncryptedStorePeer(profileDirectory string, name string, password string) (CwtchPeer, error)

CreateEncryptedStorePeer creates a *new* Cwtch Profile backed by an encrypted datastore

func FromEncryptedDatabase added in v0.14.0

func FromEncryptedDatabase(profileDirectory string, password string) (CwtchPeer, error)

FromEncryptedDatabase constructs a Cwtch Profile from an existing Encrypted Database

func FromEncryptedStorage added in v0.14.0

func FromEncryptedStorage(cps *CwtchProfileStorage) CwtchPeer

FromEncryptedStorage loads an existing Profile from Encrypted Storage

func ImportLegacyProfile added in v0.14.0

func ImportLegacyProfile(profile *model.Profile, cps *CwtchProfileStorage) CwtchPeer

ImportLegacyProfile generates a new peer from a profile. Deprecated - Only to be used for importing new profiles

func ImportProfile added in v0.16.0

func ImportProfile(exportedCwtchFile string, profilesDir string, password string) (CwtchPeer, error)

func NewProfileWithEncryptedStorage added in v0.14.0

func NewProfileWithEncryptedStorage(name string, cps *CwtchProfileStorage) CwtchPeer

NewProfileWithEncryptedStorage instantiates a new Cwtch Profile from encrypted storage

type CwtchProfileStorage added in v0.14.0

type CwtchProfileStorage struct {
	ProfileDirectory string
	// contains filtered or unexported fields
}

CwtchProfileStorage encapsulates common datastore requests so as to not pollute the main cwtch profile struct with database knowledge

func CreateEncryptedStore added in v0.14.0

func CreateEncryptedStore(profileDirectory string, password string) (*CwtchProfileStorage, error)

CreateEncryptedStore creates a encrypted datastore

func NewCwtchProfileStorage added in v0.14.0

func NewCwtchProfileStorage(db *sql.DB, profileDirectory string) (*CwtchProfileStorage, error)

NewCwtchProfileStorage constructs a new CwtchProfileStorage from a database. It is also responsible for Preparing commonly used SQL Statements

func (*CwtchProfileStorage) AcceptConversation added in v0.14.0

func (cps *CwtchProfileStorage) AcceptConversation(id int) error

AcceptConversation sets the accepted status of a conversation to true in the backing datastore

func (*CwtchProfileStorage) Close added in v0.14.0

func (cps *CwtchProfileStorage) Close(purgeAllNonSavedMessages bool)

Close closes the underlying database and prepared statements

func (*CwtchProfileStorage) Delete added in v0.14.0

func (cps *CwtchProfileStorage) Delete()

Delete unconditionally destroys the profile directory associated with the store. This is unrecoverable.

func (*CwtchProfileStorage) DeleteConversation added in v0.14.0

func (cps *CwtchProfileStorage) DeleteConversation(id int) error

DeleteConversation purges the conversation and any associated message history from the conversation store.

func (*CwtchProfileStorage) Export added in v0.16.0

func (cps *CwtchProfileStorage) Export(filename string) error

Export takes in a file name and creates an exported cwtch profile file (which in reality is a compressed tarball).

func (*CwtchProfileStorage) FetchConversations added in v0.14.0

func (cps *CwtchProfileStorage) FetchConversations() ([]*model.Conversation, error)

FetchConversations returns *all* active conversations. This method should only be called on app start up to build a summary of conversations for the UI. Any further updates should be integrated through the event bus.

func (*CwtchProfileStorage) FindProfileKeysByPrefix added in v0.17.0

func (cps *CwtchProfileStorage) FindProfileKeysByPrefix(keyType StorageKeyType, prefix string) ([]string, error)

FindProfileKeysByPrefix allows fetching of typed values via a known Key from the Storage Engine

func (*CwtchProfileStorage) GetChannelMessage added in v0.14.0

func (cps *CwtchProfileStorage) GetChannelMessage(conversation int, channel int, messageID int) (string, model.Attributes, error)

GetChannelMessage looks up a channel message by conversation, channel and message id. On success it returns the message body and the attributes associated with the message. Otherwise an error is returned.

func (*CwtchProfileStorage) GetChannelMessageByContentHash added in v0.14.0

func (cps *CwtchProfileStorage) GetChannelMessageByContentHash(conversation int, channel int, hash string) (int, error)

GetChannelMessageByContentHash looks up a conversation message by hash instead of identifier.

func (*CwtchProfileStorage) GetChannelMessageBySignature added in v0.14.0

func (cps *CwtchProfileStorage) GetChannelMessageBySignature(conversation int, channel int, signature string) (int, error)

GetChannelMessageBySignature looks up a conversation message by signature instead of identifier. Both are unique but signatures are common between conversation participants (in groups) and so are a more useful message to index.

func (*CwtchProfileStorage) GetChannelMessageCount added in v0.14.0

func (cps *CwtchProfileStorage) GetChannelMessageCount(conversation int, channel int) (int, error)

GetChannelMessageCount returns the number of messages in a channel

func (*CwtchProfileStorage) GetConversation added in v0.14.0

func (cps *CwtchProfileStorage) GetConversation(id int) (*model.Conversation, error)

GetConversation looks up a particular conversation by id

func (*CwtchProfileStorage) GetConversationByHandle added in v0.14.0

func (cps *CwtchProfileStorage) GetConversationByHandle(handle string) (*model.Conversation, error)

GetConversationByHandle is a convenience method to fetch an active conversation by a handle Usage Notes: This should **only** be used to look up p2p conversations by convention. Ideally this function should not exist, and all lookups should happen by ID (this is currently unavoidable in some circumstances because the event bus references conversations by handle, not by id)

func (*CwtchProfileStorage) GetMostRecentMessages added in v0.14.0

func (cps *CwtchProfileStorage) GetMostRecentMessages(conversation int, channel int, offset int, limit uint) ([]model.ConversationMessage, error)

GetMostRecentMessages returns the most recent messages in a channel up to a given limit at a given offset

func (*CwtchProfileStorage) GetRowNumberByMessageID added in v0.14.0

func (cps *CwtchProfileStorage) GetRowNumberByMessageID(conversation int, channel int, id int) (int, error)

GetRowNumberByMessageID looks up the row number of a message by the message ID

func (*CwtchProfileStorage) InsertMessage added in v0.14.0

func (cps *CwtchProfileStorage) InsertMessage(conversation int, channel int, body string, attributes model.Attributes, signature string, contentHash string) (int, error)

InsertMessage appends a message to a conversation channel, with a given set of attributes

func (*CwtchProfileStorage) LoadProfileKeyValue added in v0.14.0

func (cps *CwtchProfileStorage) LoadProfileKeyValue(keyType StorageKeyType, key string) ([]byte, error)

LoadProfileKeyValue allows fetching of typed values via a known Key from the Storage Engine

func (*CwtchProfileStorage) NewConversation added in v0.14.0

func (cps *CwtchProfileStorage) NewConversation(handle string, attributes model.Attributes, acl model.AccessControlList, accepted bool) (int, error)

NewConversation stores a new conversation in the data store

func (*CwtchProfileStorage) PurgeConversationChannel added in v0.14.0

func (cps *CwtchProfileStorage) PurgeConversationChannel(conversation int, channel int) error

PurgeConversationChannel deletes all message for a conversation channel.

func (*CwtchProfileStorage) PurgeNonSavedMessages added in v0.14.0

func (cps *CwtchProfileStorage) PurgeNonSavedMessages()

PurgeNonSavedMessages deletes all message conversations that are not explicitly set to saved.

func (*CwtchProfileStorage) Rekey added in v0.14.6

func (cps *CwtchProfileStorage) Rekey(newkey [32]byte) error

Rekey re-encrypts the datastore with the new key. **note* this is technically a very dangerous API and should only be called after checks on the current password and the derived new password.

func (*CwtchProfileStorage) SearchMessages added in v0.21.0

func (cps *CwtchProfileStorage) SearchMessages(conversation int, channel int, pattern string, offset int, limit int) ([]model.ConversationMessage, error)

func (*CwtchProfileStorage) SetConversationACL added in v0.14.0

func (cps *CwtchProfileStorage) SetConversationACL(id int, acl model.AccessControlList) error

SetConversationACL sets a new ACL on a given conversation.

func (*CwtchProfileStorage) SetConversationAttribute added in v0.14.0

func (cps *CwtchProfileStorage) SetConversationAttribute(id int, path attr.ScopedZonedPath, value string) error

SetConversationAttribute sets a new attribute on a given conversation.

func (*CwtchProfileStorage) StoreProfileKeyValue added in v0.14.0

func (cps *CwtchProfileStorage) StoreProfileKeyValue(keyType StorageKeyType, key string, value []byte) error

StoreProfileKeyValue allows storing of typed Key/Value attribute in the Storage Engine

func (*CwtchProfileStorage) UpdateMessageAttributes added in v0.14.0

func (cps *CwtchProfileStorage) UpdateMessageAttributes(conversation int, channel int, messageID int, attributes model.Attributes) error

UpdateMessageAttributes updates the attributes associated with a message of a given conversation

type EnhancedMessage added in v0.19.0

type EnhancedMessage struct {
	model.Message
	ID           int // the actual ID of the message in the database (not the row number)
	LocalIndex   int // local index in the DB (row #). Can be empty (most calls supply it) but lookup by hash will fill it
	ContentHash  string
	ContactImage string
	Attributes   map[string]string
}

EnhancedMessage wraps a Cwtch model.Message with some additional data to reduce calls from the UI.

type LastSeenConversation added in v0.18.5

type LastSeenConversation struct {
	// contains filtered or unexported fields
}

type ModifyContactsAndPeers added in v0.6.3

type ModifyContactsAndPeers interface {
	ModifyPeeringState
}

ModifyContactsAndPeers is a meta-interface intended to restrict a call to reading and modifying contacts and peers.

type ModifyGroups added in v0.6.3

type ModifyGroups interface {
	ImportGroup(string) (int, error)
	StartGroup(string, string) (int, error)
}

ModifyGroups provides write-only access add/edit/remove new groups

type ModifyPeeringState added in v0.6.3

type ModifyPeeringState interface {
	BlockUnknownConnections()
	AllowUnknownConnections()
	PeerWithOnion(string)
	QueueJoinServer(string)
	DisconnectFromPeer(string)
	DisconnectFromServer(string)
}

ModifyPeeringState is a meta-interface intended to restrict callers to modify-only access to connection peers

type ModifyServers added in v0.6.3

type ModifyServers interface {
	AddServer(string) (string, error)
	ResyncServer(onion string) error
}

ModifyServers provides write-only access to servers

type ProfileHook added in v0.19.0

type ProfileHook struct {
	// contains filtered or unexported fields
}

func ConstructHook added in v0.19.0

func ConstructHook(extension ProfileHooks) ProfileHook

type ProfileHooks added in v0.19.0

type ProfileHooks interface {
	// EventsToRegister returns a set of events that the extension is interested hooking
	EventsToRegister() []event.Type

	// ExperimentsToRegister returns a set of experiments that the extension is interested in being notified about
	ExperimentsToRegister() []string

	// OnEvent is called whenever an event Registered with RegisterEvents is called
	OnEvent(event event.Event, profile CwtchPeer)

	// OnContactRequestValue is Hooked when a contact sends a request for the given path
	OnContactRequestValue(profile CwtchPeer, conversation model.Conversation, eventID string, path attr.ScopedZonedPath)

	// OnContactReceiveValue is Hooked after a profile receives a response to a Get/Val Request
	OnContactReceiveValue(profile CwtchPeer, conversation model.Conversation, path attr.ScopedZonedPath, value string, exists bool)

	// NotifySettingsUpdate allow profile hooks to access configs e.g. download folder
	NotifySettingsUpdate(settings settings.GlobalSettings)
}

type ReadServers added in v0.6.3

type ReadServers interface {
	GetServers() []string
}

ReadServers provides access to the servers

type Response added in v0.14.0

type Response error

Response is a wrapper to better semantically convey the response type...

func ConstructResponse added in v0.14.0

func ConstructResponse(prefix string, error string) Response

ConstructResponse is a helper function for creating Response structures.

type SendMessages added in v0.6.3

type SendMessages interface {
	SendMessage(conversation int, message string) (int, error)

	// EnhancedSendMessage Attempts to Send a Message and Immediately Attempts to Lookup the Message in the Database
	EnhancedSendMessage(conversation int, message string) string

	SendInviteToConversation(conversationID int, inviteConversationID int) (int, error)

	// EnhancedSendInviteMessage Attempts to Send an Invite and Immediately Attempts to Lookup the Message in the Database
	EnhancedSendInviteMessage(conversation int, inviteConversationID int) string

	SendScopedZonedGetValToContact(conversationID int, scope attr.Scope, zone attr.Zone, key string)
}

SendMessages enables a caller to sender messages to a contact

type StorageKeyType added in v0.14.0

type StorageKeyType string

StorageKeyType is an interface wrapper around storage key types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL