fix
This commit is contained in:
parent
5358d9a2b7
commit
2e311cbf9e
@ -41,7 +41,7 @@ actor SDLPuncherActor {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingRequests[dstMac] = .init(expireAt: Date().addingTimeInterval(cooldownInterval), request: request)
|
self.pendingRequests[dstMac] = .init(expireAt: Date().addingTimeInterval(cooldownInterval), request: request)
|
||||||
// 触发一次打洞
|
// 触发一次打洞
|
||||||
var queryInfo = SDLQueryInfo()
|
var queryInfo = SDLQueryInfo()
|
||||||
queryInfo.dstMac = request.dstMac
|
queryInfo.dstMac = request.dstMac
|
||||||
@ -51,11 +51,17 @@ actor SDLPuncherActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlePeerInfo(using udpHole: SDLUDPHole?, peerInfo: SDLPeerInfo) async {
|
func handlePeerInfo(using udpHole: SDLUDPHole?, peerInfo: SDLPeerInfo) async {
|
||||||
guard let udpHole, let requestContext = pendingRequests.removeValue(forKey: peerInfo.dstMac),
|
// 如果服务器返回了值,优先删除掉; 避免数据堆积
|
||||||
let remoteAddress = try? await peerInfo.v4Info.socketAddress() else {
|
guard let requestContext = pendingRequests.removeValue(forKey: peerInfo.dstMac) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断必要的值是否存在
|
||||||
|
guard let udpHole, peerInfo.hasV4Info else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let remoteAddress = try? await peerInfo.v4Info.socketAddress() {
|
||||||
SDLLogger.shared.log("[SDLContext] hole sock address: \(remoteAddress)", level: .debug)
|
SDLLogger.shared.log("[SDLContext] hole sock address: \(remoteAddress)", level: .debug)
|
||||||
// 发送register包
|
// 发送register包
|
||||||
var register = SDLRegister()
|
var register = SDLRegister()
|
||||||
@ -67,6 +73,7 @@ actor SDLPuncherActor {
|
|||||||
udpHole.send(type: .register, data: registerData, remoteAddress: remoteAddress)
|
udpHole.send(type: .register, data: registerData, remoteAddress: remoteAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 判断是否需要提交
|
// 判断是否需要提交
|
||||||
func isRequestExpired(dstMac: Data) -> Bool {
|
func isRequestExpired(dstMac: Data) -> Bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user