sid

package
v0.0.0-...-1af4f67 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sid Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license

Package sid Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HighSid

func HighSid(sid Sid) byte

HighSid returns a highest byte of a SID

func LowSid

func LowSid(sid Sid) byte

LowSid returns a lowest byte of a SID

func TokenA

func TokenA(token uint32) byte

TokenA returns the highest byte of a token

func TokenB

func TokenB(token uint32) byte

TokenB returns the second byte of a token

func TokenC

func TokenC(token uint32) byte

TokenC returns the first byte of a token

func TokenD

func TokenD(token uint32) byte

TokenD returns the lowest byte of a token

Types

type MailBox

type MailBox struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MailBox is a special container to accumulate "pending-to-send" data, in order to send N messages in a single UDP packet instead of N different messages. It will help to improve latency between client and server

func NewMailBox

func NewMailBox() *MailBox

NewMailBox creates a new instance of MailBox. Please don't create a MailBox manually.

func (*MailBox) Flush

func (box *MailBox) Flush() (sids []Sid, messages [][]byte)

Flush unpacks the MailBox to array of messages, so that each element of the array corresponds to a given Session ID. The length of result types "sids" and "messages" is guaranteed to be the same. This action will ERASE the MailBox (and theoretically it can be re-used again)

func (*MailBox) GetSids

func (box *MailBox) GetSids() []Sid

GetSids returns all the Session IDs, accumulated in the MailBox so far

func (*MailBox) Pick

func (box *MailBox) Pick(sid Sid) (res [][]byte)

Pick retrieves all messages for a given Session ID, but doesn't remove them from the MailBox

func (*MailBox) Put

func (box *MailBox) Put(sid Sid, msg []byte) *MailBox

Put adds new message for a given Session ID, thereby appends data at the end of the resulting message. You can call Put several times, and the order of messages will be preserved "sid" - MailBox key (because a MailBox can contain data for several SIDs) "msg" - message to be appended

func (*MailBox) Remove

func (box *MailBox) Remove(sid Sid)

Remove deletes all messages (as well as a prefix) for a given Session ID

func (*MailBox) SetPrefix

func (box *MailBox) SetPrefix(sid Sid, prefix []byte) *MailBox

SetPrefix assigns a new prefix for a given SID, thereby prepends data in the beginning of the resulting message. NOTE: the prefix is single, i.e. this action will overwrite the existing prefix. "sid" - MailBox key (because a MailBox can contain data for several SIDs) "prefix" - arbitrary byte array to be prepended

type Sid

type Sid uint16

Sid is a Session ID

type TSidManager

type TSidManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TSidManager responsible for a SID distribution This component is independent.

func (*TSidManager) FreeSid

func (mgr *TSidManager) FreeSid(sid Sid)

FreeSid releases the SID and brings it back to the pool

func (*TSidManager) GetSid

func (mgr *TSidManager) GetSid() (Sid, *Error)

GetSid returns an arbitrary free SID. You MUST release it after the use with FreeSid(). Method throws error in case of empty SID pool

func (*TSidManager) GetUsedSidsCount

func (mgr *TSidManager) GetUsedSidsCount() uint16

GetUsedSidsCount returns count of currently BUSY SIDs

type TokenManager

type TokenManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TokenManager responsible for generating new tokens. Token is designed for validation purposes only (not for security), because Session ID (2 bytes) is not enough to identify both user and its session. E.g. if a client has been re-connected, a new token should be generated for him. This component is independent.

func NewTokenManager

func NewTokenManager() *TokenManager

NewTokenManager creates a new instance of a TokenManager. Please don't create a TokenManager manually.

func (*TokenManager) GetToken

func (mgr *TokenManager) GetToken(sid Sid) (token uint32, ok bool)

GetToken returns a previously issued token by a given SID (if there are no match, returns "false")

func (*TokenManager) NewToken

func (mgr *TokenManager) NewToken(sid Sid) (token uint32)

NewToken generates a new randomly generated 32-bit token for a given SID (and stores it for the future reference)

Jump to

Keyboard shortcuts

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