mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
support meta info for client and proxy
This commit is contained in:
parent
df18375308
commit
a57679f837
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -70,6 +70,7 @@ type Login struct {
|
|||||||
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"`
|
||||||
@ -90,6 +91,7 @@ type NewProxy struct {
|
|||||||
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"`
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user