mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
update kcp mode
This commit is contained in:
parent
32f8745d61
commit
a2c318d24c
@ -30,6 +30,7 @@ type ServerCommonConf struct {
|
|||||||
ConfigFile string
|
ConfigFile string
|
||||||
BindAddr string
|
BindAddr string
|
||||||
BindPort int64
|
BindPort int64
|
||||||
|
KcpBindPort int64
|
||||||
|
|
||||||
// If VhostHttpPort equals 0, don't listen a public port for http protocol.
|
// If VhostHttpPort equals 0, don't listen a public port for http protocol.
|
||||||
VhostHttpPort int64
|
VhostHttpPort int64
|
||||||
@ -51,7 +52,6 @@ type ServerCommonConf struct {
|
|||||||
AuthTimeout int64
|
AuthTimeout int64
|
||||||
SubDomainHost string
|
SubDomainHost string
|
||||||
TcpMux bool
|
TcpMux bool
|
||||||
SupportKcp bool
|
|
||||||
|
|
||||||
// if PrivilegeAllowPorts is not nil, tcp proxies which remote port exist in this map can be connected
|
// if PrivilegeAllowPorts is not nil, tcp proxies which remote port exist in this map can be connected
|
||||||
PrivilegeAllowPorts [][2]int64
|
PrivilegeAllowPorts [][2]int64
|
||||||
@ -65,6 +65,7 @@ func GetDefaultServerCommonConf() *ServerCommonConf {
|
|||||||
ConfigFile: "./frps.ini",
|
ConfigFile: "./frps.ini",
|
||||||
BindAddr: "0.0.0.0",
|
BindAddr: "0.0.0.0",
|
||||||
BindPort: 7000,
|
BindPort: 7000,
|
||||||
|
KcpBindPort: 0,
|
||||||
VhostHttpPort: 0,
|
VhostHttpPort: 0,
|
||||||
VhostHttpsPort: 0,
|
VhostHttpsPort: 0,
|
||||||
DashboardPort: 0,
|
DashboardPort: 0,
|
||||||
@ -80,7 +81,6 @@ func GetDefaultServerCommonConf() *ServerCommonConf {
|
|||||||
AuthTimeout: 900,
|
AuthTimeout: 900,
|
||||||
SubDomainHost: "",
|
SubDomainHost: "",
|
||||||
TcpMux: true,
|
TcpMux: true,
|
||||||
SupportKcp: true,
|
|
||||||
MaxPoolCount: 5,
|
MaxPoolCount: 5,
|
||||||
HeartBeatTimeout: 90,
|
HeartBeatTimeout: 90,
|
||||||
UserConnTimeout: 10,
|
UserConnTimeout: 10,
|
||||||
@ -109,6 +109,14 @@ func LoadServerCommonConf(conf ini.File) (cfg *ServerCommonConf, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpStr, ok = conf.Get("common", "kcp_bind_port")
|
||||||
|
if ok {
|
||||||
|
v, err = strconv.ParseInt(tmpStr, 10, 64)
|
||||||
|
if err == nil && v > 0 {
|
||||||
|
cfg.KcpBindPort = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tmpStr, ok = conf.Get("common", "vhost_http_port")
|
tmpStr, ok = conf.Get("common", "vhost_http_port")
|
||||||
if ok {
|
if ok {
|
||||||
cfg.VhostHttpPort, err = strconv.ParseInt(tmpStr, 10, 64)
|
cfg.VhostHttpPort, err = strconv.ParseInt(tmpStr, 10, 64)
|
||||||
@ -233,13 +241,6 @@ func LoadServerCommonConf(conf ini.File) (cfg *ServerCommonConf, err error) {
|
|||||||
cfg.TcpMux = true
|
cfg.TcpMux = true
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpStr, ok = conf.Get("common", "support_kcp")
|
|
||||||
if ok && tmpStr == "false" {
|
|
||||||
cfg.SupportKcp = false
|
|
||||||
} else {
|
|
||||||
cfg.SupportKcp = true
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpStr, ok = conf.Get("common", "heartbeat_timeout")
|
tmpStr, ok = conf.Get("common", "heartbeat_timeout")
|
||||||
if ok {
|
if ok {
|
||||||
v, errRet := strconv.ParseInt(tmpStr, 10, 64)
|
v, errRet := strconv.ParseInt(tmpStr, 10, 64)
|
||||||
|
@ -79,17 +79,17 @@ func NewService() (svr *Service, err error) {
|
|||||||
log.Info("frps tcp listen on %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort)
|
log.Info("frps tcp listen on %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort)
|
||||||
|
|
||||||
// Listen for accepting connections from client using kcp protocol.
|
// Listen for accepting connections from client using kcp protocol.
|
||||||
if config.ServerCommonCfg.SupportKcp {
|
if config.ServerCommonCfg.KcpBindPort > 0 {
|
||||||
svr.kcpListener, err = frpNet.ListenKcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort)
|
svr.kcpListener, err = frpNet.ListenKcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.KcpBindPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Listen on kcp address [%s:%d] error: %v", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort, err)
|
err = fmt.Errorf("Listen on kcp address udp [%s:%d] error: %v", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.KcpBindPort, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("frps kcp listen on %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort)
|
log.Info("frps kcp listen on udp %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.BindPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create http vhost muxer.
|
// Create http vhost muxer.
|
||||||
if config.ServerCommonCfg.VhostHttpPort != 0 {
|
if config.ServerCommonCfg.VhostHttpPort > 0 {
|
||||||
var l frpNet.Listener
|
var l frpNet.Listener
|
||||||
l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpPort)
|
l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -105,7 +105,7 @@ func NewService() (svr *Service, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create https vhost muxer.
|
// Create https vhost muxer.
|
||||||
if config.ServerCommonCfg.VhostHttpsPort != 0 {
|
if config.ServerCommonCfg.VhostHttpsPort > 0 {
|
||||||
var l frpNet.Listener
|
var l frpNet.Listener
|
||||||
l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpsPort)
|
l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpsPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,7 +121,7 @@ func NewService() (svr *Service, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create dashboard web server.
|
// Create dashboard web server.
|
||||||
if config.ServerCommonCfg.DashboardPort != 0 {
|
if config.ServerCommonCfg.DashboardPort > 0 {
|
||||||
err = RunDashboardServer(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.DashboardPort)
|
err = RunDashboardServer(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.DashboardPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Create dashboard web server error, %v", err)
|
err = fmt.Errorf("Create dashboard web server error, %v", err)
|
||||||
@ -133,7 +133,7 @@ func NewService() (svr *Service, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (svr *Service) Run() {
|
func (svr *Service) Run() {
|
||||||
if config.ServerCommonCfg.SupportKcp {
|
if config.ServerCommonCfg.KcpBindPort > 0 {
|
||||||
go svr.HandleListener(svr.kcpListener)
|
go svr.HandleListener(svr.kcpListener)
|
||||||
}
|
}
|
||||||
svr.HandleListener(svr.listener)
|
svr.HandleListener(svr.listener)
|
||||||
|
Loading…
Reference in New Issue
Block a user