MCPcopy Create free account
hub / github.com/bepass-org/proxy / embedHandleConnect

Method embedHandleConnect

pkg/socks5/server.go:254–293  ·  view source on GitHub ↗
(req *request)

Source from the content-addressed store, hash-verified

252}
253
254func (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
295func (s *Server) handleAssociate(req *request) error {
296 destinationAddr := req.DestinationAddr.String()

Callers 1

handleConnectMethod · 0.95

Calls 9

TunnelFunction · 0.92
errToReplyFunction · 0.85
CloseMethod · 0.80
GetMethod · 0.80
PutMethod · 0.80
sendReplyFunction · 0.70
AddressMethod · 0.45
NetworkMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected