support meta info for client and proxy

This commit is contained in:
fatedier 2019-12-08 21:01:58 +08:00
parent df18375308
commit a57679f837
6 changed files with 46 additions and 18 deletions

View File

@ -64,6 +64,10 @@ tls_enable = true
# heartbeat_interval = 30
# heartbeat_timeout = 90
# additional meta info for client
meta_var1 = 123
meta_var2 = 234
# 'ssh' is the unique proxy name
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
[ssh]
@ -92,6 +96,9 @@ health_check_timeout_s = 3
health_check_max_failed = 3
# every 10 seconds will do a health check
health_check_interval_s = 10
# additional meta info for each proxy
meta_var1 = 123
meta_var2 = 234
[ssh_random]
type = tcp

View File

@ -115,6 +115,8 @@ type ClientCommonConf struct {
// before the connection is terminated, in seconds. It is not recommended
// to change this value. By default, this value is 90.
HeartBeatTimeout int64 `json:"heartbeat_timeout"`
// Client meta info
Metas map[string]string `json:"metas"`
}
// GetDefaultClientConf returns a client configuration with default values.
@ -144,6 +146,7 @@ func GetDefaultClientConf() ClientCommonConf {
TLSEnable: false,
HeartBeatInterval: 30,
HeartBeatTimeout: 90,
Metas: make(map[string]string),
}
}
@ -294,6 +297,11 @@ func UnmarshalClientConfFromIni(content string) (cfg ClientCommonConf, err error
cfg.HeartBeatInterval = v
}
}
for k, v := range conf.Section("common") {
if strings.HasPrefix(k, "meta_") {
cfg.Metas[strings.TrimPrefix(k, "meta_")] = v
}
}
return
}

View File

@ -130,6 +130,9 @@ type BaseProxyConf struct {
// 0 means no limit
BandwidthLimit BandwidthQuantity `json:"bandwidth_limit"`
// meta info for each proxy
Metas map[string]string `json:"metas"`
LocalSvrConf
HealthCheckConf
}
@ -146,7 +149,8 @@ func (cfg *BaseProxyConf) compare(cmp *BaseProxyConf) bool {
cfg.Group != cmp.Group ||
cfg.GroupKey != cmp.GroupKey ||
cfg.ProxyProtocolVersion != cmp.ProxyProtocolVersion ||
cfg.BandwidthLimit.Equal(&cmp.BandwidthLimit) {
cfg.BandwidthLimit.Equal(&cmp.BandwidthLimit) ||
!reflect.DeepEqual(cfg.Metas, cmp.Metas) {
return false
}
if !cfg.LocalSvrConf.compare(&cmp.LocalSvrConf) {
@ -165,6 +169,7 @@ func (cfg *BaseProxyConf) UnmarshalFromMsg(pMsg *msg.NewProxy) {
cfg.UseCompression = pMsg.UseCompression
cfg.Group = pMsg.Group
cfg.GroupKey = pMsg.GroupKey
cfg.Metas = pMsg.Metas
}
func (cfg *BaseProxyConf) UnmarshalFromIni(prefix string, name string, section ini.Section) error {
@ -212,6 +217,12 @@ func (cfg *BaseProxyConf) UnmarshalFromIni(prefix string, name string, section i
}
cfg.HealthCheckUrl = s + cfg.HealthCheckUrl
}
for k, v := range section {
if strings.HasPrefix(k, "meta_") {
cfg.Metas[strings.TrimPrefix(k, "meta_")] = v
}
}
return nil
}
@ -222,6 +233,7 @@ func (cfg *BaseProxyConf) MarshalToMsg(pMsg *msg.NewProxy) {
pMsg.UseCompression = cfg.UseCompression
pMsg.Group = cfg.Group
pMsg.GroupKey = cfg.GroupKey
pMsg.Metas = cfg.Metas
}
func (cfg *BaseProxyConf) checkForCli() (err error) {

View File

@ -70,6 +70,7 @@ type Login struct {
PrivilegeKey string `json:"privilege_key"`
Timestamp int64 `json:"timestamp"`
RunId string `json:"run_id"`
Metas map[string]string `json:"metas"`
// Some global configures.
PoolCount int `json:"pool_count"`
@ -90,6 +91,7 @@ type NewProxy struct {
UseCompression bool `json:"use_compression"`
Group string `json:"group"`
GroupKey string `json:"group_key"`
Metas map[string]string `json:"metas"`
// tcp and udp only
RemotePort int `json:"remote_port"`

View File

@ -94,7 +94,6 @@ func NewHTTP2HTTPSPlugin(params map[string]string) (Plugin, error) {
return p, nil
}
func (p *HTTP2HTTPSPlugin) Handle(conn io.ReadWriteCloser, realConn net.Conn, extraBufToLocal []byte) {
wrapConn := frpNet.WrapReadWriteCloserToConn(conn, realConn)
p.l.PutConn(wrapConn)
@ -105,7 +104,7 @@ func (p *HTTP2HTTPSPlugin) Name() string {
}
func (p *HTTP2HTTPSPlugin) Close() error {
if err := p.s.Close();err != nil {
if err := p.s.Close(); err != nil {
return err
}
return nil

View File

@ -126,7 +126,7 @@ func (p *HTTPS2HTTPPlugin) Name() string {
}
func (p *HTTPS2HTTPPlugin) Close() error {
if err := p.s.Close();err != nil {
if err := p.s.Close(); err != nil {
return err
}
return nil