Merge pull request #184 from fatedier/fatedier/udp

udp: fix privilege_mode not success for udp type
This commit is contained in:
fatedier 2016-12-19 09:57:08 -06:00 committed by GitHub
commit d7d2b72431
3 changed files with 9 additions and 8 deletions

View File

@ -55,9 +55,10 @@ func (pc *ProxyClient) StartUdpTunnelOnce(addr string, port int64) {
} }
if err != nil { if err != nil {
log.Error("ProxyName [%s], udp tunnel connect to server [%s:%d] error, %v", pc.Name, addr, port, err) 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 continue
} }
log.Info("ProxyName [%s], udp tunnel reconnect to server [%s:%d] success", pc.Name, addr, port)
nowTime := time.Now().Unix() nowTime := time.Now().Unix()
req := &msg.ControlReq{ req := &msg.ControlReq{

View File

@ -199,7 +199,7 @@ func LoadConf(confFile string) (err error) {
proxyClient.PrivilegeToken = PrivilegeToken proxyClient.PrivilegeToken = PrivilegeToken
} }
if proxyClient.Type == "tcp" { if proxyClient.Type == "tcp" || proxyClient.Type == "udp" {
// remote_port // remote_port
tmpStr, ok = section["remote_port"] tmpStr, ok = section["remote_port"]
if ok { if ok {

View File

@ -69,7 +69,7 @@ func NewProxyServerFromCtlMsg(req *msg.ControlReq) (p *ProxyServer) {
p.PrivilegeMode = req.PrivilegeMode p.PrivilegeMode = req.PrivilegeMode
p.PrivilegeToken = PrivilegeToken p.PrivilegeToken = PrivilegeToken
p.BindAddr = BindAddr p.BindAddr = BindAddr
if p.Type == "tcp" { if p.Type == "tcp" || p.Type == "udp" {
p.ListenPort = req.RemotePort p.ListenPort = req.RemotePort
} else if p.Type == "http" { } else if p.Type == "http" {
p.ListenPort = VhostHttpPort p.ListenPort = VhostHttpPort
@ -160,11 +160,6 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
p.Unlock() p.Unlock()
metric.SetStatus(p.Name, p.Status) metric.SetStatus(p.Name, p.Status)
// create connection pool if needed
if p.PoolCount > 0 {
go p.connectionPoolManager(p.closeChan)
}
if p.Type == "udp" { if p.Type == "udp" {
// udp is special // udp is special
p.udpConn, err = conn.ListenUDP(p.BindAddr, p.ListenPort) p.udpConn, err = conn.ListenUDP(p.BindAddr, p.ListenPort)
@ -191,6 +186,11 @@ func (p *ProxyServer) Start(c *conn.Conn) (err error) {
} }
}() }()
} else { } 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 // start a goroutine for every listener to accept user connection
for _, listener := range p.listeners { for _, listener := range p.listeners {
go func(l Listener) { go func(l Listener) {