mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 18:44:02 +03:00
Add possibility to scale middleproxy buffers
This commit is contained in:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user