matrixolm

package
v0.0.0-...-d87adc8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendToDeviceRoomID

func SendToDeviceRoomID(key olm.Curve25519) mat.RoomID

func SplitAlgorithmKeyID

func SplitAlgorithmKeyID(algorithmKeyID string) (string, string)

Types

type Ciphertext

type Ciphertext struct {
	Type olm.MsgType `json:"type"`
	Body string      `json:"body"`
}

TODO: Delete this

type Client

type Client struct {
	mat.Client
	Crypto *Container
	// contains filtered or unexported fields
}

func NewClient

func NewClient(homeserverURL, userID, deviceID, accessToken string, db Databaser,
	log Logger) (*Client, error)

func (*Client) DeviceKeysUpload

func (cli *Client) DeviceKeysUpload() error

TODO: Track how many unused keys are in the server, and find a mechanism to update them if necessary

func (*Client) SendImage

func (cli *Client) SendImage(roomID, body, url string) (*mat.RespSendEvent, error)

SendImage sends an m.room.message event into the given room with a msgtype of m.image See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image

func (*Client) SendMegolmOutKey

func (cli *Client) SendMegolmOutKey(device *Device, roomID mat.RoomID,
	session *olm.OutboundGroupSession) error

func (*Client) SendMessageEvent

func (cli *Client) SendMessageEvent(roomID string, eventType string,
	contentJSON interface{}) (*mat.RespSendEvent, error)

SendMessageEvent sends a message event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.

func (*Client) SendNotice

func (cli *Client) SendNotice(roomID, text string) (*mat.RespSendEvent, error)

SendNotice sends an m.room.message event into the given room with a msgtype of m.notice See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice

func (*Client) SendText

func (cli *Client) SendText(roomID, text string) (*mat.RespSendEvent, error)

SendText sends an m.room.message event into the given room with a msgtype of m.text See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-text

func (*Client) SendVideo

func (cli *Client) SendVideo(roomID, body, url string) (*mat.RespSendEvent, error)

SendVideo sends an m.room.message event into the given room with a msgtype of m.video See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-video

func (*Client) SetRoomEncryption

func (cli *Client) SetRoomEncryption(roomID string, encryptionAlg olm.Algorithm) error

SetRoomEncryption sends the event to set the encryption Algorithm of the room and sets it in the internal state.

func (*Client) SetRoomEncryptionMegolm

func (cli *Client) SetRoomEncryptionMegolm(roomID string) error

SetRoomEncryptionMegolm calls SetRoomEncryption with the Megolm algorithm, which is the most common one for rooms.

func (*Client) SyncRequest

func (cli *Client) SyncRequest(timeout int, since, filterID string, fullState bool, setPresence string) (resp *RespSync, err error)

SyncRequest makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync

func (*Client) UserDevice

func (cli *Client) UserDevice(userID mat.UserID, deviceKey olm.Curve25519) (*Device, error)

func (*Client) UserDevices

func (cli *Client) UserDevices(userID mat.UserID) (*UserDevices, error)

type Container

type Container struct {
	Me *MyUserDevice
	// contains filtered or unexported fields
}

Container contains data structures that are completely or partly permanent (backed by a data base).

func LoadContainer

func LoadContainer(userID mat.UserID, deviceID mat.DeviceID, db Databaser) (*Container, error)

LoadContainer loads the Container datastructure. It sets up the database and loads its contents into the rest of the datastructure.

func (*Container) Close

func (c *Container) Close()

func (*Container) ForEachRoom

func (c *Container) ForEachRoom(fn func(rID mat.RoomID, r *Room) error) (err error)

func (*Container) ForEachUser

func (c *Container) ForEachUser(fn func(uID mat.UserID, ud *UserDevices) error) (err error)

func (*Container) NewRoom

func (c *Container) NewRoom(roomID mat.RoomID) *Room

func (*Container) Room

func (c *Container) Room(roomID mat.RoomID) (room *Room)

Room gets or creates (if it doesn't exist) a Room and returns it

type ContentRoomMember

type ContentRoomMember struct {
	DisplayName string `json:"displayname"`
	Membership  string `json:"membership"`
}

type CryptoDB

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

func OpenCryptoDB

func OpenCryptoDB(filename string) (*CryptoDB, error)

OpenCryptoDB opens the DB and initializes the /crypto bucket if necessary

func (*CryptoDB) AddMyUserMyDevice

func (cdb *CryptoDB) AddMyUserMyDevice(userID mat.UserID, deviceID mat.DeviceID) error

AddMyUserMyDevice adds /crypto_me/<userID>/<deviceID>/megolm_out/ buckets

func (*CryptoDB) AddUser

func (cdb *CryptoDB) AddUser(userID mat.UserID) error

AddUser adds /crypto_users/<userID>/ bucket

func (*CryptoDB) AddUserDevice

func (cdb *CryptoDB) AddUserDevice(userID mat.UserID, deviceID mat.DeviceID) error

AddUserDevice adds /crypto_users/<userID>/devices/<deviceID>/{olm,megolm_in,shared_megolm}/ buckets

func (*CryptoDB) Close

func (cdb *CryptoDB) Close()

Close closes the DB

func (*CryptoDB) ExistsOlmAccount

func (cdb *CryptoDB) ExistsOlmAccount(userID mat.UserID, deviceID mat.DeviceID) bool

ExistsOlmAccount checks if an olm.Account exists at /crypto_me/<userID>/<deviceID>/

func (*CryptoDB) LoadAllUserDevices

func (cdb *CryptoDB) LoadAllUserDevices() (map[mat.UserID]*UserDevices, error)

LoadAllUserDevices loads all the UserDevices from /crypto_users/

func (*CryptoDB) LoadMapSessionsID

func (cdb *CryptoDB) LoadMapSessionsID() (*RoomsSessionsID, error)

LoadMapSessionsID loads all the RoomsSessionsID at /crypto_sessions_id/

func (*CryptoDB) LoadMyUserDevice

func (cdb *CryptoDB) LoadMyUserDevice(userID mat.UserID) (*MyUserDevice, error)

LoadMyUserDevice loads the MyUserDevice at /crypto_me/<userID>/

func (*CryptoDB) LoadRooms

func (cdb *CryptoDB) LoadRooms() (map[mat.RoomID]*Room, error)

func (*CryptoDB) SetSharedMegolmOutKey

func (cdb *CryptoDB) SetSharedMegolmOutKey(userID mat.UserID, deviceID mat.DeviceID,
	sessionID olm.SessionID) error

func (*CryptoDB) StoreMegolmInSession

func (cdb *CryptoDB) StoreMegolmInSession(userID mat.UserID, deviceID mat.DeviceID,
	megolmInSession *olm.InboundGroupSession) error

StoreMegolmInSession stores an olm.InboundGroupSession at /crypto_users/<userID>/devices/<deviceID>/megolm_in/<megolmInSession.ID>

func (*CryptoDB) StoreMegolmInSessionID

func (cdb *CryptoDB) StoreMegolmInSessionID(roomID mat.RoomID, userID mat.UserID,
	key olm.Curve25519, sessionID olm.SessionID) error

StoreMegolmInSessionID stores an olm.Account at /crypto_sessions_id/SessionTriplet{roomID,userID,deviceID}/megolm_session_id

func (*CryptoDB) StoreMegolmOutSession

func (cdb *CryptoDB) StoreMegolmOutSession(userID mat.UserID, deviceID mat.DeviceID,
	megolmOutSession *olm.OutboundGroupSession) error

StoreMegolmOutSession stores an olm.OutboundGroupSession at /crypto_me/<userID>/<deviceID>/megolm_out/<megolmOutSession.ID>

func (*CryptoDB) StoreOlmAccount

func (cdb *CryptoDB) StoreOlmAccount(userID mat.UserID, deviceID mat.DeviceID, olmAccount *olm.Account) error

StoreOlmAccount stores an olm.Account at /crypto_me/<userID>/<deviceID>/

func (*CryptoDB) StoreOlmSession

func (cdb *CryptoDB) StoreOlmSession(userID mat.UserID, deviceID mat.DeviceID,
	olmSession *olm.Session) error

StoreOlmSession stores an olm.Session at /crypto_users/<userID>/devices/<deviceID>/olm/<olmSession.ID>

func (*CryptoDB) StoreOlmSessionID

func (cdb *CryptoDB) StoreOlmSessionID(roomID mat.RoomID, userID mat.UserID, key olm.Curve25519,
	sessionID olm.SessionID) error

StoreOlmSessionID stores an olm SessionID at /crypto_sessions_id/SessionTriplet{roomID,userID,deviceID}/olm_session_id

func (*CryptoDB) StorePubKeys

func (cdb *CryptoDB) StorePubKeys(userID mat.UserID, deviceID mat.DeviceID,
	ed25519 olm.Ed25519, curve25519 olm.Curve25519) error

StorePubKeys stores the ed25519 and curve25519 public keys at /crypto_users/<userID>/devices/<deviceID>/

func (*CryptoDB) StoreRoomEncryptionAlg

func (cdb *CryptoDB) StoreRoomEncryptionAlg(roomID mat.RoomID, encryptionAlg olm.Algorithm) error

type Databaser

type Databaser interface {
	Close()
	AddUser(userID mat.UserID) error
	AddUserDevice(userID mat.UserID, deviceID mat.DeviceID) error
	AddMyUserMyDevice(userID mat.UserID, deviceID mat.DeviceID) error
	StorePubKeys(userID mat.UserID, deviceID mat.DeviceID,
		ed25519 olm.Ed25519, curve25519 olm.Curve25519) error
	StoreOlmSession(userID mat.UserID, deviceID mat.DeviceID,
		olmSession *olm.Session) error
	StoreMegolmInSession(userID mat.UserID, deviceID mat.DeviceID,
		megolmInSession *olm.InboundGroupSession) error
	SetSharedMegolmOutKey(userID mat.UserID, deviceID mat.DeviceID,
		sessionID olm.SessionID) error
	StoreMegolmOutSession(userID mat.UserID, deviceID mat.DeviceID,
		megolmOutSession *olm.OutboundGroupSession) error
	LoadAllUserDevices() (map[mat.UserID]*UserDevices, error)
	LoadMyUserDevice(userID mat.UserID) (*MyUserDevice, error)
	ExistsOlmAccount(userID mat.UserID, deviceID mat.DeviceID) bool
	StoreOlmAccount(userID mat.UserID, deviceID mat.DeviceID, olmAccount *olm.Account) error
	StoreOlmSessionID(roomID mat.RoomID, userID mat.UserID, key olm.Curve25519,
		sessionID olm.SessionID) error
	StoreMegolmInSessionID(roomID mat.RoomID, userID mat.UserID, key olm.Curve25519,
		sessionID olm.SessionID) error
	LoadMapSessionsID() (*RoomsSessionsID, error)
	LoadRooms() (map[mat.RoomID]*Room, error)
	StoreRoomEncryptionAlg(roomID mat.RoomID, encryptionAlg olm.Algorithm) error
}

type DecryptedEvent

type DecryptedEvent struct {
	Error error
	Event *Event
}

type Device

type Device struct {

	//OneTimeKey       string                              // IdentityKey
	OlmSessions      map[olm.SessionID]*olm.Session
	MegolmInSessions map[olm.SessionID]*olm.InboundGroupSession
	// contains filtered or unexported fields
}

func (*Device) Curve25519

func (d *Device) Curve25519() olm.Curve25519

func (*Device) Ed25519

func (d *Device) Ed25519() olm.Ed25519

func (*Device) ID

func (d *Device) ID() mat.DeviceID

func (*Device) String

func (d *Device) String() string

func (*Device) UserID

func (d *Device) UserID() mat.UserID

type Event

type Event struct {
	mat.Event
	Decrypted *DecryptedEvent `json:"-"`
}

Event represents a single Matrix event.

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

type MegolmMsg

type MegolmMsg struct {
	Algorithm  olm.Algorithm  `json:"algorithm"`
	Ciphertext string         `json:"ciphertext"`
	DeviceID   mat.DeviceID   `json:"device_id"`
	SenderKey  olm.Curve25519 `json:"sender_key"`
	SessionID  olm.SessionID  `json:"session_id"`
}

type Membership

type Membership int
const (
	MemInvite     Membership = iota
	MemJoin       Membership = iota
	MemLeave      Membership = iota
	MemBan        Membership = iota
	MembershipLen Membership = iota
)

type MyDevice

type MyDevice struct {
	ID mat.DeviceID

	OlmAccount *olm.Account
	//OlmSessions       map[string]*olm.Session              // key:room_id
	MegolmOutSessions map[mat.RoomID]*olm.OutboundGroupSession
	// contains filtered or unexported fields
}

type MyUserDevice

type MyUserDevice struct {
	ID     mat.UserID
	Device *MyDevice
}

type OlmMsg

type OlmMsg struct {
	Algorithm  olm.Algorithm  `json:"algorithm"`
	SenderKey  olm.Curve25519 `json:"sender_key"`
	Ciphertext map[olm.Curve25519]struct {
		Type olm.MsgType `json:"type"`
		Body string      `json:"body"`
	} `json:"ciphertext"`
}

type RespSync

type RespSync struct {
	NextBatch   string `json:"next_batch"`
	AccountData struct {
		Events []Event `json:"events"`
	} `json:"account_data"`
	Presence struct {
		Events []Event `json:"events"`
	} `json:"presence"`
	Rooms struct {
		Leave map[string]struct {
			State struct {
				Events []Event `json:"events"`
			} `json:"state"`
			Timeline struct {
				Events    []Event `json:"events"`
				Limited   bool    `json:"limited"`
				PrevBatch string  `json:"prev_batch"`
			} `json:"timeline"`
		} `json:"leave"`
		Join map[string]struct {
			State struct {
				Events []Event `json:"events"`
			} `json:"state"`
			Timeline struct {
				Events    []Event `json:"events"`
				Limited   bool    `json:"limited"`
				PrevBatch string  `json:"prev_batch"`
			} `json:"timeline"`
		} `json:"join"`
		Invite map[string]struct {
			State struct {
				Events []Event
			} `json:"invite_state"`
		} `json:"invite"`
	} `json:"rooms"`
	ToDevice struct {
		Events []SendToDeviceEvent `json:"events"`
	} `json:"to_device"`
}

RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync

type Room

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

func (*Room) ForEachUser

func (r *Room) ForEachUser(mem Membership, fn func(uID mat.UserID, u *User) error) (err error)

func (*Room) ID

func (r *Room) ID() mat.RoomID

func (*Room) SetUserMembership

func (r *Room) SetUserMembership(userID mat.UserID, mem Membership)

type RoomKey

type RoomKey struct {
	// OlmSenderKey is filled when this event is obtained through the
	// decryption of an m.room.encrypted event.
	OlmSenderKey olm.Curve25519
	Algorithm    olm.Algorithm `json:"algorithm"`
	RoomID       mat.RoomID    `json:"room_id"`
	SessionID    olm.SessionID `json:"session_id"`
	SessionKey   string        `json:"session_key"`
}

type RoomsSessionsID

type RoomsSessionsID struct {
	Sessions map[SessionTriplet]*SessionsID
}

RoomsSessionsID maps (RoomID, UserID, Curve25519) to (olmSessionID, megolmInSessionID)

func (*RoomsSessionsID) GetOlmSessionID

func (rs *RoomsSessionsID) GetOlmSessionID(roomID mat.RoomID, userID mat.UserID, key olm.Curve25519) olm.SessionID

type SendEncEventError

type SendEncEventError struct {
	UserID   mat.UserID
	DeviceID mat.DeviceID
	//Content  interface{}
	Err error
}

func (*SendEncEventError) Error

func (err *SendEncEventError) Error() string

type SendEncEventErrors

type SendEncEventErrors []SendEncEventError

func (SendEncEventErrors) Error

func (errs SendEncEventErrors) Error() string

type SendToDeviceEvent

type SendToDeviceEvent struct {
	mat.SendToDeviceEvent
	Decrypted *DecryptedEvent `json:"-"`
}

SendToDeviceEvent represents an event received through the send-to-device API: https://matrix.org/speculator/spec/drafts%2Fe2e/client_server/unstable.html#extensions-to-sync

type SessionTriplet

type SessionTriplet struct {
	RoomID mat.RoomID
	UserID mat.UserID
	Key    olm.Curve25519
}

type SessionsID

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

type SignedKey

type SignedKey struct {
	Key        olm.Curve25519               `json:"key"`
	Signatures map[string]map[string]string `json:"signatures"`
}

type User

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

func NewUser

func NewUser(userID mat.UserID) *User

func (*User) ID

func (u *User) ID() mat.UserID

type UserDevices

type UserDevices struct {
	Devices     map[olm.Curve25519]*Device
	DevicesByID map[mat.DeviceID]*Device
	// contains filtered or unexported fields
}

func NewUserDevices

func NewUserDevices(userID mat.UserID) *UserDevices

func (*UserDevices) ForEach

func (ud *UserDevices) ForEach(fn func(k olm.Curve25519, d *Device) error) (err error)

func (*UserDevices) ID

func (ud *UserDevices) ID() mat.UserID

Jump to

Keyboard shortcuts

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