MCPcopy Index your code
hub / github.com/SenseUnit/dumbproxy / PortForwardHandler

Function PortForwardHandler

handler/streamhandler.go:12–31  ·  view source on GitHub ↗
(logger *clog.CondLogger, dialer HandlerDialer, address string, forward ForwardFunc)

Source from the content-addressed store, hash-verified

10)
11
12func PortForwardHandler(logger *clog.CondLogger, dialer HandlerDialer, address string, forward ForwardFunc) func(context.Context, net.Conn) {
13 return func(ctx context.Context, c net.Conn) {
14 if err := func() error {
15 defer c.Close()
16 username := ""
17 localAddr := c.LocalAddr().String()
18 ctx = ddto.BoundDialerParamsToContext(ctx, nil, trimAddrPort(localAddr))
19 ctx = ddto.FilterParamsToContext(ctx, nil, username)
20 logger.Info("Request: %v => %v %q %v %v %v", c.RemoteAddr().String(), localAddr, username, "STREAM", "CONNECT", address)
21 target, err := dialer.DialContext(ctx, "tcp", address)
22 if err != nil {
23 return fmt.Errorf("connect to %s failed: %w", address, err)
24 }
25 defer target.Close()
26 return forward(ctx, username, c, target, "tcp", address)
27 }(); err != nil {
28 logger.Error("handler failure: %v", err)
29 }
30 }
31}

Callers 1

runFunction · 0.92

Calls 9

trimAddrPortFunction · 0.85
ErrorfMethod · 0.80
CloseMethod · 0.65
DialContextMethod · 0.65
StringMethod · 0.45
LocalAddrMethod · 0.45
InfoMethod · 0.45
RemoteAddrMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected