You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-2Lines changed: 43 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -378,6 +378,43 @@ function getProxy(req, dst, username) {
378
378
>
379
379
> This shouldn't be much of concern, though, if `getProxy` function doesn't use dst.resolvedHost and returns consistent values across invocations with the rest of inputs having same values.
380
380
381
+
### Bandwidth limit definition by JS script
382
+
383
+
dumbproxy can retrieve bandwidth limit parameters defined by result of `bwLimit` JS function from file specified by `-js-bw-limit` option.
384
+
385
+
`bwLimit` function is invoked with the [same parameters](#access-filter-by-js-script) as the `access` function. But unlike `access` function it must return object defining bandwidth limit parameters.
386
+
387
+
Example, equivalent to `-bw-limit 100000 -bw-limit-burst 1000000`:
388
+
389
+
```js
390
+
functionbwLimit(req, dst, username) {
391
+
return {
392
+
uploadBPS:100000,
393
+
uploadBurst:1000000,
394
+
downloadBPS:100000,
395
+
downloadBurst:1000000,
396
+
};
397
+
}
398
+
```
399
+
400
+
Following properties of returned object are recognized:
***downloadBPS***(Number)* - download limit rate value. Ignored if `separate` property is false.
405
+
***downloadBurst***(Number)* - download limit burst value. Ignored if `separate` property is false.
406
+
***groupKey***(String)* - aggregation key for limits. All connections with the same `groupKey` value are accounted by one exact rate limit. If value is `null` or not set, username will be used as aggregation key.
407
+
***separate***(Boolean)* - account upload and download in separate limiters.
408
+
409
+
> [!NOTE]
410
+
> `bwLimit` can be invoked more than once per request.
411
+
412
+
> [!NOTE]
413
+
> Numeric values of limit parameters are used to (re-)create rate limit object, but do not update existing object unless it is evicted from cache naturally (which happens only if it has full bucket and no connections holding a shared lock on it).
414
+
415
+
> [!NOTE]
416
+
> `resolvedHost` property of destination address object is always null for `bwLimit` invocations because this information is not available in this context. Only `originalHost` and `port` are available.
417
+
381
418
### Scripting functions
382
419
383
420
Following builtin functions are addionally available within JS scripts:
@@ -515,7 +552,7 @@ Usage of /home/user/go/bin/dumbproxy:
515
552
allow multiple server instances on the same port
516
553
-bind-unix-socket value
517
554
Unix domain socket to listen to, overrides bind-address if set.
518
-
-bw-limit uint
555
+
-bw-limit value
519
556
per-user bandwidth limit in bytes per second
520
557
-bw-limit-burst int
521
558
allowed burst size for bandwidth limit, how many "tokens" can fit into leaky bucket
@@ -555,6 +592,10 @@ Usage of /home/user/go/bin/dumbproxy:
555
592
path to JS script file with the "access" filter function
556
593
-js-access-filter-instances int
557
594
number of JS VM instances to handle access filter requests (default 4)
595
+
-js-bw-limit value
596
+
path to JS script with "bwLimit" function. Overrides every other BW limit option
597
+
-js-bw-limit-instances int
598
+
number of JS VM instances to handle requests for BW limit parameters (default 4)
558
599
-js-proxy-router value
559
600
path to JS script file with the "getProxy" function
560
601
-js-proxy-router-instances int
@@ -570,7 +611,7 @@ Usage of /home/user/go/bin/dumbproxy:
570
611
-min-tls-version value
571
612
minimum TLS version accepted by server (default TLS12)
0 commit comments