Documentation
¶
Overview ¶
This package implements all functionality for working with a concurrent access point for all common funcionality between clients.
Index ¶
- Constants
- func Process(h *Hub, r Request, u User)
- func SendErrorPacket(id spec.ID, err error, cl net.Conn)
- func SendOKPacket(id spec.ID, cl net.Conn)
- type Hub
- func (hub *Hub) Broadcast(message string, sender User)
- func (hub *Hub) Cleanup(cl net.Conn)
- func (hub *Hub) FindUser(uname string) (*User, bool)
- func (hub *Hub) Motd() string
- func (hub *Hub) Notify(h spec.Hook, only net.Conn, args ...[]byte)
- func (hub *Hub) Session(r Request) (*User, error)
- func (hub *Hub) Userlist(ulist spec.Userlist) (ret string)
- func (hub *Hub) Wait(ctx context.Context, socks ...net.Listener)
- type Request
- type User
- type Verif
Constants ¶
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 ¶
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 ¶
Auxiliary function to reduce code when sending errors.
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 ¶
Initialises all data structures the hub needs to function: database, shutdown context and table sizes.
func (*Hub) Broadcast ¶
Sends a message to all users on the server, creating the corresponding RECIV for each user and encrypting the data correspondingly
func (*Hub) Cleanup ¶
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 ¶
Tries to find an online user, returning a boolean that indicates if it was found or not.
func (*Hub) Notify ¶
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 ¶
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
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.