matrix

package
v0.19.0-mod-2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MPL-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const ContentURIMaxLength = 255
View Source
const MediaIDPrefix = "\U0001F408"
View Source
const MediaIDTruncatedHashLength = 16

Variables

View Source
var (
	ErrMismatchingMXID = errors.New("whoami result does not match custom mxid")
	ErrNoAccessToken   = errors.New("no access token provided")
	ErrNoMXID          = errors.New("no mxid provided")
)
View Source
var CommandDiscardMegolmSession = &commands.FullHandler{
	Func: func(ce *commands.Event) {
		matrix := ce.Bridge.Matrix.(*Connector)
		if matrix.Crypto == nil {
			ce.Reply("This bridge instance doesn't have end-to-bridge encryption enabled")
		} else {
			matrix.Crypto.ResetSession(ce.Ctx, ce.RoomID)
			ce.Reply("Successfully reset Megolm session in this room. New decryption keys will be shared the next time a message is sent from the remote network.")
		}
	},
	Name:    "discard-megolm-session",
	Aliases: []string{"discard-session"},
	Help: commands.HelpMeta{
		Section:     commands.HelpSectionAdmin,
		Description: "Discard the Megolm session in the room",
	},
	RequiresAdmin: true,
}
View Source
var CommandLoginMatrix = &commands.FullHandler{
	Func: fnLoginMatrix,
	Name: "login-matrix",
	Help: commands.HelpMeta{
		Section:     commands.HelpSectionAuth,
		Description: "Enable double puppeting.",
		Args:        "<_access token_>",
	},
	RequiresLogin: true,
}
View Source
var CommandLogoutMatrix = &commands.FullHandler{
	Func: fnLogoutMatrix,
	Name: "logout-matrix",
	Help: commands.HelpMeta{
		Section:     commands.HelpSectionAuth,
		Description: "Disable double puppeting.",
	},
	RequiresLogin: true,
}
View Source
var CommandPingMatrix = &commands.FullHandler{
	Func: fnPingMatrix,
	Name: "ping-matrix",
	Help: commands.HelpMeta{
		Section:     commands.HelpSectionAuth,
		Description: "Ping the Matrix server with the double puppet.",
	},
}
View Source
var CommandSetPowerLevel = &commands.FullHandler{
	Func:    fnSetPowerLevel,
	Name:    "set-pl",
	Aliases: []string{"set-power-level"},
	Help: commands.HelpMeta{
		Section:     commands.HelpSectionAdmin,
		Description: "Change the power level in a portal room.",
		Args:        "[_user ID_] <_power level_>",
	},
	RequiresAdmin:  true,
	RequiresPortal: true,
}
View Source
var DuplicateMessageIndex = crypto.DuplicateMessageIndex
View Source
var MinSpecVersion = mautrix.SpecV14
View Source
var NoSessionFound = crypto.NoSessionFound
View Source
var UnknownMessageIndex = olm.UnknownMessageIndex

Functions

This section is empty.

Types

type ASIntent

type ASIntent struct {
	Matrix    *appservice.IntentAPI
	Connector *Connector
}

ASIntent implements the bridge ghost API interface using a real Matrix homeserver as the backend.

func (*ASIntent) CreateRoom

func (as *ASIntent) CreateRoom(ctx context.Context, req *mautrix.ReqCreateRoom) (id.RoomID, error)

func (*ASIntent) DeleteRoom

func (as *ASIntent) DeleteRoom(ctx context.Context, roomID id.RoomID, puppetsOnly bool) error

func (*ASIntent) DownloadMedia

func (as *ASIntent) DownloadMedia(ctx context.Context, uri id.ContentURIString, file *event.EncryptedFileInfo) ([]byte, error)

func (*ASIntent) EnsureInvited

func (as *ASIntent) EnsureInvited(ctx context.Context, roomID id.RoomID, userID id.UserID) error

func (*ASIntent) EnsureJoined

func (as *ASIntent) EnsureJoined(ctx context.Context, roomID id.RoomID) error

func (*ASIntent) GetMXID

func (as *ASIntent) GetMXID() id.UserID

func (*ASIntent) InviteUser

func (as *ASIntent) InviteUser(ctx context.Context, roomID id.RoomID, userID id.UserID) error

func (*ASIntent) MarkRead

func (as *ASIntent) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID, ts time.Time) error

func (*ASIntent) MarkTyping

func (as *ASIntent) MarkTyping(ctx context.Context, roomID id.RoomID, typingType bridgev2.TypingType, timeout time.Duration) error

func (*ASIntent) MarkUnread

func (as *ASIntent) MarkUnread(ctx context.Context, roomID id.RoomID, unread bool) error

func (*ASIntent) MuteRoom

func (as *ASIntent) MuteRoom(ctx context.Context, roomID id.RoomID, until time.Time) error

func (*ASIntent) SendMessage

func (as *ASIntent) SendMessage(ctx context.Context, roomID id.RoomID, eventType event.Type, content *event.Content, ts time.Time) (*mautrix.RespSendEvent, error)

func (*ASIntent) SendState

func (as *ASIntent) SendState(ctx context.Context, roomID id.RoomID, eventType event.Type, stateKey string, content *event.Content, ts time.Time) (*mautrix.RespSendEvent, error)

func (*ASIntent) SetAvatarURL

func (as *ASIntent) SetAvatarURL(ctx context.Context, avatarURL id.ContentURIString) error

func (*ASIntent) SetDisplayName

func (as *ASIntent) SetDisplayName(ctx context.Context, name string) error

func (*ASIntent) SetExtraProfileMeta

func (as *ASIntent) SetExtraProfileMeta(ctx context.Context, data any) error

func (*ASIntent) TagRoom

func (as *ASIntent) TagRoom(ctx context.Context, roomID id.RoomID, tag event.RoomTag, isTagged bool) error

func (*ASIntent) UploadMedia

func (as *ASIntent) UploadMedia(ctx context.Context, roomID id.RoomID, data []byte, fileName, mimeType string) (url id.ContentURIString, file *event.EncryptedFileInfo, err error)

type CommandProcessor

type CommandProcessor interface {
	Handle(ctx context.Context, roomID id.RoomID, eventID id.EventID, user bridgev2.User, message string, replyTo id.EventID)
}

type Connector

type Connector struct {
	AS           *appservice.AppService
	Bot          *appservice.IntentAPI
	StateStore   *sqlstatestore.SQLStateStore
	Crypto       Crypto
	Log          *zerolog.Logger
	Config       *bridgeconfig.Config
	Bridge       *bridgev2.Bridge
	Provisioning *ProvisioningAPI
	DoublePuppet *doublePuppetUtil
	MediaProxy   *mediaproxy.MediaProxy

	MediaConfig             mautrix.RespMediaConfig
	SpecVersions            *mautrix.RespVersions
	Capabilities            *bridgev2.MatrixCapabilities
	IgnoreUnsupportedServer bool

	EventProcessor *appservice.EventProcessor

	Websocket bool

	OnWebsocketReplaced func()
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(cfg *bridgeconfig.Config) *Connector

func (*Connector) BatchSend

func (br *Connector) BatchSend(ctx context.Context, roomID id.RoomID, req *mautrix.ReqBeeperBatchSend) (*mautrix.RespBeeperBatchSend, error)

func (*Connector) BotIntent

func (br *Connector) BotIntent() bridgev2.MatrixAPI

func (*Connector) FormatGhostMXID

func (br *Connector) FormatGhostMXID(userID networkid.UserID) id.UserID

func (*Connector) GenerateContentURI

func (br *Connector) GenerateContentURI(ctx context.Context, mediaID networkid.MediaID) (id.ContentURIString, error)

func (*Connector) GenerateDeterministicEventID

func (br *Connector) GenerateDeterministicEventID(roomID id.RoomID, _ networkid.PortalKey, messageID networkid.MessageID, partID networkid.PartID) id.EventID

func (*Connector) GetCapabilities

func (br *Connector) GetCapabilities() *bridgev2.MatrixCapabilities

func (*Connector) GetMemberInfo

func (br *Connector) GetMemberInfo(ctx context.Context, roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, error)

func (*Connector) GetMembers

func (br *Connector) GetMembers(ctx context.Context, roomID id.RoomID) (map[id.UserID]*event.MemberEventContent, error)

func (*Connector) GetPowerLevels

func (br *Connector) GetPowerLevels(ctx context.Context, roomID id.RoomID) (*event.PowerLevelsEventContent, error)

func (*Connector) GetProvisioning

func (br *Connector) GetProvisioning() IProvisioningAPI

func (*Connector) GetPublicAddress

func (br *Connector) GetPublicAddress() string

func (*Connector) GetRouter

func (br *Connector) GetRouter() *mux.Router

func (*Connector) GhostIntent

func (br *Connector) GhostIntent(userID networkid.UserID) bridgev2.MatrixAPI

func (*Connector) Init

func (br *Connector) Init(bridge *bridgev2.Bridge)

func (*Connector) NewUserIntent

func (br *Connector) NewUserIntent(ctx context.Context, userID id.UserID, accessToken string) (bridgev2.MatrixAPI, string, error)

func (*Connector) ParseGhostMXID

func (br *Connector) ParseGhostMXID(userID id.UserID) (networkid.UserID, bool)

func (*Connector) PingServer

func (br *Connector) PingServer() (start, serverTs, end time.Time)

func (*Connector) SendBridgeStatus

func (br *Connector) SendBridgeStatus(ctx context.Context, state *status.BridgeState) error

func (*Connector) SendMessageCheckpoints

func (br *Connector) SendMessageCheckpoints(checkpoints []*status.MessageCheckpoint) error

func (*Connector) SendMessageStatus

func (br *Connector) SendMessageStatus(ctx context.Context, ms *bridgev2.MessageStatus, evt *bridgev2.MessageStatusEventInfo)

func (*Connector) ServerName

func (br *Connector) ServerName() string

func (*Connector) Start

func (br *Connector) Start(ctx context.Context) error

func (*Connector) Stop

func (br *Connector) Stop()

func (*Connector) UpdateBotProfile

func (br *Connector) UpdateBotProfile(ctx context.Context)

type Crypto

type Crypto interface {
	HandleMemberEvent(context.Context, *event.Event)
	Decrypt(context.Context, *event.Event) (*event.Event, error)
	Encrypt(context.Context, id.RoomID, event.Type, *event.Content) error
	WaitForSession(context.Context, id.RoomID, id.SenderKey, id.SessionID, time.Duration) bool
	RequestSession(context.Context, id.RoomID, id.SenderKey, id.SessionID, id.UserID, id.DeviceID)
	ResetSession(context.Context, id.RoomID)
	Init(ctx context.Context) error
	Start()
	Stop()
	Reset(ctx context.Context, startAfterReset bool)
	Client() *mautrix.Client
	ShareKeys(context.Context) error
}

func NewCryptoHelper

func NewCryptoHelper(c *Connector) Crypto

type CryptoHelper

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

func (*CryptoHelper) Client

func (helper *CryptoHelper) Client() *mautrix.Client

func (*CryptoHelper) Decrypt

func (helper *CryptoHelper) Decrypt(ctx context.Context, evt *event.Event) (*event.Event, error)

func (*CryptoHelper) Encrypt

func (helper *CryptoHelper) Encrypt(ctx context.Context, roomID id.RoomID, evtType event.Type, content *event.Content) (err error)

func (*CryptoHelper) HandleMemberEvent

func (helper *CryptoHelper) HandleMemberEvent(ctx context.Context, evt *event.Event)

func (*CryptoHelper) Init

func (helper *CryptoHelper) Init(ctx context.Context) error

func (*CryptoHelper) RequestSession

func (helper *CryptoHelper) RequestSession(ctx context.Context, roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, userID id.UserID, deviceID id.DeviceID)

func (*CryptoHelper) Reset

func (helper *CryptoHelper) Reset(ctx context.Context, startAfterReset bool)

func (*CryptoHelper) ResetSession

func (helper *CryptoHelper) ResetSession(ctx context.Context, roomID id.RoomID)

func (*CryptoHelper) ShareKeys

func (helper *CryptoHelper) ShareKeys(ctx context.Context) error

ShareKeys uploads the given number of one-time-keys to the server.

func (*CryptoHelper) Start

func (helper *CryptoHelper) Start()

func (*CryptoHelper) Stop

func (helper *CryptoHelper) Stop()

func (*CryptoHelper) WaitForSession

func (helper *CryptoHelper) WaitForSession(ctx context.Context, roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, timeout time.Duration) bool

type IProvisioningAPI

type IProvisioningAPI interface {
	GetRouter() *mux.Router
	GetUser(r *http.Request) *bridgev2.User
}

type ProvLogin

type ProvLogin struct {
	ID       string
	Process  bridgev2.LoginProcess
	NextStep *bridgev2.LoginStep
	Lock     sync.Mutex
}

type ProvisioningAPI

type ProvisioningAPI struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

func (*ProvisioningAPI) AuthMiddleware

func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler

func (*ProvisioningAPI) GetContactList

func (prov *ProvisioningAPI) GetContactList(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) GetLoginFlows

func (prov *ProvisioningAPI) GetLoginFlows(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) GetLoginForRequest

func (prov *ProvisioningAPI) GetLoginForRequest(w http.ResponseWriter, r *http.Request) *bridgev2.UserLogin

func (*ProvisioningAPI) GetLogins

func (prov *ProvisioningAPI) GetLogins(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) GetResolveIdentifier

func (prov *ProvisioningAPI) GetResolveIdentifier(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) GetRouter

func (prov *ProvisioningAPI) GetRouter() *mux.Router

func (*ProvisioningAPI) GetUser

func (prov *ProvisioningAPI) GetUser(r *http.Request) *bridgev2.User

func (*ProvisioningAPI) Init

func (prov *ProvisioningAPI) Init()

func (*ProvisioningAPI) PostCreateDM

func (prov *ProvisioningAPI) PostCreateDM(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) PostCreateGroup

func (prov *ProvisioningAPI) PostCreateGroup(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) PostLoginStart

func (prov *ProvisioningAPI) PostLoginStart(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) PostLoginSubmitInput

func (prov *ProvisioningAPI) PostLoginSubmitInput(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) PostLoginWait

func (prov *ProvisioningAPI) PostLoginWait(w http.ResponseWriter, r *http.Request)

func (*ProvisioningAPI) PostLogout

func (prov *ProvisioningAPI) PostLogout(w http.ResponseWriter, r *http.Request)

type RespGetContactList

type RespGetContactList struct {
	Contacts []*RespResolveIdentifier `json:"contacts"`
}

type RespGetLogins

type RespGetLogins struct {
	LoginIDs []networkid.UserLoginID `json:"login_ids"`
}

type RespLoginFlows

type RespLoginFlows struct {
	Flows []bridgev2.LoginFlow `json:"flows"`
}

type RespResolveIdentifier

type RespResolveIdentifier struct {
	ID          networkid.UserID    `json:"id,omitempty"`
	Name        string              `json:"name,omitempty"`
	AvatarURL   id.ContentURIString `json:"avatar_url,omitempty"`
	Identifiers []string            `json:"identifiers,omitempty"`
	MXID        id.UserID           `json:"mxid,omitempty"`
	DMRoomID    id.RoomID           `json:"dm_room_mxid,omitempty"`
}

type RespSubmitLogin

type RespSubmitLogin struct {
	LoginID string `json:"login_id"`
	*bridgev2.LoginStep
}

type SQLCryptoStore

type SQLCryptoStore struct {
	*crypto.SQLCryptoStore
	UserID        id.UserID
	GhostIDFormat string
}

func NewSQLCryptoStore

func NewSQLCryptoStore(db *dbutil.Database, log dbutil.DatabaseLogger, accountID string, userID id.UserID, ghostIDFormat, pickleKey string) *SQLCryptoStore

func (*SQLCryptoStore) GetRoomJoinedOrInvitedMembers

func (store *SQLCryptoStore) GetRoomJoinedOrInvitedMembers(ctx context.Context, roomID id.RoomID) (members []id.UserID, err error)

Directories

Path Synopsis
Package mxmain contains initialization code for a single-network Matrix bridge using the bridgev2 package.
Package mxmain contains initialization code for a single-network Matrix bridge using the bridgev2 package.

Jump to

Keyboard shortcuts

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