types

package
v0.0.0-...-72cce0b Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PubContPort = 10050
	PubConvPort = 10051
)

Variables

This section is empty.

Functions

func CleanCallbacks

func CleanCallbacks()

func ConstructCommand

func ConstructCommand(message []byte, command Command) []byte

func Fingerprint

func Fingerprint(key ed25519.PublicKey) string

func HandleCommand

func HandleCommand(message *Message, room *Room) error

func RegisterCommand

func RegisterCommand(command Command, callback func(Command, *Message, *Room) error) error

func RegisterRoomCommands

func RegisterRoomCommands() error

func Sign

func Sign(key ed25519.PrivateKey, data []byte) []byte

func SyncMapsEqual

func SyncMapsEqual(map1, map2 SyncMap) bool

Types

type BlobMeta

type BlobMeta struct {
	ID   uuid.UUID `json:"uuid"`
	Name string    `json:"name,omitempty"`
	Type string    `json:"type,omitempty"`
	Size int       `json:"size,omitempty"`
}

type Command

type Command string
const (
	RoomCommandInvite     Command = "invite"
	RoomCommandNameRoom   Command = "name_room"
	RoomCommandNick       Command = "nick"
	RoomCommandPromote    Command = "promote"
	RoomCommandRemovePeer Command = "remove_peer"

	//This command is essentially a No-Op,
	//and is mainly used for indication in frontends
	RoomCommandAccept Command = "accept"

	CommandDelimiter = " "
)

type ContactRequest

type ContactRequest struct {
	RemoteFP string
	LocalFP  string
	ID       uuid.UUID
}

type ContactResponse

type ContactResponse struct {
	ConvFP string
	Sig    []byte
}

type ContentType

type ContentType string
const (
	ContentTypeText    ContentType = "mtype.text"
	ContentTypeCmd     ContentType = "mtype.cmd"
	ContentTypeFile    ContentType = "mtype.file"
	ContentTypeSticker ContentType = "mtype.sticker"
)

type Identity

type Identity struct {
	Type IdentityType `json:"type"`

	Priv *ed25519.PrivateKey `json:"priv,omitempty"`
	Pub  *ed25519.PublicKey  `json:"pub,omitempty"`

	Meta *IdentityMeta `json:"meta,omitempty"`
}

func NewIdentity

func NewIdentity(iType IdentityType, fingerprint string) (Identity, error)

func (Identity) Admin

func (i Identity) Admin() bool

func (Identity) Fingerprint

func (i Identity) Fingerprint() string

func (Identity) IsType

func (i Identity) IsType(toCheck ...IdentityType) bool

func (Identity) Nick

func (i Identity) Nick() string

func (Identity) ServiceID

func (i Identity) ServiceID() string

func (Identity) Sign

func (i Identity) Sign(data []byte) ([]byte, error)

func (Identity) String

func (i Identity) String() string

func (Identity) URL

func (i Identity) URL() string

func (Identity) Verify

func (i Identity) Verify(msg, sig []byte) (bool, error)

type IdentityMeta

type IdentityMeta struct {
	Nick  string `json:"nick"`
	Admin bool   `json:"admin"`
}

type IdentityType

type IdentityType string
const (
	Remote  IdentityType = "RemoteIdentity"
	Self    IdentityType = "SelfIdentity"
	Contact IdentityType = "ContactIdentity"
)

type Message

type Message struct {
	Meta    MessageMeta    `json:"meta"`
	Content MessageContent `json:"content"`
	Sig     []byte         `json:"sig"`
}

func NewMessage

func NewMessage(content MessageContent, sender Identity) Message

func (*Message) ContainsBlob

func (m *Message) ContainsBlob() bool

func (*Message) SigIsValid

func (m *Message) SigIsValid() bool

func (*Message) Sign

func (m *Message) Sign(key ed25519.PrivateKey)

type MessageContent

type MessageContent struct {
	Type    ContentType `json:"type"`
	ReplyTo *Message    `json:"replyto,omitempty"`
	Blob    *BlobMeta   `json:"blob,omitempty"`
	Data    []byte      `json:"data,omitempty"`
}

type MessageMeta

type MessageMeta struct {
	Sender string    `json:"sender"`
	Time   time.Time `json:"time"`
}

type MessagingPeer

type MessagingPeer struct {
	RIdentity     Identity `json:"identity"`
	LastSyncState SyncMap  `json:"lastSync"`

	Room *Room `json:"-"`
	// contains filtered or unexported fields
}

func NewMessagingPeer

func NewMessagingPeer(rid Identity) *MessagingPeer

func (*MessagingPeer) BumpQueue

func (mp *MessagingPeer) BumpQueue()

func (*MessagingPeer) RunMessageQueue

func (mp *MessagingPeer) RunMessageQueue(ctx context.Context, room *Room)

RunMessageQueue creates a cancellable context for the MessagingPeer and starts a loop that will try to send queued messages every so often.

func (*MessagingPeer) Stop

func (mp *MessagingPeer) Stop()

type Room

type Room struct {
	Self     Identity         `json:"self"`
	Peers    []*MessagingPeer `json:"peers"`
	ID       uuid.UUID        `json:"uuid"`
	Name     string           `json:"name"`
	Messages []Message        `json:"messages"`

	SyncState SyncMap `json:"lastMessage"`

	Ctx context.Context `json:"-"`
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(ctx context.Context, contactIdentities ...Identity) (*Room, error)

func (*Room) AddPeers

func (r *Room) AddPeers(contactIdentities ...Identity) error

AddPeers adds a user to the Room, and if successful syncs the PeerLists. If not successful returns the error.

func (*Room) Info

func (r *Room) Info() *RoomInfo

Info returns a struct with useful information about this Room

func (*Room) PeerByFingerprint

func (r *Room) PeerByFingerprint(fingerprint string) (Identity, bool)

func (*Room) PushMessages

func (r *Room) PushMessages(msgs ...Message) error

func (*Room) RunMessageQueueForAllPeers

func (r *Room) RunMessageQueueForAllPeers()

func (*Room) SendMessageToAllPeers

func (r *Room) SendMessageToAllPeers(content MessageContent)

func (*Room) SetContext

func (r *Room) SetContext(ctx context.Context) error

func (*Room) StopQueues

func (r *Room) StopQueues()

StopQueues cancels this context and with that all message queues of MessagingPeer's in this Room

type RoomInfo

type RoomInfo struct {
	Self   string            `json:"self"`
	Peers  []string          `json:"peers"`
	ID     uuid.UUID         `json:"uuid"`
	Name   string            `json:"name,omitempty"`
	Nicks  map[string]string `json:"nicks,omitempty"`
	Admins map[string]bool   `json:"admins,omitempty"`
}

type RoomRequest

type RoomRequest struct {
	Room           Room      `json:"room"`
	ViaFingerprint string    `json:"via"`
	ID             uuid.UUID `json:"uuid"`
}

type SyncMap

type SyncMap map[string]time.Time

func CopySyncMap

func CopySyncMap(m SyncMap) SyncMap

Jump to

Keyboard shortcuts

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