docs(proxy): sharpen AX usage examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
8a52856719
commit
35db5f6840
1 changed files with 10 additions and 4 deletions
14
core_impl.go
14
core_impl.go
|
|
@ -295,7 +295,9 @@ func (cd *CustomDiff) OnLogin(e Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300})
|
// limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300})
|
||||||
// if limiter.Allow("203.0.113.42:3333") { /* accept the socket */ }
|
// if limiter.Allow("203.0.113.42:3333") {
|
||||||
|
// // first 30 connection attempts per minute are allowed
|
||||||
|
// }
|
||||||
func NewRateLimiter(config RateLimit) *RateLimiter {
|
func NewRateLimiter(config RateLimit) *RateLimiter {
|
||||||
return &RateLimiter{
|
return &RateLimiter{
|
||||||
config: config,
|
config: config,
|
||||||
|
|
@ -304,7 +306,9 @@ func NewRateLimiter(config RateLimit) *RateLimiter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if limiter.Allow("203.0.113.42:3333") { /* accept the socket */ }
|
// if limiter.Allow("203.0.113.42:3333") {
|
||||||
|
// // hostOnly("203.0.113.42:3333") == "203.0.113.42"
|
||||||
|
// }
|
||||||
func (rl *RateLimiter) Allow(ip string) bool {
|
func (rl *RateLimiter) Allow(ip string) bool {
|
||||||
if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 {
|
if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 {
|
||||||
return true
|
return true
|
||||||
|
|
@ -363,8 +367,10 @@ func (rl *RateLimiter) Tick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// watcher := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) { p.Reload(cfg) })
|
// watcher := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) {
|
||||||
// watcher.Start()
|
// p.Reload(cfg)
|
||||||
|
// })
|
||||||
|
// watcher.Start() // polls once per second and reloads after the file mtime changes
|
||||||
func NewConfigWatcher(configPath string, onChange func(*Config)) *ConfigWatcher {
|
func NewConfigWatcher(configPath string, onChange func(*Config)) *ConfigWatcher {
|
||||||
watcher := &ConfigWatcher{
|
watcher := &ConfigWatcher{
|
||||||
path: configPath,
|
path: configPath,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue