Skip to content

Commit e3399b0

Browse files
committed
jslimit: upd doc
1 parent 5bdac67 commit e3399b0

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,43 @@ function getProxy(req, dst, username) {
378378
>
379379
> 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.
380380
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+
function bwLimit(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:
401+
402+
* **uploadBPS** *(Number)* - upload limit rate value.
403+
* **uploadBurst** *(Number)* - upload limit burst value.
404+
* **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+
381418
### Scripting functions
382419

383420
Following builtin functions are addionally available within JS scripts:
@@ -515,7 +552,7 @@ Usage of /home/user/go/bin/dumbproxy:
515552
allow multiple server instances on the same port
516553
-bind-unix-socket value
517554
Unix domain socket to listen to, overrides bind-address if set.
518-
-bw-limit uint
555+
-bw-limit value
519556
per-user bandwidth limit in bytes per second
520557
-bw-limit-burst int
521558
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:
555592
path to JS script file with the "access" filter function
556593
-js-access-filter-instances int
557594
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)
558599
-js-proxy-router value
559600
path to JS script file with the "getProxy" function
560601
-js-proxy-router-instances int
@@ -570,7 +611,7 @@ Usage of /home/user/go/bin/dumbproxy:
570611
-min-tls-version value
571612
minimum TLS version accepted by server (default TLS12)
572613
-mode value
573-
proxy operation mode (http/socks5/stdio) (default http)
614+
proxy operation mode (http/socks5/stdio/port-forward) (default http)
574615
-passwd string
575616
update given htpasswd file and add/set password for username. Username and password can be passed as positional arguments or requested interactively
576617
-passwd-cost int

0 commit comments

Comments
 (0)