From d04d31b39a50c1bbc8e3cf4a7b7356a68252c760 Mon Sep 17 00:00:00 2001 From: fatedier Date: Mon, 19 Dec 2016 23:30:48 +0800 Subject: [PATCH] udp: fix privilege_mode not success for udp type --- src/models/client/client.go | 3 ++- src/models/client/config.go | 2 +- src/models/server/server.go | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/models/client/client.go b/src/models/client/client.go index a108bebb..6d733774 100644 --- a/src/models/client/client.go +++ b/src/models/client/client.go @@ -55,9 +55,10 @@ func (pc *ProxyClient) StartUdpTunnelOnce(addr string, port int64) { } if err != nil { log.Error("ProxyName [%s], udp tunnel connect to server [%s:%d] error, %v", pc.Name, addr, port, err) - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) continue } + log.Info("ProxyName [%s], udp tunnel reconnect to server [%s:%d] success", pc.Name, addr, port) nowTime := time.Now().Unix() req := &msg.ControlReq{ diff --git a/src/models/client/config.go b/src/models/client/config.go index 49b81224..a33d48ba 100644 --- a/src/models/client/config.go +++ b/src/models/client/config.go @@ -194,7 +194,7 @@ func LoadConf(confFile string) (err error) { proxyClient.PrivilegeToken = PrivilegeToken } - if proxyClient.Type == "tcp" { + if proxyClient.Type == "tcp" || proxyClient.Type == "udp" { // remote_port tmpStr, ok = section["remote_port"] if ok { diff --git a/src/models/server/server.go b/src/models/server/server.go index 33c278bb..730cb5e1 100644 --- a/src/models/server/server.go +++ b/src/models/server/server.go @@ -69,7 +69,7 @@ func NewProxyServerFromCtlMsg(req *msg.ControlReq) (p *ProxyServer) { p.PrivilegeMode = req.PrivilegeMode p.PrivilegeToken = PrivilegeToken p.BindAddr = BindAddr - if p.Type == "tcp" { + if p.Type == "tcp" || p.Type == "udp" { p.ListenPort = req.RemotePort } else if p.Type == "http" { p.ListenPort = VhostHttpPort @@ -152,11 +152,6 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { p.Unlock() metric.SetStatus(p.Name, p.Status) - // create connection pool if needed - if p.PoolCount > 0 { - go p.connectionPoolManager(p.closeChan) - } - if p.Type == "udp" { // udp is special p.udpConn, err = conn.ListenUDP(p.BindAddr, p.ListenPort) @@ -183,6 +178,11 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) { } }() } else { + // create connection pool if needed + if p.PoolCount > 0 { + go p.connectionPoolManager(p.closeChan) + } + // start a goroutine for every listener to accept user connection for _, listener := range p.listeners { go func(l Listener) {