MCPcopy
hub / github.com/MetaCubeX/mihomo / dialContext

Function dialContext

component/dialer/dialer.go:123–175  ·  view source on GitHub ↗
(ctx context.Context, network string, destination netip.Addr, port string, opt option)

Source from the content-addressed store, hash-verified

121}
122
123func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt option) (net.Conn, error) {
124 var address string
125 destination, port = resolver.LookupIP4P(destination, port)
126 address = net.JoinHostPort(destination.String(), port)
127
128 netDialer := opt.netDialer
129 switch netDialer.(type) {
130 case nil:
131 netDialer = &net.Dialer{}
132 case *net.Dialer:
133 _netDialer := *netDialer.(*net.Dialer)
134 netDialer = &_netDialer // make a copy
135 default:
136 return netDialer.DialContext(ctx, network, address)
137 }
138
139 dialer := netDialer.(*net.Dialer)
140 keepalive.SetNetDialer(dialer)
141 mptcp.SetNetDialer(dialer, opt.mpTcp)
142
143 if DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo when DefaultSocketHook not null (in CMFA)
144 socketHookToToDialer(dialer)
145 } else {
146 if opt.interfaceName == "" {
147 opt.interfaceName = DefaultInterface.Load()
148 }
149 if opt.interfaceName == "" {
150 if finder := DefaultInterfaceFinder.Load(); finder != nil {
151 opt.interfaceName = finder.FindInterfaceName(destination)
152 }
153 }
154 if opt.interfaceName != "" {
155 bind := bindIfaceToDialer
156 if opt.fallbackBind {
157 bind = fallbackBindIfaceToDialer
158 }
159 if err := bind(opt.interfaceName, dialer, network, destination); err != nil {
160 return nil, err
161 }
162 }
163 if opt.routingMark == 0 {
164 opt.routingMark = int(DefaultRoutingMark.Load())
165 }
166 if opt.routingMark != 0 {
167 bindMarkToDialer(opt.routingMark, dialer, network, destination)
168 }
169 if opt.tfo && !DisableTFO {
170 return dialTFO(ctx, *dialer, network, address)
171 }
172 }
173
174 return dialer.DialContext(ctx, network, address)
175}
176
177func ICMPControl(destination netip.Addr) func(network, address string, conn syscall.RawConn) error {
178 return func(network, address string, conn syscall.RawConn) error {

Callers 3

parallelDialContextFunction · 0.85
serialDialContextFunction · 0.85
buildHTTPTransportFunction · 0.85

Calls 10

LookupIP4PFunction · 0.92
SetNetDialerFunction · 0.92
SetNetDialerFunction · 0.92
socketHookToToDialerFunction · 0.85
dialTFOFunction · 0.85
bindMarkToDialerFunction · 0.70
StringMethod · 0.65
DialContextMethod · 0.65
FindInterfaceNameMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected