(req *request)
| 252 | } |
| 253 | |
| 254 | func (s *Server) embedHandleConnect(req *request) error { |
| 255 | defer func() { |
| 256 | _ = req.Conn.Close() |
| 257 | }() |
| 258 | |
| 259 | target, err := s.ProxyDial(s.Context, "tcp", req.DestinationAddr.Address()) |
| 260 | if err != nil { |
| 261 | if err := sendReply(req.Conn, errToReply(err), nil); err != nil { |
| 262 | return fmt.Errorf("failed to send reply: %v", err) |
| 263 | } |
| 264 | return fmt.Errorf("connect to %v failed: %w", req.DestinationAddr, err) |
| 265 | } |
| 266 | defer func() { |
| 267 | _ = target.Close() |
| 268 | }() |
| 269 | |
| 270 | localAddr := target.LocalAddr() |
| 271 | local, ok := localAddr.(*net.TCPAddr) |
| 272 | if !ok { |
| 273 | return fmt.Errorf("connect to %v failed: local address is %s://%s", req.DestinationAddr, localAddr.Network(), localAddr.String()) |
| 274 | } |
| 275 | bind := address{IP: local.IP, Port: local.Port} |
| 276 | if err := sendReply(req.Conn, successReply, &bind); err != nil { |
| 277 | return fmt.Errorf("failed to send reply: %v", err) |
| 278 | } |
| 279 | |
| 280 | var buf1, buf2 []byte |
| 281 | if s.BytesPool != nil { |
| 282 | buf1 = s.BytesPool.Get() |
| 283 | buf2 = s.BytesPool.Get() |
| 284 | defer func() { |
| 285 | s.BytesPool.Put(buf1) |
| 286 | s.BytesPool.Put(buf2) |
| 287 | }() |
| 288 | } else { |
| 289 | buf1 = make([]byte, 32*1024) |
| 290 | buf2 = make([]byte, 32*1024) |
| 291 | } |
| 292 | return statute.Tunnel(s.Context, target, req.Conn, buf1, buf2) |
| 293 | } |
| 294 | |
| 295 | func (s *Server) handleAssociate(req *request) error { |
| 296 | destinationAddr := req.DestinationAddr.String() |
no test coverage detected