package autonatv2
import "time"
type autoNATSettings struct {
allowPrivateAddrs bool
serverRPM int
serverPerPeerRPM int
serverDialDataRPM int
maxConcurrentRequestsPerPeer int
dataRequestPolicy dataRequestPolicyFunc
now func () time .Time
amplificatonAttackPreventionDialWait time .Duration
metricsTracer MetricsTracer
throttlePeerDuration time .Duration
}
func defaultSettings() *autoNATSettings {
return &autoNATSettings {
allowPrivateAddrs : false ,
serverRPM : 60 ,
serverPerPeerRPM : 12 ,
serverDialDataRPM : 12 ,
maxConcurrentRequestsPerPeer : 2 ,
dataRequestPolicy : amplificationAttackPrevention ,
amplificatonAttackPreventionDialWait : 3 * time .Second ,
now : time .Now ,
throttlePeerDuration : defaultThrottlePeerDuration ,
}
}
type AutoNATOption func (s *autoNATSettings ) error
func WithServerRateLimit (rpm , perPeerRPM , dialDataRPM int , maxConcurrentRequestsPerPeer int ) AutoNATOption {
return func (s *autoNATSettings ) error {
s .serverRPM = rpm
s .serverPerPeerRPM = perPeerRPM
s .serverDialDataRPM = dialDataRPM
s .maxConcurrentRequestsPerPeer = maxConcurrentRequestsPerPeer
return nil
}
}
func WithMetricsTracer (m MetricsTracer ) AutoNATOption {
return func (s *autoNATSettings ) error {
s .metricsTracer = m
return nil
}
}
func withDataRequestPolicy(drp dataRequestPolicyFunc ) AutoNATOption {
return func (s *autoNATSettings ) error {
s .dataRequestPolicy = drp
return nil
}
}
func allowPrivateAddrs(s *autoNATSettings ) error {
s .allowPrivateAddrs = true
return nil
}
func withAmplificationAttackPreventionDialWait(d time .Duration ) AutoNATOption {
return func (s *autoNATSettings ) error {
s .amplificatonAttackPreventionDialWait = d
return nil
}
}
func withThrottlePeerDuration(d time .Duration ) AutoNATOption {
return func (s *autoNATSettings ) error {
s .throttlePeerDuration = d
return nil
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .