pipeshandler

package module
v0.0.0-...-3343934 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultClientEncodingMiddleware

func DefaultClientEncodingMiddleware(client *Client, message []byte) ([]byte, error)

Default pipes-fiber encoding middleware (using JSON)

func ErrorResponse

func ErrorResponse(ctx Context, err string)

func NormalResponse

func NormalResponse(ctx Context, data map[string]interface{})

func Response

func Response(client string, action string, data map[string]interface{}, local *pipes.LocalNode)

func StatusResponse

func StatusResponse(ctx Context, status string)

func SuccessResponse

func SuccessResponse(ctx Context)

Types

type Client

type Client struct {
	Conn    *websocket.Conn
	ID      string
	Session string
	End     time.Time
	Data    interface{}
	Mutex   *sync.Mutex
}

func (*Client) IsExpired

func (c *Client) IsExpired() bool

type Config

type Config struct {
	ExpectedConnections int64
	SessionDuration     time.Duration // How long a session should stay alive
	Secret              []byte        // JWT secret (for authorization)

	// Node handlers
	NodeDisconnectHandler func(node pipes.Node)

	// Client handlers
	ClientDisconnectHandler   func(client *Client)
	TokenValidateHandler      func(claims *ConnectionTokenClaims, attachments string) bool // Called before the websocket connection is accepted, returns if the client should be disconnected (true = disconnect)
	ClientConnectHandler      func(client *Client, attachments string) bool                // Called after websocket connection is established, returns if the client should be disconnected (true = disconnect)
	ClientEnterNetworkHandler func(client *Client, attachments string) bool                // Called after pipes adapter is registered, returns if the client should be disconnected (true = disconnect)

	// Codec middleware
	ClientEncodingMiddleware func(client *Client, instance *Instance, message []byte) ([]byte, error)
	DecodingMiddleware       func(client *Client, instance *Instance, message []byte) (Message, error)

	// Error handler
	ErrorHandler func(err error)
}

! If the functions aren't implemented pipesfiber will panic

type ConnectionTokenClaims

type ConnectionTokenClaims struct {
	Account        string `json:"acc"`  // Account id of the connecting client
	ExpiredUnixSec int64  `json:"e_u"`  // Expiration time in unix seconds
	Session        string `json:"ses"`  // Session id of the connecting client
	Node           string `json:"node"` // Node id of the node the client is connecting to

	jwt.RegisteredClaims
}

Connection token struct

func (ConnectionTokenClaims) ToClient

func (tk ConnectionTokenClaims) ToClient(conn *websocket.Conn, end time.Time) Client

type Context

type Context struct {
	Client *Client                `json:"client"`
	Action string                 `json:"action"` // The action to perform
	Data   map[string]interface{} `json:"data"`
	Node   *pipes.LocalNode       `json:"-"`
}

func (*Context) ValidateForm

func (ctx *Context) ValidateForm(fields ...string) bool

Returns true if one of the fields is not set

type Instance

type Instance struct {
	Config Config
	// contains filtered or unexported fields
}

func Setup

func Setup(config Config) *Instance

func (*Instance) AddClient

func (instance *Instance) AddClient(client Client) *Client

func (*Instance) CheckToken

func (instance *Instance) CheckToken(token string, local *pipes.LocalNode) (*ConnectionTokenClaims, bool)

Check the JWT token

func (*Instance) ExistsConnection

func (instance *Instance) ExistsConnection(id string, session string) bool

func (*Instance) Get

func (instance *Instance) Get(id string, session string) (*Client, bool)

func (*Instance) GetConnections

func (instance *Instance) GetConnections(id string) int

func (*Instance) GetSessions

func (instance *Instance) GetSessions(id string) []string

func (*Instance) Handle

func (instance *Instance) Handle(ctx Context) bool

func (*Instance) RegisterHandler

func (instance *Instance) RegisterHandler(action string, handler func(Context))

func (*Instance) Remove

func (instance *Instance) Remove(id string, session string)

func (*Instance) ReportClientError

func (instance *Instance) ReportClientError(client *Client, context string, err error)

func (*Instance) ReportGeneralError

func (instance *Instance) ReportGeneralError(context string, err error)

func (*Instance) Send

func (instance *Instance) Send(id string, msg []byte)

func (*Instance) SendEvent

func (instance *Instance) SendEvent(c *Client, event pipes.Event) error

func (*Instance) SendMessage

func (instance *Instance) SendMessage(conn *websocket.Conn, client *Client, msg []byte) error

func (*Instance) SendSession

func (instance *Instance) SendSession(id string, session string, msg []byte) bool

func (*Instance) SetupConnectionsCache

func (instance *Instance) SetupConnectionsCache(expected int64)

func (*Instance) UpdateClient

func (instance *Instance) UpdateClient(client *Client)

type Message

type Message struct {
	Action string                 `json:"action"`
	Data   map[string]interface{} `json:"data"`
}

Message received from the client

func DefaultDecodingMiddleware

func DefaultDecodingMiddleware(client *Client, bytes []byte) (Message, error)

Default pipes-fiber decoding middleware (using JSON)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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