MCPcopy
hub / github.com/gdy666/lucky / StartProxy

Method StartProxy

socketproxy/udpproxy.go:96–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94}
95
96func (p *UDPProxy) StartProxy() {
97 //p.init()
98 p.listenConnMutex.Lock()
99 defer p.listenConnMutex.Unlock()
100 if p.listenConn != nil {
101 return
102 }
103
104 bindAddr, err := net.ResolveUDPAddr(p.ProxyType, p.GetListentAddress())
105
106 if err != nil {
107 p.log.Errorf("Cannot start proxy[%s]:%s", p.GetKey(), err)
108 return
109 }
110
111 ln, err := net.ListenUDP(p.ProxyType, bindAddr)
112 if err != nil {
113 if strings.Contains(err.Error(), " bind: Only one usage of each socket address") {
114 p.log.Errorf("监听IP端口[%s]已被占用,proxy[%s]启动失败", p.GetListentAddress(), p.String())
115 } else {
116 p.log.Errorf("Cannot start proxy[%s]:%s", p.String(), err)
117 }
118 return
119 }
120
121 ln.SetReadBuffer(p.getHandlegoroutineNum() * 4 * 1024 * 1024)
122 ln.SetWriteBuffer(p.getHandlegoroutineNum() * 4 * 1024 * 1024)
123
124 p.listenConn = ln
125
126 p.log.Infof("[端口转发][开启][%s]", p.String())
127
128 p.relayChs = make([]chan *udpPackge, p.getHandlegoroutineNum())
129
130 for i := range p.relayChs {
131 p.relayChs[i] = make(chan *udpPackge, 1024)
132 }
133
134 p.replyCh = make(chan *udpPackge, 1024)
135 // if p.targetudpConnItemMap == nil {
136 // p.targetudpConnItemMap = make(map[string]*udpMapItem)
137 // }
138
139 for i := range p.relayChs {
140 go p.Forwarder(i, p.relayChs[i])
141 }
142
143 go p.replyDataToRemotAddress()
144
145 go p.CheckTargetUDPConnectSessions()
146
147 for i := 0; i < p.getHandlegoroutineNum(); i++ {
148 go p.ListenHandler(ln)
149 }
150
151}
152
153func (p *UDPProxy) StopProxy() {

Callers

nothing calls this directly

Calls 9

getHandlegoroutineNumMethod · 0.95
ForwarderMethod · 0.95
ListenHandlerMethod · 0.95
GetKeyMethod · 0.65
StringMethod · 0.65
GetListentAddressMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected