mirror of https://github.com/v2ray/v2ray-core
Merge pull request #219 from xiaokangwang/substituteDialer
Solve #218: Supporting substitute of the default Dialer.pull/2034/head
commit
27a29da7bf
|
@ -56,11 +56,15 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
|
|||
}
|
||||
|
||||
func DialToDest(src v2net.Address, dest v2net.Destination) (net.Conn, error) {
|
||||
|
||||
if isDefaultDialerSubstituted() {
|
||||
dialer := v2AlternativeDialer
|
||||
return (*dialer).Dial(dest.Network().String(), dest.NetAddr())
|
||||
} else {
|
||||
dialer := &net.Dialer{
|
||||
Timeout: time.Second * 60,
|
||||
DualStack: true,
|
||||
}
|
||||
|
||||
if src != nil && src != v2net.AnyIP {
|
||||
var addr net.Addr
|
||||
if dest.IsTCP() {
|
||||
|
@ -76,6 +80,6 @@ func DialToDest(src v2net.Address, dest v2net.Destination) (net.Conn, error) {
|
|||
}
|
||||
dialer.LocalAddr = addr
|
||||
}
|
||||
|
||||
return dialer.Dial(dest.Network().String(), dest.NetAddr())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package internet
|
||||
|
||||
import "net"
|
||||
|
||||
var v2AlternativeDialer *V2AlternativeDialerT
|
||||
|
||||
type V2AlternativeDialerT interface {
|
||||
Dial(nw string, ad string) (net.Conn, error)
|
||||
}
|
||||
|
||||
func SubstituteDialer(substituteWith V2AlternativeDialerT) error {
|
||||
v2AlternativeDialer = &substituteWith
|
||||
return nil
|
||||
}
|
||||
|
||||
func isDefaultDialerSubstituted() bool {
|
||||
return (v2AlternativeDialer != nil)
|
||||
}
|
Loading…
Reference in New Issue