mirror of
https://github.com/xiaoqidun/probe.git
synced 2026-01-29 04:58:46 +08:00
fix(超时时间): 修复超时时间硬编码
This commit is contained in:
@@ -52,7 +52,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
if s5 != "" {
|
if s5 != "" {
|
||||||
fmt.Printf("通过代理探测: %s\n", s5)
|
fmt.Printf("通过代理探测: %s\n", s5)
|
||||||
conn, err = DialSocks5UDP(s5, network)
|
conn, err = DialSocks5UDP(s5, network, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("连接代理失败: %v\n", err)
|
fmt.Printf("连接代理失败: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|||||||
+2
-2
@@ -204,7 +204,7 @@ func DetectNAT(conn net.PacketConn, primarySTUN, secondarySTUN, network string,
|
|||||||
}
|
}
|
||||||
if mappedAddr2 == nil {
|
if mappedAddr2 == nil {
|
||||||
res.Mapping = MappingUnknown
|
res.Mapping = MappingUnknown
|
||||||
} else if mappedAddr1.String() == mappedAddr2.String() {
|
} else if mappedAddr1.IP.Equal(mappedAddr2.IP) && mappedAddr1.Port == mappedAddr2.Port {
|
||||||
res.Mapping = MappingEndpointIndependent
|
res.Mapping = MappingEndpointIndependent
|
||||||
} else {
|
} else {
|
||||||
res.Mapping = MappingAddressPortDependent
|
res.Mapping = MappingAddressPortDependent
|
||||||
@@ -223,7 +223,7 @@ func DetectNAT(conn net.PacketConn, primarySTUN, secondarySTUN, network string,
|
|||||||
resp3, _, err := performTest(conn, altPortSTUN, network, timeout, false, false)
|
resp3, _, err := performTest(conn, altPortSTUN, network, timeout, false, false)
|
||||||
if err == nil && resp3 != nil {
|
if err == nil && resp3 != nil {
|
||||||
if mappedAddr3 := resp3.GetMappedAddress(); mappedAddr3 != nil {
|
if mappedAddr3 := resp3.GetMappedAddress(); mappedAddr3 != nil {
|
||||||
if mappedAddr1.String() == mappedAddr3.String() {
|
if mappedAddr1.IP.Equal(mappedAddr3.IP) && mappedAddr1.Port == mappedAddr3.Port {
|
||||||
res.Mapping = MappingAddressDependent
|
res.Mapping = MappingAddressDependent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -180,9 +180,9 @@ func (c *socks5PacketConn) SetWriteDeadline(t time.Time) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DialSocks5UDP 建立SOCKS5 UDP关联
|
// DialSocks5UDP 建立SOCKS5 UDP关联
|
||||||
// 入参: proxyAddr 代理服务器地址, network 网络协议(udp/udp4/udp6)
|
// 入参: proxyAddr 代理服务器地址, network 网络协议(udp/udp4/udp6), timeout 超时时间
|
||||||
// 返回: conn 数据包连接, err 连接错误
|
// 返回: conn 数据包连接, err 连接错误
|
||||||
func DialSocks5UDP(proxyAddr, network string) (net.PacketConn, error) {
|
func DialSocks5UDP(proxyAddr, network string, timeout time.Duration) (net.PacketConn, error) {
|
||||||
var host string
|
var host string
|
||||||
if strings.Contains(proxyAddr, "://") {
|
if strings.Contains(proxyAddr, "://") {
|
||||||
u, err := url.Parse(proxyAddr)
|
u, err := url.Parse(proxyAddr)
|
||||||
@@ -200,7 +200,7 @@ func DialSocks5UDP(proxyAddr, network string) (net.PacketConn, error) {
|
|||||||
case "udp6":
|
case "udp6":
|
||||||
tcpNetwork = "tcp6"
|
tcpNetwork = "tcp6"
|
||||||
}
|
}
|
||||||
conn, err := net.DialTimeout(tcpNetwork, host, 5*time.Second)
|
conn, err := net.DialTimeout(tcpNetwork, host, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user