mirror of
https://github.com/fatedier/frp.git
synced 2026-03-21 09:19:19 +08:00
support bandwidth_limit set by server plugin (#3271)
* support bandwidth_limit set by server plugin * limiter at proxy level * bandwidth_limit_mode * updates tests for bandwidth_limit_mode default * bandwidth_limit_mode as string * add checkForSrv for bandwidth_limit_mode * bandwidth_limit flags for sub cmds * gci write
This commit is contained in:
@@ -141,6 +141,10 @@ type BaseProxyConf struct {
|
||||
// BandwidthLimit limit the bandwidth
|
||||
// 0 means no limit
|
||||
BandwidthLimit BandwidthQuantity `ini:"bandwidth_limit" json:"bandwidth_limit"`
|
||||
// BandwidthLimitMode specifies whether to limit the bandwidth on the
|
||||
// client or server side. Valid values include "client" and "server".
|
||||
// By default, this value is "client".
|
||||
BandwidthLimitMode string `ini:"bandwidth_limit_mode" json:"bandwidth_limit_mode"`
|
||||
|
||||
// meta info for each proxy
|
||||
Metas map[string]string `ini:"-" json:"metas"`
|
||||
@@ -319,6 +323,7 @@ func defaultBaseProxyConf(proxyType string) BaseProxyConf {
|
||||
LocalSvrConf: LocalSvrConf{
|
||||
LocalIP: "127.0.0.1",
|
||||
},
|
||||
BandwidthLimitMode: BandwidthLimitModeClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +340,7 @@ func (cfg *BaseProxyConf) compare(cmp *BaseProxyConf) bool {
|
||||
cfg.GroupKey != cmp.GroupKey ||
|
||||
cfg.ProxyProtocolVersion != cmp.ProxyProtocolVersion ||
|
||||
!cfg.BandwidthLimit.Equal(&cmp.BandwidthLimit) ||
|
||||
cfg.BandwidthLimitMode != cmp.BandwidthLimitMode ||
|
||||
!reflect.DeepEqual(cfg.Metas, cmp.Metas) {
|
||||
return false
|
||||
}
|
||||
@@ -389,6 +395,8 @@ func (cfg *BaseProxyConf) marshalToMsg(pMsg *msg.NewProxy) {
|
||||
pMsg.ProxyType = cfg.ProxyType
|
||||
pMsg.UseEncryption = cfg.UseEncryption
|
||||
pMsg.UseCompression = cfg.UseCompression
|
||||
pMsg.BandwidthLimit = cfg.BandwidthLimit.String()
|
||||
pMsg.BandwidthLimitMode = cfg.BandwidthLimitMode
|
||||
pMsg.Group = cfg.Group
|
||||
pMsg.GroupKey = cfg.GroupKey
|
||||
pMsg.Metas = cfg.Metas
|
||||
@@ -399,6 +407,8 @@ func (cfg *BaseProxyConf) unmarshalFromMsg(pMsg *msg.NewProxy) {
|
||||
cfg.ProxyType = pMsg.ProxyType
|
||||
cfg.UseEncryption = pMsg.UseEncryption
|
||||
cfg.UseCompression = pMsg.UseCompression
|
||||
cfg.BandwidthLimit, _ = NewBandwidthQuantity(pMsg.BandwidthLimit)
|
||||
cfg.BandwidthLimitMode = pMsg.BandwidthLimitMode
|
||||
cfg.Group = pMsg.Group
|
||||
cfg.GroupKey = pMsg.GroupKey
|
||||
cfg.Metas = pMsg.Metas
|
||||
@@ -411,6 +421,10 @@ func (cfg *BaseProxyConf) checkForCli() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.BandwidthLimitMode != "client" && cfg.BandwidthLimitMode != "server" {
|
||||
return fmt.Errorf("bandwidth_limit_mode should be client or server")
|
||||
}
|
||||
|
||||
if err = cfg.LocalSvrConf.checkForCli(); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -420,6 +434,13 @@ func (cfg *BaseProxyConf) checkForCli() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cfg *BaseProxyConf) checkForSvr() (err error) {
|
||||
if cfg.BandwidthLimitMode != "client" && cfg.BandwidthLimitMode != "server" {
|
||||
return fmt.Errorf("bandwidth_limit_mode should be client or server")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DomainConf
|
||||
func (cfg *DomainConf) check() (err error) {
|
||||
if len(cfg.CustomDomains) == 0 && cfg.SubDomain == "" {
|
||||
@@ -557,6 +578,9 @@ func (cfg *TCPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *TCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -632,6 +656,10 @@ func (cfg *TCPMuxProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *TCPMuxProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.Multiplexer != consts.HTTPConnectTCPMultiplexer {
|
||||
return fmt.Errorf("proxy [%s] incorrect multiplexer [%s]", cfg.ProxyName, cfg.Multiplexer)
|
||||
}
|
||||
@@ -703,6 +731,9 @@ func (cfg *UDPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *UDPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -788,6 +819,10 @@ func (cfg *HTTPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *HTTPProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if serverCfg.VhostHTTPPort == 0 {
|
||||
return fmt.Errorf("type [http] not support when vhost_http_port is not set")
|
||||
}
|
||||
@@ -860,6 +895,10 @@ func (cfg *HTTPSProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *HTTPSProxyConf) CheckForSvr(serverCfg ServerCommonConf) (err error) {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if serverCfg.VhostHTTPSPort == 0 {
|
||||
return fmt.Errorf("type [https] not support when vhost_https_port is not set")
|
||||
}
|
||||
@@ -932,6 +971,9 @@ func (cfg *SUDPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *SUDPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -998,6 +1040,9 @@ func (cfg *STCPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *STCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1064,5 +1109,8 @@ func (cfg *XTCPProxyConf) CheckForCli() (err error) {
|
||||
}
|
||||
|
||||
func (cfg *XTCPProxyConf) CheckForSvr(serverCfg ServerCommonConf) error {
|
||||
if err := cfg.BaseProxyConf.checkForSvr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user