hubs

package
v0.0.0-...-f701b90 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

This package implements all functionality for working with a concurrent access point for all common funcionality between clients.

Index

Constants

View Source
const MaxUserRequests int = 5

Max amount of requests that can be buffered, asocciated channel will block once this limit is reached.

Variables

This section is empty.

Functions

func Process

func Process(h *Hub, r Request, u User)

Check which action is asocciated to an operation and runs it, the request needs to have the necessary fields for the command to run, and the user should be retrieved using the Session() function.

func SendErrorPacket

func SendErrorPacket(id spec.ID, err error, cl net.Conn)

Auxiliary function to reduce code when sending errors.

func SendOKPacket

func SendOKPacket(id spec.ID, cl net.Conn)

Auxiliary function to reduce code when sending ok packets.

Types

type Hub

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

Main data structure that stores all information shared by all client connections. It is safe to use concurrently.

func NewHub

func NewHub(database *gorm.DB, cancel context.CancelFunc, size uint, motd string) *Hub

Initialises all data structures the hub needs to function: database, shutdown context and table sizes.

func (*Hub) Broadcast

func (hub *Hub) Broadcast(message string, sender User)

Sends a message to all users on the server, creating the corresponding RECIV for each user and encrypting the data correspondingly

func (*Hub) Cleanup

func (hub *Hub) Cleanup(cl net.Conn)

Removes all mentions of a user that just disconnected from the hub, except the reusable token if the connection is secure (condition that is not checked here).

func (*Hub) FindUser

func (hub *Hub) FindUser(uname string) (*User, bool)

Tries to find an online user, returning a boolean that indicates if it was found or not.

func (*Hub) Motd

func (hub *Hub) Motd() string

Returns the message of the day that is currently active

func (*Hub) Notify

func (hub *Hub) Notify(h spec.Hook, only net.Conn, args ...[]byte)

Notifies of a hook to all relevant connections. An optional connection can be provided to only notify the one specified, otherwise that argument should be nil. An optional list of arguments to be sent can also be provided. It is safe to run this function concurrently.

func (*Hub) Session

func (hub *Hub) Session(r Request) (*User, error)

Checks if a session is present in the hub (including the database) for a connection, and returns the corresponding user if so. If no user exists and it is applicable, a newly created user will be returned, which should be filled by the function processing the operation.

Returns a specification error

func (*Hub) Userlist

func (hub *Hub) Userlist(ulist spec.Userlist) (ret string)

Provides a list of all registered users, if the "online" parameter is true, it will only return online users. If no results are found, an empty string will be returned.

func (*Hub) Wait

func (hub *Hub) Wait(ctx context.Context, socks ...net.Listener)

Blocking function that waits until a shutdown is triggered, cleaning up all necessary resources and sockets, allowing for the caling function to safely exit the program.

type Request

type Request struct {
	Conn    net.Conn     // TCP Connection
	Command spec.Command // Entire command read from the connection
	TLS     bool         // Whether the connection is secure or not
}

Determines a request coming from a listening connection.

type User

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

Specifies a user that is connected/online. By design it is not safe to use concurrently, but it depends on how is is being used.

type Verif

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

Specifies a verification in process or a reusable token. It is not safe to use concurrently but it depends on how it is being used.

Jump to

Keyboard shortcuts

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