-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
259 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package autonatv2 | ||
|
||
import "time" | ||
|
||
type autoNATSettings struct { | ||
allowAllAddrs bool | ||
serverRPM int | ||
serverRPMPerPeer int | ||
dataRequestPolicy dataRequestPolicyFunc | ||
now func() time.Time | ||
} | ||
|
||
func defaultSettings() *autoNATSettings { | ||
return &autoNATSettings{ | ||
allowAllAddrs: false, | ||
serverRPM: 20, | ||
serverRPMPerPeer: 2, | ||
dataRequestPolicy: defaultDataRequestPolicy, | ||
now: time.Now, | ||
} | ||
} | ||
|
||
type AutoNATOption func(s *autoNATSettings) error | ||
|
||
func allowAll(s *autoNATSettings) error { | ||
s.allowAllAddrs = true | ||
return nil | ||
} | ||
|
||
func WithServerRateLimit(rpm, rpmPerPeer int) AutoNATOption { | ||
return func(s *autoNATSettings) error { | ||
s.serverRPM = rpm | ||
s.serverRPMPerPeer = rpmPerPeer | ||
return nil | ||
} | ||
} | ||
|
||
func WithDataRequestPolicy(drp dataRequestPolicyFunc) AutoNATOption { | ||
return func(s *autoNATSettings) error { | ||
s.dataRequestPolicy = drp | ||
return nil | ||
} | ||
} | ||
|
||
func WithNow(now func() time.Time) AutoNATOption { | ||
return func(s *autoNATSettings) error { | ||
s.now = now | ||
return nil | ||
} | ||
} |
Oops, something went wrong.