(ctx context.Context, network, address string)
| 49 | } |
| 50 | |
| 51 | func (d *CommandDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { |
| 52 | killCtx, kill := context.WithCancel(context.Background()) |
| 53 | cmd := exec.CommandContext(killCtx, d.command[0], d.command[1:]...) |
| 54 | cmd.Env = append(os.Environ(), |
| 55 | "DUMBPROXY_DST_ADDR="+address, |
| 56 | "DUMBPROXY_DST_NET="+network, |
| 57 | ) |
| 58 | cmdIn, err := cmd.StdinPipe() |
| 59 | if err != nil { |
| 60 | return nil, fmt.Errorf("can't create stdin pipe for subprocess: %w", err) |
| 61 | } |
| 62 | cmdOut, err := cmd.StdoutPipe() |
| 63 | if err != nil { |
| 64 | return nil, fmt.Errorf("can't create stdout pipe for subprocess: %w", err) |
| 65 | } |
| 66 | cmd.Stderr = os.Stderr |
| 67 | cmd.WaitDelay = d.waitDelay |
| 68 | if err := cmd.Start(); err != nil { |
| 69 | return nil, fmt.Errorf("unable to start subprocess: %w", err) |
| 70 | } |
| 71 | go func() { |
| 72 | cmd.Wait() |
| 73 | cmdIn.Close() |
| 74 | cmdOut.Close() |
| 75 | }() |
| 76 | return NewPipeConn(cmdOut.(ReadPipe), cmdIn.(WritePipe), kill), nil |
| 77 | } |
| 78 | |
| 79 | func (d *CommandDialer) WantsHostname(_ context.Context, _, _ string) bool { |
| 80 | return true |
no test coverage detected