users

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package users implements the server-side user whitelist: identification by handshake user hash, payload bandwidth limiting and wire traffic quota.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry resolves handshake user hashes to users. A nil Registry means "no whitelist".

func NewRegistry

func NewRegistry(cfgs []config.UserConfig) (*Registry, error)

func (*Registry) Lookup

func (r *Registry) Lookup(hash string) *User

Lookup returns the user for a hex handshake hash, or nil when it is not whitelisted.

func (*Registry) Stats

func (r *Registry) Stats() []Stat

Stats lists every user in config order.

func (*Registry) TrackUsage

func (r *Registry) TrackUsage(path string) (stop func(), err error)

TrackUsage restores this month's usage from path, saves it every minute and once more on stop, and resets every user when a new month begins. An empty path keeps usage in memory.

type Stat

type Stat struct {
	Name     string
	Blocked  bool
	Exceeded bool
	Conns    int    // open connections
	Up, Down uint64 // wire bytes from and to the client since start
	Used     uint64 // wire bytes this month, counted against Limit
	Limit    uint64 // bytes, 0 = unlimited
}

Stat is a point-in-time view of one user, for monitoring.

type User

type User struct {
	Alias   string
	Blocked bool
	// contains filtered or unexported fields
}

func (*User) Exceeded

func (u *User) Exceeded() bool

Exceeded reports whether the user's data quota is used up.

func (*User) WrapPayload

func (u *User) WrapPayload(conn net.Conn) net.Conn

WrapPayload throttles decoded payload to the user's bandwidth limits. It returns conn unchanged when the user has no limit.

func (*User) WrapWire

func (u *User) WrapWire(conn net.Conn) net.Conn

WrapWire counts every byte on conn (both directions) against the user's data quota.

type WireConn

type WireConn struct {
	net.Conn
	// contains filtered or unexported fields
}

WireConn counts wire bytes. Bytes seen before Bind (the handshake) are charged on Bind.

func NewWireConn

func NewWireConn(conn net.Conn) *WireConn

func (*WireConn) Bind

func (w *WireConn) Bind(u *User)

func (*WireConn) Close

func (w *WireConn) Close() error

func (*WireConn) CloseRead

func (w *WireConn) CloseRead() error

func (*WireConn) CloseWrite

func (w *WireConn) CloseWrite() error

func (*WireConn) Read

func (w *WireConn) Read(p []byte) (int, error)

func (*WireConn) Write

func (w *WireConn) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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