Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
discosrv
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ind.ie Projects
discosrv
Commits
7a7cccf1
Commit
7a7cccf1
authored
Jun 27, 2014
by
Jakob Borg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
discosrv: Tunable limiter settings
parent
e3154a0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
+18
-10
main.go
main.go
+18
-10
No files found.
main.go
View file @
7a7cccf1
...
...
@@ -32,15 +32,18 @@ type address struct {
}
var
(
nodes
=
make
(
map
[
string
]
node
)
lock
sync
.
Mutex
queries
=
0
announces
=
0
answered
=
0
limited
=
0
unknowns
=
0
debug
=
false
limiter
=
lru
.
New
(
1024
)
nodes
=
make
(
map
[
string
]
node
)
lock
sync
.
Mutex
queries
=
0
announces
=
0
answered
=
0
limited
=
0
unknowns
=
0
debug
=
false
lruSize
=
1024
limitAvg
=
1
limitBurst
=
10
limiter
*
lru
.
Cache
)
func
main
()
{
...
...
@@ -54,8 +57,13 @@ func main() {
flag
.
BoolVar
(
&
timestamp
,
"timestamp"
,
true
,
"Timestamp the log output"
)
flag
.
IntVar
(
&
statsIntv
,
"stats-intv"
,
0
,
"Statistics output interval (s)"
)
flag
.
StringVar
(
&
statsFile
,
"stats-file"
,
"/var/log/discosrv.stats"
,
"Statistics file name"
)
flag
.
IntVar
(
&
lruSize
,
"limit-cache"
,
lruSize
,
"Limiter cache entries"
)
flag
.
IntVar
(
&
limitAvg
,
"limit-avg"
,
limitAvg
,
"Allowed average package rate, per 10 s"
)
flag
.
IntVar
(
&
limitBurst
,
"limit-burst"
,
limitBurst
,
"Allowed burst size, packets"
)
flag
.
Parse
()
limiter
=
lru
.
New
(
lruSize
)
log
.
SetOutput
(
os
.
Stdout
)
if
!
timestamp
{
log
.
SetFlags
(
0
)
...
...
@@ -130,7 +138,7 @@ func limit(addr *net.UDPAddr) bool {
log
.
Println
(
"New limiter for"
,
key
)
}
// One packet per ten seconds average rate, burst ten packets
limiter
.
Add
(
key
,
ratelimit
.
NewBucket
(
10
*
time
.
Second
,
10
))
limiter
.
Add
(
key
,
ratelimit
.
NewBucket
(
10
*
time
.
Second
/
time
.
Duration
(
limitAvg
),
int64
(
limitBurst
)
))
}
return
false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment