Allow multiple sub sections for tcp/udp server
This commit is contained in:
parent
db4ba56513
commit
173b32a2a5
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
ini "github.com/vaughan0/go-ini"
|
ini "github.com/vaughan0/go-ini"
|
||||||
|
|
||||||
"github.com/fatedier/frp/utils/util"
|
// "github.com/fatedier/frp/utils/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -32,7 +32,7 @@ var (
|
|||||||
vhostHttpsPort int
|
vhostHttpsPort int
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitServerCfg(cfg *ServerCommonConf) {
|
func InitServerCfg(cfg *ServerSectionConf) {
|
||||||
proxyBindAddr = cfg.ProxyBindAddr
|
proxyBindAddr = cfg.ProxyBindAddr
|
||||||
subDomainHost = cfg.SubDomainHost
|
subDomainHost = cfg.SubDomainHost
|
||||||
vhostHttpPort = cfg.VhostHttpPort
|
vhostHttpPort = cfg.VhostHttpPort
|
||||||
@ -40,7 +40,7 @@ func InitServerCfg(cfg *ServerCommonConf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// common config
|
// common config
|
||||||
type ServerCommonConf struct {
|
type ServerSectionConf struct {
|
||||||
BindAddr string `json:"bind_addr"`
|
BindAddr string `json:"bind_addr"`
|
||||||
BindPort int `json:"bind_port"`
|
BindPort int `json:"bind_port"`
|
||||||
BindUdpPort int `json:"bind_udp_port"`
|
BindUdpPort int `json:"bind_udp_port"`
|
||||||
@ -66,20 +66,18 @@ type ServerCommonConf struct {
|
|||||||
LogWay string `json:"log_way"` // console or file
|
LogWay string `json:"log_way"` // console or file
|
||||||
LogLevel string `json:"log_level"`
|
LogLevel string `json:"log_level"`
|
||||||
LogMaxDays int64 `json:"log_max_days"`
|
LogMaxDays int64 `json:"log_max_days"`
|
||||||
Token string `json:"token"`
|
|
||||||
AuthTimeout int64 `json:"auth_timeout"`
|
AuthTimeout int64 `json:"auth_timeout"`
|
||||||
SubDomainHost string `json:"subdomain_host"`
|
SubDomainHost string `json:"subdomain_host"`
|
||||||
TcpMux bool `json:"tcp_mux"`
|
TcpMux bool `json:"tcp_mux"`
|
||||||
|
|
||||||
AllowPorts map[int]struct{}
|
|
||||||
MaxPoolCount int64 `json:"max_pool_count"`
|
MaxPoolCount int64 `json:"max_pool_count"`
|
||||||
MaxPortsPerClient int64 `json:"max_ports_per_client"`
|
MaxPortsPerClient int64 `json:"max_ports_per_client"`
|
||||||
HeartBeatTimeout int64 `json:"heart_beat_timeout"`
|
HeartBeatTimeout int64 `json:"heart_beat_timeout"`
|
||||||
UserConnTimeout int64 `json:"user_conn_timeout"`
|
UserConnTimeout int64 `json:"user_conn_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultServerConf() *ServerCommonConf {
|
func GetDefaultServerConf() *ServerSectionConf {
|
||||||
return &ServerCommonConf{
|
return &ServerSectionConf{
|
||||||
BindAddr: "0.0.0.0",
|
BindAddr: "0.0.0.0",
|
||||||
BindPort: 7000,
|
BindPort: 7000,
|
||||||
BindUdpPort: 0,
|
BindUdpPort: 0,
|
||||||
@ -97,11 +95,9 @@ func GetDefaultServerConf() *ServerCommonConf {
|
|||||||
LogWay: "console",
|
LogWay: "console",
|
||||||
LogLevel: "info",
|
LogLevel: "info",
|
||||||
LogMaxDays: 3,
|
LogMaxDays: 3,
|
||||||
Token: "",
|
|
||||||
AuthTimeout: 900,
|
AuthTimeout: 900,
|
||||||
SubDomainHost: "",
|
SubDomainHost: "",
|
||||||
TcpMux: true,
|
TcpMux: true,
|
||||||
AllowPorts: make(map[int]struct{}),
|
|
||||||
MaxPoolCount: 5,
|
MaxPoolCount: 5,
|
||||||
MaxPortsPerClient: 0,
|
MaxPortsPerClient: 0,
|
||||||
HeartBeatTimeout: 90,
|
HeartBeatTimeout: 90,
|
||||||
@ -109,7 +105,7 @@ func GetDefaultServerConf() *ServerCommonConf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (cfg *ServerCommonConf, err error) {
|
func UnmarshalServerConfFromIni(defaultCfg *ServerSectionConf, content string) (cfg *ServerSectionConf, err error) {
|
||||||
cfg = defaultCfg
|
cfg = defaultCfg
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
cfg = GetDefaultServerConf()
|
cfg = GetDefaultServerConf()
|
||||||
@ -117,7 +113,7 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c
|
|||||||
|
|
||||||
conf, err := ini.Load(strings.NewReader(content))
|
conf, err := ini.Load(strings.NewReader(content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("parse ini conf file error: %v", err)
|
err = fmt.Errorf("parse ini file error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,13 +122,14 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c
|
|||||||
ok bool
|
ok bool
|
||||||
v int64
|
v int64
|
||||||
)
|
)
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "bind_addr"); ok {
|
if tmpStr, ok = conf.Get("common", "bind_addr"); ok {
|
||||||
cfg.BindAddr = tmpStr
|
cfg.BindAddr = tmpStr
|
||||||
}
|
}
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "bind_port"); ok {
|
if tmpStr, ok = conf.Get("common", "bind_port"); ok {
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
||||||
err = fmt.Errorf("Parse conf error: invalid bind_port")
|
err = fmt.Errorf("parse conf error: invalid bind_port")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
cfg.BindPort = int(v)
|
cfg.BindPort = int(v)
|
||||||
@ -244,21 +241,6 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Token, _ = conf.Get("common", "token")
|
|
||||||
|
|
||||||
if allowPortsStr, ok := conf.Get("common", "allow_ports"); ok {
|
|
||||||
// e.g. 1000-2000,2001,2002,3000-4000
|
|
||||||
ports, errRet := util.ParseRangeNumbers(allowPortsStr)
|
|
||||||
if errRet != nil {
|
|
||||||
err = fmt.Errorf("Parse conf error: allow_ports: %v", errRet)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, port := range ports {
|
|
||||||
cfg.AllowPorts[int(port)] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tmpStr, ok = conf.Get("common", "max_pool_count"); ok {
|
if tmpStr, ok = conf.Get("common", "max_pool_count"); ok {
|
||||||
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
if v, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
||||||
err = fmt.Errorf("Parse conf error: invalid max_pool_count")
|
err = fmt.Errorf("Parse conf error: invalid max_pool_count")
|
||||||
@ -317,6 +299,6 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *ServerCommonConf) Check() (err error) {
|
func (cfg *ServerSectionConf) Check() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user