Feature: dial different NIC for all proxies (#1714)
This commit is contained in:
@ -36,12 +36,12 @@ func DialContext(ctx context.Context, network, address string, options ...Option
|
||||
}
|
||||
|
||||
func ListenPacket(ctx context.Context, network, address string, options ...Option) (net.PacketConn, error) {
|
||||
cfg := &config{}
|
||||
cfg := &option{
|
||||
interfaceName: DefaultInterface.Load(),
|
||||
}
|
||||
|
||||
if !cfg.skipDefault {
|
||||
for _, o := range DefaultOptions {
|
||||
o(cfg)
|
||||
}
|
||||
for _, o := range DefaultOptions {
|
||||
o(cfg)
|
||||
}
|
||||
|
||||
for _, o := range options {
|
||||
@ -64,12 +64,12 @@ func ListenPacket(ctx context.Context, network, address string, options ...Optio
|
||||
}
|
||||
|
||||
func dialContext(ctx context.Context, network string, destination net.IP, port string, options []Option) (net.Conn, error) {
|
||||
opt := &config{}
|
||||
opt := &option{
|
||||
interfaceName: DefaultInterface.Load(),
|
||||
}
|
||||
|
||||
if !opt.skipDefault {
|
||||
for _, o := range DefaultOptions {
|
||||
o(opt)
|
||||
}
|
||||
for _, o := range DefaultOptions {
|
||||
o(opt)
|
||||
}
|
||||
|
||||
for _, o := range options {
|
||||
|
@ -1,29 +1,27 @@
|
||||
package dialer
|
||||
|
||||
var DefaultOptions []Option
|
||||
import "go.uber.org/atomic"
|
||||
|
||||
type config struct {
|
||||
skipDefault bool
|
||||
var (
|
||||
DefaultOptions []Option
|
||||
DefaultInterface = atomic.NewString("")
|
||||
)
|
||||
|
||||
type option struct {
|
||||
interfaceName string
|
||||
addrReuse bool
|
||||
}
|
||||
|
||||
type Option func(opt *config)
|
||||
type Option func(opt *option)
|
||||
|
||||
func WithInterface(name string) Option {
|
||||
return func(opt *config) {
|
||||
return func(opt *option) {
|
||||
opt.interfaceName = name
|
||||
}
|
||||
}
|
||||
|
||||
func WithAddrReuse(reuse bool) Option {
|
||||
return func(opt *config) {
|
||||
return func(opt *option) {
|
||||
opt.addrReuse = reuse
|
||||
}
|
||||
}
|
||||
|
||||
func WithSkipDefault(skip bool) Option {
|
||||
return func(opt *config) {
|
||||
opt.skipDefault = skip
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user