44 "flag"
55 "fmt"
66 "log"
7- "math"
87 "net"
98 "net/http"
109 "net/http/pprof"
@@ -90,13 +89,15 @@ func main() {
9089 }
9190 log .Println ("main: domain server is" , * flDnserv )
9291 }
92+ rateLimits := func () * rate.Limits {
93+ log .Println ("main: bandwidth is set" , * flLimits )
94+ return rate .NewLimits (daze .SizeParser (* flLimits ), time .Second )
95+ }
9396 switch * flProtoc {
9497 case "ashe" :
9598 server := ashe .NewServer (* flListen , * flCipher )
9699 if * flLimits != "" {
97- n := daze .SizeParser (* flLimits )
98- doa .Doa (n <= math .MaxInt )
99- server .Limits = rate .NewLimits (n , time .Second )
100+ server .Limits = rateLimits ()
100101 }
101102 defer server .Close ()
102103 doa .Nil (server .Run ())
@@ -106,27 +107,21 @@ func main() {
106107 server .Masker = * flExtend
107108 }
108109 if * flLimits != "" {
109- n := daze .SizeParser (* flLimits )
110- doa .Doa (n <= math .MaxInt )
111- server .Limits = rate .NewLimits (n , time .Second )
110+ server .Limits = rateLimits ()
112111 }
113112 defer server .Close ()
114113 doa .Nil (server .Run ())
115114 case "czar" :
116115 server := czar .NewServer (* flListen , * flCipher )
117116 if * flLimits != "" {
118- n := daze .SizeParser (* flLimits )
119- doa .Doa (n <= math .MaxInt )
120- server .Limits = rate .NewLimits (n , time .Second )
117+ server .Limits = rateLimits ()
121118 }
122119 defer server .Close ()
123120 doa .Nil (server .Run ())
124121 case "dahlia" :
125122 server := dahlia .NewServer (* flListen , * flExtend , * flCipher )
126123 if * flLimits != "" {
127- n := daze .SizeParser (* flLimits )
128- doa .Doa (n <= math .MaxInt )
129- server .Limits = rate .NewLimits (n , time .Second )
124+ server .Limits = rateLimits ()
130125 }
131126 defer server .Close ()
132127 doa .Nil (server .Run ())
@@ -167,6 +162,10 @@ func main() {
167162 }
168163 log .Println ("main: domain server is" , * flDnserv )
169164 }
165+ rateLimits := func () * rate.Limits {
166+ log .Println ("main: bandwidth is set" , * flLimits )
167+ return rate .NewLimits (daze .SizeParser (* flLimits ), time .Second )
168+ }
170169 switch * flProtoc {
171170 case "ashe" :
172171 client := ashe .NewClient (* flServer , * flCipher )
@@ -176,9 +175,7 @@ func main() {
176175 Cidr : * flCidrls ,
177176 }))
178177 if * flLimits != "" {
179- n := daze .SizeParser (* flLimits )
180- doa .Doa (n <= math .MaxInt )
181- locale .Limits = rate .NewLimits (n , time .Second )
178+ locale .Limits = rateLimits ()
182179 }
183180 defer locale .Close ()
184181 doa .Nil (locale .Run ())
@@ -190,9 +187,7 @@ func main() {
190187 Cidr : * flCidrls ,
191188 }))
192189 if * flLimits != "" {
193- n := daze .SizeParser (* flLimits )
194- doa .Doa (n <= math .MaxInt )
195- locale .Limits = rate .NewLimits (n , time .Second )
190+ locale .Limits = rateLimits ()
196191 }
197192 defer locale .Close ()
198193 doa .Nil (locale .Run ())
@@ -205,18 +200,14 @@ func main() {
205200 Cidr : * flCidrls ,
206201 }))
207202 if * flLimits != "" {
208- n := daze .SizeParser (* flLimits )
209- doa .Doa (n <= math .MaxInt )
210- locale .Limits = rate .NewLimits (n , time .Second )
203+ locale .Limits = rateLimits ()
211204 }
212205 defer locale .Close ()
213206 doa .Nil (locale .Run ())
214207 case "dahlia" :
215208 client := dahlia .NewClient (* flListen , * flServer , * flCipher )
216209 if * flLimits != "" {
217- n := daze .SizeParser (* flLimits )
218- doa .Doa (n <= math .MaxInt )
219- client .Limits = rate .NewLimits (n , time .Second )
210+ client .Limits = rateLimits ()
220211 }
221212 defer client .Close ()
222213 doa .Nil (client .Run ())
0 commit comments