关于stunServer的tcp使用问题
在TCP网络中使用stunClient的连接stunServer时,出现了 2024-10-22 16:04:22.768 [WARN] [LianCheng] stun/stunclient.go:253 testFilterType err: dial addr(/ip4/47.98.238.134/tcp/3678) err:all dial failed, errors found below: [dial tcp 192.168.75.1:9001->47.98.238.134:3678: connectex: A socket operation was attempted to an unreachable network.][dial tcp 192.168.93.1:9001->47.98.238.134:3678: connectex: A socket operation was attempted to an unreachable network.][dial tcp 172.16.10.115:9001->47.98.238.134:3678: connectex: No connection could be made because the target machine actively refused it.] [dial tcp 127.0.0.1:9001->47.98.238.134:3678: connectex: A socket operation was attempted to an unreachable network.][dial tcp 47.98.238.134:3678: connectex: No connection could be made because the target machine actively refused it.]
服务器的端口配置如下: stunServerConfig: enableServer: true serverListenAddr1: "/ip4/127.0.0.1/tcp/3678" serverListenAddr2: "/ip4/127.0.0.1/tcp/3679" twoPublicAddress: true otherStunServerAddr: "/ip4/47.98.238.134/tcp/3681" serverListenAddr3: "/ip4/127.0.0.1/tcp/3680" serverListenAddr4: "/ip4/127.0.0.1/tcp/3681" notifyAddr: "http://127.0.0.1:8787" localNotifyAddr: "http://127.0.0.1:8788" networkType: "TCP" 服务器的输出如下: 2024-10-22 15:43:38.208 [INFO] [LianCheng] node/LCNode.go:103 [LcNode] network type: TCP 2024-10-22 15:43:38.235 [INFO] [LianCheng] host/host.go:310 [Host] register new msg payload handler (protocol id: /protocol-exchanger/v0.0.1) 2024-10-22 15:43:38.235 [INFO] [LianCheng] tcp/network.go:531 [Network] local peer id : QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.235 [INFO] [LianCheng] tcp/network.go:533 [Network] TLS enabled. 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:359 [Network] listening on address : /ip4/127.0.0.1/tcp/8081/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] host/host.go:273 [Host] host started. 2024-10-22 15:43:38.236 [DEBUG] [LianCheng] node/LCNode.go:263 initStunServer default 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:531 [Network] local peer id : QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:535 [Network] TLS disabled. 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:359 [Network] listening on address : /ip4/127.0.0.1/tcp/3680/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:531 [Network] local peer id : QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:535 [Network] TLS disabled. 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:359 [Network] listening on address : /ip4/127.0.0.1/tcp/3681/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:531 [Network] local peer id : QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:535 [Network] TLS disabled. 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:359 [Network] listening on address : /ip4/127.0.0.1/tcp/3678/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:531 [Network] local peer id : QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:535 [Network] TLS disabled. 2024-10-22 15:43:38.236 [INFO] [LianCheng] tcp/network.go:359 [Network] listening on address : /ip4/127.0.0.1/tcp/3679/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 2024-10-22 15:43:38.236 [INFO] [LianCheng] node/LCNode.go:133 [LCNet] initStunServer ok
客户端的配置如下: stunClientConfig: # 当enable==false时,其余配置信息都不会起作用 enable: true # 本地stun监听的地址 clientListenAddr: "/ip4/0.0.0.0/tcp/9001" stunServerAddr: "/ip4/47.98.238.134/tcp/3678"
调用的方法如下: func (l *LCNode) GetLocalNATType() (stun.NATDeviceType, error) { return l.stunClient.CheckNatType(l.host.ID().ToString(), l.stunClientCfg.ClientListenAddr, l.stunClientCfg.StunServerAddr) }