Documentation
¶
Overview ¶
Package rate limits the bytes a client's connections transfer, on top of github.com/djylb/byterate.
Index ¶
- func GlobalLimit() int64
- func GlobalThroughput() (inBps, outBps int64)
- func GlobalTraffic() (in, out int64)
- func NewRateConn(conn io.ReadWriteCloser, r *Rate, entry ...*Directional) io.ReadWriteCloser
- func ResetGlobalTraffic()
- func RootGroup() *byterate.Group
- func SetGlobalLimit(limitBps int64)
- func SetGlobalTraffic(in, out int64)
- type Directional
- type Rate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GlobalLimit ¶ added in v0.34.9
func GlobalLimit() int64
GlobalLimit returns the limit of all forwarded traffic in bytes per second, or 0 if unlimited.
func GlobalThroughput ¶ added in v0.34.9
func GlobalThroughput() (inBps, outBps int64)
GlobalThroughput returns the forwarded bytes per second, in and out as GlobalTraffic counts them.
func GlobalTraffic ¶ added in v0.34.9
func GlobalTraffic() (in, out int64)
GlobalTraffic returns the bytes forwarded in total: in from visitors to clients, out from clients to visitors.
func NewRateConn ¶
func NewRateConn(conn io.ReadWriteCloser, r *Rate, entry ...*Directional) io.ReadWriteCloser
NewRateConn limits conn's reads and writes together by r and by the global limit and optional per-entry directional limits, and counts global traffic; conn is a connection to an npc. A net.Conn stays a net.Conn. A nil r leaves only the global limit. Close wakes a Read or Write waiting for a limit.
func ResetGlobalTraffic ¶ added in v0.34.9
func ResetGlobalTraffic()
ResetGlobalTraffic starts the totals over from zero.
func RootGroup ¶ added in v0.34.10
RootGroup is the server level shared by all client and resource groups.
func SetGlobalLimit ¶ added in v0.34.9
func SetGlobalLimit(limitBps int64)
SetGlobalLimit sets the limit of all forwarded traffic together, in bytes per second; 0 or less means unlimited. It applies to open connections too.
func SetGlobalTraffic ¶ added in v0.34.9
func SetGlobalTraffic(in, out int64)
SetGlobalTraffic makes in and out the totals, such as persisted ones, which do not count as new traffic in GlobalThroughput.
Types ¶
type Directional ¶ added in v0.34.10
type Directional struct {
// contains filtered or unexported fields
}
Directional shares independent visitor-to-backend and backend-to-visitor buckets across all connections belonging to one tunnel or domain entry.
func (*Directional) Group ¶ added in v0.34.10
func (d *Directional) Group(parent *byterate.Group) *byterate.Group
Group is the tunnel/domain level. A nil parent keeps its current ancestry.
func (*Directional) SetLimits ¶ added in v0.34.10
func (d *Directional) SetLimits(upload, download int64)
SetLimits updates both byte-per-second limits without replacing the buckets.
func (*Directional) Throughput ¶ added in v0.34.10
func (d *Directional) Throughput() (int64, int64)
Throughput returns current upload and download speeds in bytes per second.
type Rate ¶
type Rate struct {
// contains filtered or unexported fields
}
Rate is a byte rate limiter shared by all connections of a client: their reads and writes are charged to the same bucket. A limit <= 0 means unlimited. The zero value is an unlimited, running Rate.
Its JSON form is {"NowRate":...,"Limit":...}, the measured throughput and the limit in bytes per second. Decoding ignores both: they are runtime state, and the limit comes from the client's configuration.
func (*Rate) CurrentRates ¶ added in v0.34.10
CurrentRates reports visitor uploads and downloads, without changing the legacy combined limiter or its JSON representation.
func (*Rate) Group ¶ added in v0.34.10
Group is the client level, with a single combined rate and a global parent.
func (*Rate) Limit ¶ added in v0.33.13
Limit returns the limit in bytes per second, or 0 if unlimited.
func (*Rate) MarshalJSON ¶ added in v0.33.13
func (*Rate) ResetLimit ¶ added in v0.33.14
ResetLimit sets the limit, wakes waiting connections and starts over with a full burst.