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:
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())
|
||||
}
|
||||
}
|
||||
|
18
transport/internet/dialerSubstitute.go
Normal file
18
transport/internet/dialerSubstitute.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user