memory

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "MEMORY"

Variables

This section is empty.

Functions

func NewAuthenticator

func NewAuthenticator(ctx context.Context) (statistic.Authenticator, error)

Types

type Authenticator

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

func (*Authenticator) AddUser

func (a *Authenticator) AddUser(hash string) error

func (*Authenticator) AuthUser

func (a *Authenticator) AuthUser(hash string) (bool, statistic.User)

func (*Authenticator) Close

func (a *Authenticator) Close() error

func (*Authenticator) DelUser

func (a *Authenticator) DelUser(hash string) error

func (*Authenticator) ListUsers

func (a *Authenticator) ListUsers() []statistic.User

func (*Authenticator) SetUserIPLimit

func (a *Authenticator) SetUserIPLimit(hash string, limit int) error

func (*Authenticator) SetUserQuota added in v1.1.1

func (a *Authenticator) SetUserQuota(hash string, quota int64) error

func (*Authenticator) SetUserSpeedLimit

func (a *Authenticator) SetUserSpeedLimit(hash string, send, recv int) error

func (*Authenticator) SetUserTraffic

func (a *Authenticator) SetUserTraffic(hash string, sent, recv uint64) error

type Config

type Config struct {
	Passwords []string `json:"password" yaml:"password"`
	Sqlite    string   `json:"sqlite" yaml:"sqlite"`
}

type User

type User struct {
	// WARNING: do not change the order of these fields.
	// 64-bit fields that use `sync/atomic` package functions
	// must be 64-bit aligned on 32-bit systems.
	// Reference: https://github.com/golang/go/issues/599
	// Solution: https://github.com/golang/go/issues/11891#issuecomment-433623786
	Sent uint64
	Recv uint64

	Hash string

	MaxIPNum int

	MaxConnNum int

	SendLimiter *rate.Limiter
	RecvLimiter *rate.Limiter
	// contains filtered or unexported fields
}

func (*User) AddIP

func (u *User) AddIP(ip string) bool

func (*User) AddRecvTraffic

func (u *User) AddRecvTraffic(recv int)

func (*User) AddSentTraffic

func (u *User) AddSentTraffic(sent int)

func (*User) Close

func (u *User) Close() error

func (*User) DelIP

func (u *User) DelIP(ip string) bool

func (*User) Done added in v1.2.0

func (u *User) Done() <-chan struct{}

Done satisfies statistic.Metadata. Returns a channel that is closed when the user is cut off — either because their quota was exceeded or because they were removed by the operator (DelUser / Close). Authenticator shutdown does NOT fire this channel; tunnel teardown during shutdown is handled by the normal connection-close path. Callers (typically a tunnel.Conn wrapper) can react to cutoff by closing the underlying transport so in-flight reads observe a closed-conn error.

func (*User) GetHash

func (u *User) GetHash() string

func (*User) GetIP

func (u *User) GetIP() int

func (*User) GetIPLimit

func (u *User) GetIPLimit() int

func (*User) GetQuota added in v1.1.1

func (u *User) GetQuota() int64

func (*User) GetSpeed

func (u *User) GetSpeed() (uint64, uint64)

func (*User) GetSpeedLimit

func (u *User) GetSpeedLimit() (send, recv int)

func (*User) GetTraffic

func (u *User) GetTraffic() (uint64, uint64)

func (*User) ResetTraffic

func (u *User) ResetTraffic() (uint64, uint64)

func (*User) SetQuota added in v1.1.1

func (u *User) SetQuota(quota int64)

func (*User) SetSpeedLimit

func (u *User) SetSpeedLimit(send, recv int)

Jump to

Keyboard shortcuts

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