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

View File

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

View File

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

View File

@ -62,14 +62,15 @@ var (
// When frpc start, client send this message to login to server. // When frpc start, client send this message to login to server.
type Login struct { type Login struct {
Version string `json:"version"` Version string `json:"version"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
Os string `json:"os"` Os string `json:"os"`
Arch string `json:"arch"` Arch string `json:"arch"`
User string `json:"user"` User string `json:"user"`
PrivilegeKey string `json:"privilege_key"` PrivilegeKey string `json:"privilege_key"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
RunId string `json:"run_id"` RunId string `json:"run_id"`
Metas map[string]string `json:"metas"`
// Some global configures. // Some global configures.
PoolCount int `json:"pool_count"` PoolCount int `json:"pool_count"`
@ -84,12 +85,13 @@ type LoginResp struct {
// When frpc login success, send this message to frps for running a new proxy. // When frpc login success, send this message to frps for running a new proxy.
type NewProxy struct { type NewProxy struct {
ProxyName string `json:"proxy_name"` ProxyName string `json:"proxy_name"`
ProxyType string `json:"proxy_type"` ProxyType string `json:"proxy_type"`
UseEncryption bool `json:"use_encryption"` UseEncryption bool `json:"use_encryption"`
UseCompression bool `json:"use_compression"` UseCompression bool `json:"use_compression"`
Group string `json:"group"` Group string `json:"group"`
GroupKey string `json:"group_key"` GroupKey string `json:"group_key"`
Metas map[string]string `json:"metas"`
// tcp and udp only // tcp and udp only
RemotePort int `json:"remote_port"` RemotePort int `json:"remote_port"`

View File

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

View File

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