-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdial.go
More file actions
34 lines (30 loc) · 710 Bytes
/
dial.go
File metadata and controls
34 lines (30 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package commandproxy
import (
"context"
"net"
)
type DialProxyCommand []string
func (p *DialProxyCommand) Format(network string, address string) []string {
host, port, err := net.SplitHostPort(address)
if err != nil {
host = address
} else if host == "" {
host = "0.0.0.0"
}
m := map[byte]string{
'n': network,
'h': host,
'p': port,
}
proxy := make([]string, len(*p))
copy(proxy, *p)
for i := range proxy {
proxy[i] = ReplaceEscape(proxy[i], m)
}
return proxy
}
func (p *DialProxyCommand) DialContext(ctx context.Context, network string, address string) (net.Conn, error) {
proxy := p.Format(network, address)
cp := ProxyCommand(ctx, proxy[0], proxy[1:]...)
return cp.Stdio()
}