gfwproxyshadowsocksdocker-imagegogolanggvisornatnetworksocks4socks5tcpip-stacktortun-devicetun2sockstunneludpwireguard
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
629 B
35 lines
629 B
package dialer
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"syscall"
|
|
)
|
|
|
|
type controlFunc func(string, string, syscall.RawConn) error
|
|
|
|
var _controlPool = make([]controlFunc, 0, 2)
|
|
|
|
func addControl(f controlFunc) {
|
|
_controlPool = append(_controlPool, f)
|
|
}
|
|
|
|
func setControl(i interface{}) {
|
|
control := func(address, network string, c syscall.RawConn) error {
|
|
for _, f := range _controlPool {
|
|
if err := f(address, network, c); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
switch v := i.(type) {
|
|
case *net.Dialer:
|
|
v.Control = control
|
|
case *net.ListenConfig:
|
|
v.Control = control
|
|
default:
|
|
panic(errors.New("wrong type"))
|
|
}
|
|
}
|
|
|