1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

Merge pull request #219 from xiaokangwang/substituteDialer

Solve #218: Supporting substitute of the default Dialer.
This commit is contained in:
Darien Raymond 2016-07-26 16:33:14 +02:00 committed by GitHub
commit 27a29da7bf
2 changed files with 41 additions and 19 deletions

View File

@ -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())
}
}

View File

@ -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)
}