style: split tcpmux into functions
This commit is contained in:
parent
045d5102d8
commit
6fc7135cbd
@ -31,50 +31,56 @@ type TcpMuxProxy struct {
|
|||||||
realPort int
|
realPort int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TcpMuxProxy) Run() (remoteAddr string, err error) {
|
func (pxy *TcpMuxProxy) httpConnectListen(domain string, addrs []string) ([]string, error) {
|
||||||
xl := pxy.xl
|
routeConfig := &vhost.VhostRouteConfig{
|
||||||
|
Domain: domain,
|
||||||
switch pxy.cfg.Multiplexer {
|
|
||||||
case consts.HttpConnectTcpMultiplexer:
|
|
||||||
routeConfig := &vhost.VhostRouteConfig{}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
pxy.Close()
|
|
||||||
}
|
}
|
||||||
}()
|
l, err := pxy.rc.TcpMuxHttpConnectMuxer.Listen(pxy.ctx, routeConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pxy.xl.Info("tcpmux httpconnect multiplexer listens for host [%s]", routeConfig.Domain)
|
||||||
|
pxy.listeners = append(pxy.listeners, l)
|
||||||
|
return append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.TCPMuxHTTPConnectPort)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pxy *TcpMuxProxy) httpConnectRun() (remoteAddr string, err error) {
|
||||||
addrs := make([]string, 0)
|
addrs := make([]string, 0)
|
||||||
for _, domain := range pxy.cfg.CustomDomains {
|
for _, domain := range pxy.cfg.CustomDomains {
|
||||||
if domain == "" {
|
if domain == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
routeConfig.Domain = domain
|
addrs, err = pxy.httpConnectListen(domain, addrs)
|
||||||
l, err := pxy.rc.TcpMuxHttpConnectMuxer.Listen(pxy.ctx, routeConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return remoteAddr, err
|
return "", err
|
||||||
}
|
}
|
||||||
xl.Info("tcpmux httpconnect multiplexer listens for host [%s]", routeConfig.Domain)
|
|
||||||
pxy.listeners = append(pxy.listeners, l)
|
|
||||||
addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.TCPMuxHTTPConnectPort))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pxy.cfg.SubDomain != "" {
|
if pxy.cfg.SubDomain != "" {
|
||||||
routeConfig.Domain = pxy.cfg.SubDomain + "." + pxy.serverCfg.SubDomainHost
|
addrs, err = pxy.httpConnectListen(pxy.cfg.SubDomain+"."+pxy.serverCfg.SubDomainHost, addrs)
|
||||||
l, err := pxy.rc.TcpMuxHttpConnectMuxer.Listen(pxy.ctx, routeConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return remoteAddr, err
|
return "", err
|
||||||
}
|
}
|
||||||
xl.Info("tcpmux httpconnect multiplexer listens for host [%s]", routeConfig.Domain)
|
|
||||||
pxy.listeners = append(pxy.listeners, l)
|
|
||||||
addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.TCPMuxHTTPConnectPort))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pxy.startListenHandler(pxy, HandleUserTcpConnection)
|
pxy.startListenHandler(pxy, HandleUserTcpConnection)
|
||||||
remoteAddr = strings.Join(addrs, ",")
|
remoteAddr = strings.Join(addrs, ",")
|
||||||
return remoteAddr, err
|
return remoteAddr, err
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("unknown multiplexer [%s]", pxy.cfg.Multiplexer)
|
|
||||||
|
func (pxy *TcpMuxProxy) Run() (remoteAddr string, err error) {
|
||||||
|
switch pxy.cfg.Multiplexer {
|
||||||
|
case consts.HttpConnectTcpMultiplexer:
|
||||||
|
remoteAddr, err = pxy.httpConnectRun()
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unknown multiplexer [%s]", pxy.cfg.Multiplexer)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
pxy.Close()
|
||||||
|
}
|
||||||
|
return remoteAddr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TcpMuxProxy) GetConf() config.ProxyConf {
|
func (pxy *TcpMuxProxy) GetConf() config.ProxyConf {
|
||||||
|
Loading…
Reference in New Issue
Block a user