types

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeNow

func TimeNow() time.Time

Types

type AccessMode

type AccessMode uint
const (
	ModeJoin    AccessMode = 1 << iota // user can join, i.e. {sub} (J:1)
	ModeRead                           // user can receive broadcasts ({data}, {info}) (R:2)
	ModeWrite                          // user can Write, i.e. {pub} (W:4)
	ModePres                           // user can receive presence updates (P:8)
	ModeApprove                        // user can approve new members or evict existing members (A:0x10)
	ModeShare                          // user can invite new members (S:0x20)
	ModeDelete                         // user can hard-delete messages (D:0x40)
	ModeOwner                          // user is the owner (O:0x80) - full access
	ModeUnset                          // Non-zero value to indicate unknown or undefined mode (:0x100),

	ModeNone AccessMode = 0 // No access, requests to gain access are processed normally (N)

	// Normal user's access to a topic
	ModeCPublic AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeShare
	// User's subscription to 'me' and 'fnd' - user can only read and delete incoming invites
	ModeCSelf AccessMode = ModeJoin | ModeRead | ModeDelete | ModePres
	// Owner's subscription to a generic topic
	ModeCFull AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove | ModeShare | ModeDelete | ModeOwner
	// Default P2P access mode
	ModeCP2P AccessMode = ModeJoin | ModeRead | ModeWrite | ModePres | ModeApprove
	// Read-only access to topic (0x3)
	ModeCReadOnly = ModeJoin | ModeRead

	// Admin: user who can modify access mode (hex: 0x90, dec: 144)
	ModeCAdmin = ModeOwner | ModeApprove
	// Sharer: flags which define user who can be notified of access mode changes (dec: 176, hex: 0xB0)
	ModeCSharer = ModeCAdmin | ModeShare

	// Invalid mode to indicate an error
	ModeInvalid AccessMode = 0x100000
)

Various access mode constants

func (AccessMode) BetterEqual

func (grant AccessMode) BetterEqual(want AccessMode) bool

Check if grant mode allows all that was requested in want mode

func (AccessMode) Delta

func (o AccessMode) Delta(n AccessMode) string

Delta between two modes as a string old.Delta(new). JRPAS -> JRWS: "+W-PA" Zero delta is an empty string ""

func (AccessMode) IsAdmin

func (a AccessMode) IsAdmin() bool

Check if owner or approver

func (AccessMode) IsApprover

func (a AccessMode) IsApprover() bool

Check if approver

func (AccessMode) IsDeleter

func (a AccessMode) IsDeleter() bool

Check if user can hard-delete messages

func (AccessMode) IsInvalid

func (a AccessMode) IsInvalid() bool

Check if mode is invalid

func (AccessMode) IsJoiner

func (a AccessMode) IsJoiner() bool

Check if Join flag is set

func (AccessMode) IsOwner

func (a AccessMode) IsOwner() bool

Check if owner

func (AccessMode) IsPresencer

func (a AccessMode) IsPresencer() bool

Check if user recieves presence updates

func (AccessMode) IsReader

func (a AccessMode) IsReader() bool

Check if allowed to publish

func (AccessMode) IsSharer

func (a AccessMode) IsSharer() bool

Approver or sharer or owner

func (AccessMode) IsWriter

func (a AccessMode) IsWriter() bool

Check if allowed to publish

func (AccessMode) IsZero

func (a AccessMode) IsZero() bool

Check if not set

func (AccessMode) MarshalJSON

func (m AccessMode) MarshalJSON() ([]byte, error)

func (AccessMode) MarshalText

func (m AccessMode) MarshalText() ([]byte, error)

func (AccessMode) String

func (m AccessMode) String() string

func (*AccessMode) UnmarshalJSON

func (m *AccessMode) UnmarshalJSON(b []byte) error

func (*AccessMode) UnmarshalText

func (m *AccessMode) UnmarshalText(b []byte) error

Parse access mode string. Do not change the mode if the string is empty or invalid.

type BrowseOpt

type BrowseOpt struct {
	Since  int
	After  *time.Time
	Before int
	Until  *time.Time
	ByTime bool
	Limit  int
}

type Contact

type Contact struct {
	Id       string
	MatchOn  []string
	Access   DefaultAccess
	LastSeen time.Time
	Public   interface{}
}

Result of a search for connections

type DefaultAccess

type DefaultAccess struct {
	Auth AccessMode
	Anon AccessMode
}

Per-topic default access modes

type DeviceDef

type DeviceDef struct {
	// Device registration ID
	DeviceId string
	// Device platform (iOS, Android, Web)
	Platform string
	// Last logged in
	LastSeen time.Time
	// Device language, ISO code
	Lang string
}

Data provided by connected device. Used primarily for push notifications

type Message

type Message struct {
	ObjHeader
	// List of users who have marked this message as soft-deleted
	DeletedFor []SoftDelete
	SeqId      int
	Topic      string
	// UID as string of the user who sent the message, could be empty
	From    string
	Head    map[string]string
	Content interface{}
}

Stored {data} message

type ObjHeader

type ObjHeader struct {
	Id string // using string to get around rethinkdb's problems with unit64

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
	// contains filtered or unexported fields
}

Header shared by all stored objects

func (*ObjHeader) InitTimes

func (h *ObjHeader) InitTimes()

InitTimes initializes time.Time variables in the header to current time.

func (*ObjHeader) IsDeleted

func (h *ObjHeader) IsDeleted() bool

True if the object is deleted.

func (*ObjHeader) MergeTimes

func (h *ObjHeader) MergeTimes(h2 *ObjHeader)

InitTimes intelligently copies time.Time variables from h2 to h.

func (*ObjHeader) SetUid

func (h *ObjHeader) SetUid(uid Uid)

func (*ObjHeader) Uid

func (h *ObjHeader) Uid() Uid

type SoftDelete

type SoftDelete struct {
	User      string
	Timestamp time.Time
}

type Subscription

type Subscription struct {
	ObjHeader
	// User who has relationship with the topic
	User string
	// Topic subscribed to
	Topic string

	// Subscription state, currently unused
	State int

	// User soft-deleted messages equal or lower to this seq ID
	ClearId int
	// Last SeqId reported by user as received by at least one of his sessions
	RecvSeqId int
	// Last SeqID reported read by the user
	ReadSeqId int

	// Access mode requested by this user
	ModeWant AccessMode
	// Access mode granted to this user
	ModeGiven AccessMode
	// User's private data associated with the subscription to topic
	Private interface{}
	// contains filtered or unexported fields
}

Subscription to a topic

func (*Subscription) GetDefaultAccess

func (s *Subscription) GetDefaultAccess() *DefaultAccess

func (*Subscription) GetHardClearId

func (s *Subscription) GetHardClearId() int

func (*Subscription) GetLastSeen

func (s *Subscription) GetLastSeen() time.Time

func (*Subscription) GetPublic

func (s *Subscription) GetPublic() interface{}

func (*Subscription) GetSeqId

func (s *Subscription) GetSeqId() int

func (*Subscription) GetUserAgent

func (s *Subscription) GetUserAgent() string

func (*Subscription) GetWith

func (s *Subscription) GetWith() string

func (*Subscription) SetDefaultAccess

func (s *Subscription) SetDefaultAccess(auth, anon AccessMode)

func (*Subscription) SetHardClearId

func (s *Subscription) SetHardClearId(id int)

func (*Subscription) SetLastSeenAndUA

func (s *Subscription) SetLastSeenAndUA(when time.Time, ua string)

func (*Subscription) SetPublic

func (s *Subscription) SetPublic(pub interface{})

SetPublic assigns to public, otherwise not accessible from outside the package

func (*Subscription) SetSeqId

func (s *Subscription) SetSeqId(id int)

func (*Subscription) SetWith

func (s *Subscription) SetWith(with string)

type Topic

type Topic struct {
	ObjHeader
	State int

	// Use bearer token or use ACL
	UseBt bool

	// Default access to topic
	Access DefaultAccess

	// Server-issued sequential ID
	SeqId int
	// If messages were deleted, id of the last deleted message
	ClearId int

	Public interface{}
	// contains filtered or unexported fields
}

Topic stored in database

func (*Topic) GetAccess

func (t *Topic) GetAccess(uid Uid) (mode AccessMode)

func (*Topic) GetOwner

func (t *Topic) GetOwner() Uid

func (*Topic) GetPrivate

func (t *Topic) GetPrivate(uid Uid) (private interface{})

func (*Topic) GiveAccess

func (t *Topic) GiveAccess(uid Uid, want AccessMode, given AccessMode)

func (*Topic) SetPrivate

func (t *Topic) SetPrivate(uid Uid, private interface{})

type TopicAccess

type TopicAccess struct {
	User  string
	Topic string
	Want  AccessMode
	Given AccessMode
}

Relationship between users & topics, stored in database as Subscription

type TopicCat

type TopicCat int
const (
	TopicCat_Me TopicCat = iota
	TopicCat_Fnd
	TopicCat_P2P
	TopicCat_Grp
)

func GetTopicCat

func GetTopicCat(name string) TopicCat

type Uid

type Uid uint64

Uid is a database-specific record id, suitable to be used as a primary key.

var ZeroUid Uid = 0

func ParseP2P

func ParseP2P(p2p string) (uid1, uid2 Uid, err error)

ParseP2P extracts uids from the name of a p2p topic

func ParseUid

func ParseUid(s string) Uid

Parse UID parses string NOT prefixed with anything

func ParseUserId

func ParseUserId(s string) Uid

ParseUserId parses user ID of the form "usrXXXXXX"

func (Uid) Compare

func (uid Uid) Compare(u2 Uid) int

Compare returns 0 if uid is equal to u2, 1 if u2 is greater than uid, -1 if u2 is smaller

func (Uid) FndName

func (uid Uid) FndName() string

func (Uid) IsZero

func (uid Uid) IsZero() bool

func (*Uid) MarshalBinary

func (uid *Uid) MarshalBinary() ([]byte, error)

func (*Uid) MarshalJSON

func (uid *Uid) MarshalJSON() ([]byte, error)

func (*Uid) MarshalText

func (uid *Uid) MarshalText() ([]byte, error)

func (Uid) P2PName

func (uid Uid) P2PName(u2 Uid) string

Given two UIDs generate a P2P topic name

func (Uid) PrefixId

func (uid Uid) PrefixId(prefix string) string

func (Uid) String

func (uid Uid) String() string

func (*Uid) UnmarshalBinary

func (uid *Uid) UnmarshalBinary(b []byte) error

func (*Uid) UnmarshalJSON

func (uid *Uid) UnmarshalJSON(b []byte) error

func (*Uid) UnmarshalText

func (uid *Uid) UnmarshalText(src []byte) error

func (Uid) UserId

func (uid Uid) UserId() string

User ID prefixed with 'usr', like usrXXXXX

type UidGenerator

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

RethinkDB generates UUIDs as primary keys. Using snowflake-generated uint64 instead.

func (*UidGenerator) Get

func (ug *UidGenerator) Get() Uid

Get generates a unique weakly encryped id it so ids are random-looking.

func (*UidGenerator) GetStr

func (ug *UidGenerator) GetStr() string

GetStr generates a unique id then returns it as base64-encrypted string.

func (*UidGenerator) Init

func (ug *UidGenerator) Init(workerId uint, key []byte) error

Init initialises the Uid generator

type User

type User struct {
	ObjHeader
	// Currently unused: Unconfirmed, Active, etc.
	State int

	// Default access to user for P2P topics (used as default modeGiven)
	Access DefaultAccess

	// Values for 'me' topic:
	// Server-issued sequence ID for messages in 'me'
	SeqId int
	// If messages were hard-deleted in the topic, id of the last deleted message
	ClearId int
	// Last time when the user joined 'me' topic, by User Agent
	LastSeen time.Time
	// User agent provided when accessing the topic last time
	UserAgent string

	Public interface{}

	// Unique indexed tags (email, phone) for finding this user. Stored on the
	// 'users' as well as indexed in 'tagunique'
	Tags []string

	// Info on known devices, used for push notifications
	Devices map[string]*DeviceDef
}

Stored user

Jump to

Keyboard shortcuts

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