...

Package members

import "github.com/Diarkis/diarkis/members"
Overview
Index

Overview ▾

Index ▾

Constants
func EncodeClient(client *Client) string
func IsUserInRoom(name string, userData *user.User) bool
func ResetUser(name string, userData *user.User)
func UnlockExclusive(userData *user.User, key string)
type Client
    func DecodeClient(str string) *Client
type Members
    func New(name string) *Members
    func NewExclusive(name string) *Members
    func NewExclusiveLimited(name string, limit uint) *Members
    func NewLimited(name string, limit uint) *Members
    func (m *Members) Add(userData *user.User, meshAddr string) error
    func (m *Members) AddIf(userData *user.User, meshAddr string, check func() bool) error
    func (m *Members) AddReserve(userData *user.User) bool
    func (m *Members) AddReserveByUserID(userID string) bool
    func (m *Members) Count() int
    func (m *Members) Exists(userID string) bool
    func (m *Members) GetAll() map[string]*Client
    func (m *Members) GetExclusiveLockKey() string
    func (m *Members) GetLimit() int
    func (m *Members) GetName() string
    func (m *Members) GetOne(userID string) *Client
    func (m *Members) IsAddAllowed(clientsToBeAdded int) bool
    func (m *Members) Keys() []string
    func (m *Members) Remove(userData *user.User) bool
    func (m *Members) RemoveAll()
    func (m *Members) RemoveReserve(userData *user.User) bool
    func (m *Members) RemoveReserveByUserID(userID string) bool
    func (m *Members) UpdateClientByID(uid, sid, pubAddr string, privateAddrs []byte, meshAddr string) bool

Constants

NotLimited represents a members container has no member limit

const NotLimited = -1

Unexpected represents an unexpected error

const Unexpected = -2

func EncodeClient

func EncodeClient(client *Client) string

EncodeClient converts the client struct instance into a string. Use DecodeClient to revert it back to the client struct instance.

func IsUserInRoom

func IsUserInRoom(name string, userData *user.User) bool

IsUserInRoom returns true if the user with the matching name is in a members container.

func ResetUser

func ResetUser(name string, userData *user.User)

ResetUser resets the user key data with the matching name.

func UnlockExclusive

func UnlockExclusive(userData *user.User, key string)

UnlockExclusive forcefully unlocks members exclusive

type Client

Client is a representation of the user client with its IP addresses and IDs. The struct is derived from *user.User

type Client struct {
    SID      string
    ID       string
    MeshAddr string
    JoinedAt int64
    // Available for UDP only: P2P
    PublicAddr string
    // Available for UDP only: P2P
    PrivateAddrBytes []byte
    // User data copy
    UserData map[string]interface{}
}

func DecodeClient

func DecodeClient(str string) *Client

DecodeClient reverts back the encoded client struct instance. It returns a nil if the decoding fails.

type Members

Members a container to store member data. shard and storage are exclusive shard is used when the limit is -1 storage is used when the limit more than 0

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

func New

func New(name string) *Members

New creates a members container without a limit to the number of members.

func NewExclusive

func NewExclusive(name string) *Members

NewExclusive creates an exclusive members container that does NOT allow the same user to be in another members container without a limit to the number of members.

func NewExclusiveLimited

func NewExclusiveLimited(name string, limit uint) *Members

NewExclusiveLimited creates an exclusive members container that does NOT allow the same user to be in another members container with a limit to the number of members.

func NewLimited

func NewLimited(name string, limit uint) *Members

NewLimited creates a members container with a limit to the number of members.

func (*Members) Add

func (m *Members) Add(userData *user.User, meshAddr string) error

Add adds a userData.ID as key and userData.SID as value to the container.

func (*Members) AddIf

func (m *Members) AddIf(userData *user.User, meshAddr string, check func() bool) error

AddIf allows the user given to be added to the members if the given callback returns true.

func (*Members) AddReserve

func (m *Members) AddReserve(userData *user.User) bool

AddReserve makes a reservation for the given user to make sure that the user may join the members container later for sure.

func (*Members) AddReserveByUserID

func (m *Members) AddReserveByUserID(userID string) bool

AddReserveByUserID makes a reservation for the given user ID to make sure that the user may join the members container later for sure.

func (*Members) Count

func (m *Members) Count() int

Count returns the number of members in the container.

func (*Members) Exists

func (m *Members) Exists(userID string) bool

Exists returns true if the given key exists in the members container.

func (*Members) GetAll

func (m *Members) GetAll() map[string]*Client

GetAll returns all member SIDs as a map. The key of the map is user ID and the value of the map is user.

func (*Members) GetExclusiveLockKey

func (m *Members) GetExclusiveLockKey() string

GetExclusiveLockKey returns the key of user exclusive lock

func (*Members) GetLimit

func (m *Members) GetLimit() int

GetLimit returns the maximum allowed number of members.

[NOTE] If there is no limit, it returns NotLimited -1.
[NOTE] If *Member is somehow nil, it returns Unexpected -2.

func (*Members) GetName

func (m *Members) GetName() string

GetName returns the name of members container.

func (*Members) GetOne

func (m *Members) GetOne(userID string) *Client

GetOne returns the member user of the given user ID. If the key does not exist, it returns a nil instead.

func (*Members) IsAddAllowed

func (m *Members) IsAddAllowed(clientsToBeAdded int) bool

IsAddAllowed returns true if the members contain still has room to add more users.

func (*Members) Keys

func (m *Members) Keys() []string

Keys returns all member keys as an array. The keys are an array of user IDs.

func (*Members) Remove

func (m *Members) Remove(userData *user.User) bool

Remove removes a member data from the container.

func (*Members) RemoveAll

func (m *Members) RemoveAll()

RemoveAll removes all member users form the members container.

func (*Members) RemoveReserve

func (m *Members) RemoveReserve(userData *user.User) bool

RemoveReserve cancels the reservation for the given user.

func (*Members) RemoveReserveByUserID

func (m *Members) RemoveReserveByUserID(userID string) bool

RemoveReserveByUserID cancels the reservation for the given user ID.

func (*Members) UpdateClientByID

func (m *Members) UpdateClientByID(uid, sid, pubAddr string, privateAddrs []byte, meshAddr string) bool

UpdateClientByID updates internal client data