Add possibility to scale middleproxy buffers

This commit is contained in:
9seconds
2020-03-30 16:53:14 +03:00
parent 35f0fca3c5
commit b5a8d8b804
5 changed files with 52 additions and 9 deletions
+45
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"net"
"github.com/alecthomas/units"
@@ -104,6 +105,50 @@ type Config struct {
AdTag []byte `json:"adtag"`
}
func (c *Config) ClientReadBuffer() int {
return c.ReadBuffer
}
func (c *Config) ClientWriteBuffer() int {
return c.WriteBuffer
}
func (c *Config) MiddleProxyMode() bool {
return len(c.AdTag) > 0
}
func (c *Config) ProxyReadBuffer() int {
value := c.ReadBuffer
if c.MiddleProxyMode() {
value = c.adjustProxyValue(value)
}
return value
}
func (c *Config) ProxyWriteBuffer() int {
value := c.WriteBuffer
if c.MiddleProxyMode() {
value = c.adjustProxyValue(value)
}
return value
}
func (c *Config) adjustProxyValue(value int) int {
if c.MultiplexPerConnection == 0 {
return value
}
fvalue := float64(value)
newValue := fvalue * 1.5 * math.Log2(float64(c.MultiplexPerConnection))
newValue = math.Max(fvalue, math.Ceil(newValue))
return int(newValue)
}
type Opt struct {
Option OptionType
Value interface{}