clients

package
v0.0.0-...-3ba3d46 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StateBotOptionsEvent = mevt.Type{Type: "m.room.bot.options", Class: mevt.StateEventType}

Functions

This section is empty.

Types

type BotClient

type BotClient struct {
	*mautrix.Client
	// contains filtered or unexported fields
}

BotClient represents one of the bot's sessions, with a specific User and Device ID. It can be used for sending messages and retrieving information about the rooms that the client has joined.

func (*BotClient) DecryptMegolmEvent

func (botClient *BotClient) DecryptMegolmEvent(evt *mevt.Event) (*mevt.Event, error)

DecryptMegolmEvent attempts to decrypt an incoming m.room.encrypted message using the session information already present in the OlmMachine. The corresponding decrypted event is then returned. If it fails, usually because the session is not known, an error is returned.

func (*BotClient) ForwardRoomKeyToDevice

func (botClient *BotClient) ForwardRoomKeyToDevice(userID id.UserID, deviceID id.DeviceID, roomID id.RoomID, senderKey id.SenderKey,
	sessionID id.SessionID) error

ForwardRoomKeyToDevice sends a room key to another device.

func (*BotClient) InitOlmMachine

func (botClient *BotClient) InitOlmMachine(client *mautrix.Client, nebStore *matrix.NEBStore) (err error)

InitOlmMachine initializes a BotClient's internal OlmMachine given a client object and a Neb store, which will be used to store room information.

func (*BotClient) InvalidateRoomSession

func (botClient *BotClient) InvalidateRoomSession(roomID id.RoomID) (id.SessionID, error)

InvalidateRoomSession invalidates the outbound group session for the given room.

func (*BotClient) OnCancel

func (botClient *BotClient) OnCancel(cancelledByUs bool, reason string, reasonCode mevt.VerificationCancelCode)

OnCancel is called when a SAS verification is canceled.

func (*BotClient) OnSuccess

func (botClient *BotClient) OnSuccess()

OnSuccess is called when a SAS verification is successful.

func (*BotClient) Register

func (botClient *BotClient) Register(syncer mautrix.ExtensibleSyncer)

Register registers a BotClient's Sync and StateMember event callbacks to update its internal state when new events arrive.

func (*BotClient) SendMessageEvent

func (botClient *BotClient) SendMessageEvent(roomID id.RoomID, evtType mevt.Type, content interface{},
	extra ...mautrix.ReqSendEvent) (*mautrix.RespSendEvent, error)

SendMessageEvent sends the given content to the given room ID using this BotClient as a message event. If the target room has enabled encryption, a megolm session is created if one doesn't already exist and the message is sent after being encrypted.

func (*BotClient) SendRoomKeyRequest

func (botClient *BotClient) SendRoomKeyRequest(userID id.UserID, deviceID id.DeviceID, roomID id.RoomID,
	senderKey id.SenderKey, sessionID id.SessionID, timeout time.Duration) (chan bool, error)

SendRoomKeyRequest sends a room key request to another device.

func (*BotClient) StartSASVerification

func (botClient *BotClient) StartSASVerification(userID id.UserID, deviceID id.DeviceID) (string, error)

StartSASVerification starts a new SAS verification with the given user and device ID and returns the transaction ID if successful.

func (*BotClient) SubmitDecimalSAS

func (botClient *BotClient) SubmitDecimalSAS(otherUser id.UserID, otherDevice id.DeviceID, sas crypto.DecimalSASData)

SubmitDecimalSAS stores the received decimal SAS from another device to compare to the local one. It stores the SAS in the bot client's SAS sync map to be retrieved from the `VerifySASMatch` function.

func (*BotClient) Sync

func (botClient *BotClient) Sync()

Sync loops to keep syncing the client with the homeserver by calling the /sync endpoint.

func (*BotClient) VerificationMethods

func (botClient *BotClient) VerificationMethods() []crypto.VerificationMethod

VerificationMethods returns the supported SAS verification methods. As a bot we only support decimal as it's easier to understand.

func (*BotClient) VerifySASMatch

func (botClient *BotClient) VerifySASMatch(otherDevice *crypto.DeviceIdentity, sas crypto.SASData) bool

VerifySASMatch returns whether the received SAS matches the SAS that the bot generated. It retrieves the SAS of the other device from the bot client's SAS sync map, where it was stored by the `SubmitDecimalSAS` function.

type Clients

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

A Clients is a collection of clients used for bot services.

func New

func New(db database.Storer, cli *http.Client) *Clients

New makes a new collection of matrix clients

func (*Clients) Client

func (c *Clients) Client(userID id.UserID) (*BotClient, error)

Client gets a client for the userID

func (*Clients) Start

func (c *Clients) Start() error

Start listening on client /sync streams

func (*Clients) Update

func (c *Clients) Update(config api.ClientConfig) (api.ClientConfig, error)

Update updates the config for a matrix client

type CryptoMachineLogger

type CryptoMachineLogger struct{}

CryptoMachineLogger wraps around the usual logger, implementing the Logger interface needed by OlmMachine.

func (CryptoMachineLogger) Debug

func (CryptoMachineLogger) Debug(message string, args ...interface{})

Debug formats and logs a debug message.

func (CryptoMachineLogger) Error

func (CryptoMachineLogger) Error(message string, args ...interface{})

Error formats and logs an error message.

func (CryptoMachineLogger) Trace

func (CryptoMachineLogger) Trace(message string, args ...interface{})

Trace formats and logs a trace message.

func (CryptoMachineLogger) Warn

func (CryptoMachineLogger) Warn(message string, args ...interface{})

Warn formats and logs a warning message.

type NebStateStore

type NebStateStore struct {
	Storer *mautrix.InMemoryStore
}

NebStateStore implements the StateStore interface for OlmMachine. It is used to determine which rooms are encrypted and which rooms are shared with a user. The state is updated by /sync responses.

func (*NebStateStore) FindSharedRooms

func (ss *NebStateStore) FindSharedRooms(userID id.UserID) []id.RoomID

FindSharedRooms returns a list of room IDs that the given user ID is also a member of.

func (*NebStateStore) GetEncryptionEvent

func (ss *NebStateStore) GetEncryptionEvent(roomID id.RoomID) *event.EncryptionEventContent

GetEncryptionEvent returns the encryption event for a room.

func (*NebStateStore) GetJoinedMembers

func (ss *NebStateStore) GetJoinedMembers(roomID id.RoomID) ([]id.UserID, error)

GetJoinedMembers returns a list of members that are currently in a room.

func (*NebStateStore) IsEncrypted

func (ss *NebStateStore) IsEncrypted(roomID id.RoomID) bool

IsEncrypted returns whether a room has been encrypted.

func (*NebStateStore) UpdateStateStore

func (ss *NebStateStore) UpdateStateStore(resp *mautrix.RespSync)

UpdateStateStore updates the internal state of NebStateStore from a /sync response.

Jump to

Keyboard shortcuts

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