fix superServiceProxy
This commit is contained in:
parent
082fb1547e
commit
e78e49c45b
@ -70,8 +70,8 @@ actor SDLContextActor {
|
|||||||
|
|
||||||
private var udpHoleService: SDLUDPHoleService?
|
private var udpHoleService: SDLUDPHoleService?
|
||||||
private var dnsService: SDLDNSService?
|
private var dnsService: SDLDNSService?
|
||||||
private var superService: SDLSuperService?
|
|
||||||
private var packetReaderService: SDLPacketReaderService?
|
private var packetReaderService: SDLPacketReaderService?
|
||||||
|
private let superServiceProxy = SDLSuperServiceProxy()
|
||||||
|
|
||||||
private let publicDnsServers = ["223.5.5.5", "119.29.29.29"]
|
private let publicDnsServers = ["223.5.5.5", "119.29.29.29"]
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ actor SDLContextActor {
|
|||||||
let superService = SDLSuperService(host: self.config.serverHost) { [weak self] message in
|
let superService = SDLSuperService(host: self.config.serverHost) { [weak self] message in
|
||||||
await self?.handleSuperMessage(message: message)
|
await self?.handleSuperMessage(message: message)
|
||||||
}
|
}
|
||||||
self.superService = superService
|
await self.superServiceProxy.replace(superService)
|
||||||
await superService.start()
|
await superService.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +165,7 @@ actor SDLContextActor {
|
|||||||
self.dnsService = nil
|
self.dnsService = nil
|
||||||
await dnsService?.stop()
|
await dnsService?.stop()
|
||||||
|
|
||||||
let superService = self.superService
|
await self.superServiceProxy.stop()
|
||||||
self.superService = nil
|
|
||||||
await superService?.stop()
|
|
||||||
|
|
||||||
self.sessionToken = nil
|
self.sessionToken = nil
|
||||||
self.dataCipher = nil
|
self.dataCipher = nil
|
||||||
@ -320,7 +318,7 @@ extension SDLContextActor {
|
|||||||
while true {
|
while true {
|
||||||
try await Task.sleep(for: .seconds(300))
|
try await Task.sleep(for: .seconds(300))
|
||||||
SDLLogger.log("[SDLContext] updatePolicyTask execute")
|
SDLLogger.log("[SDLContext] updatePolicyTask execute")
|
||||||
await self.policyService.updatePolicy(superService: self.superService)
|
await self.policyService.updatePolicy(superServiceProxy: self.superServiceProxy)
|
||||||
}
|
}
|
||||||
} catch let err {
|
} catch let err {
|
||||||
SDLLogger.log("[SDLContext] updatePolicyTask stop with err: \(err)")
|
SDLLogger.log("[SDLContext] updatePolicyTask stop with err: \(err)")
|
||||||
@ -389,7 +387,7 @@ extension SDLContextActor {
|
|||||||
|
|
||||||
if let registerSuperData = try? registerSuper.serializedData() {
|
if let registerSuperData = try? registerSuper.serializedData() {
|
||||||
SDLLogger.log("[SDLContext] will send register super")
|
SDLLogger.log("[SDLContext] will send register super")
|
||||||
await self.superService?.send(type: .registerSuper, data: registerSuperData)
|
await self.superServiceProxy.send(type: .registerSuper, data: registerSuperData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,7 +503,7 @@ extension SDLContextActor {
|
|||||||
case .requestPolicy(let srcIdentityID):
|
case .requestPolicy(let srcIdentityID):
|
||||||
SDLLogger.log("[SDLContext] not found identity: \(srcIdentityID) ruleMap", for: .debug)
|
SDLLogger.log("[SDLContext] not found identity: \(srcIdentityID) ruleMap", for: .debug)
|
||||||
if let queryData = await self.policyService.identifyStore.makePolicyRequest(srcIdentityId: srcIdentityID, dstIdentityId: self.config.identityId) {
|
if let queryData = await self.policyService.identifyStore.makePolicyRequest(srcIdentityId: srcIdentityID, dstIdentityId: self.config.identityId) {
|
||||||
await self.superService?.send(type: .policyRequest, data: queryData)
|
await self.superServiceProxy.send(type: .policyRequest, data: queryData)
|
||||||
}
|
}
|
||||||
case .none:
|
case .none:
|
||||||
()
|
()
|
||||||
@ -721,7 +719,7 @@ extension SDLContextActor {
|
|||||||
else {
|
else {
|
||||||
SDLLogger.log("[SDLContext] dstIp: \(asIpAddress(ip)) arp query not found, broadcast", for: .trace)
|
SDLLogger.log("[SDLContext] dstIp: \(asIpAddress(ip)) arp query not found, broadcast", for: .trace)
|
||||||
if let arpRequest = try? await self.arpServer.makeArpRequest(targetIp: ip) {
|
if let arpRequest = try? await self.arpServer.makeArpRequest(targetIp: ip) {
|
||||||
await self.superService?.send(type: .arpRequest, data: arpRequest)
|
await self.superServiceProxy.send(type: .arpRequest, data: arpRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -762,7 +760,7 @@ extension SDLContextActor {
|
|||||||
|
|
||||||
// 尝试打洞
|
// 尝试打洞
|
||||||
if let queryData = await self.puncherActor.makeQueryInfoRequest(request: request) {
|
if let queryData = await self.puncherActor.makeQueryInfoRequest(request: request) {
|
||||||
await self.superService?.send(type: .queryInfo, data: queryData)
|
await self.superServiceProxy.send(type: .queryInfo, data: queryData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,14 +58,10 @@ actor PolicyService {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePolicy(superService: SDLSuperService?) async {
|
func updatePolicy(superServiceProxy: SDLSuperServiceProxy) async {
|
||||||
guard let superService else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let requests = await self.identifyStore.makeBatchPolicyRequests(dstIdentityID: self.identityId)
|
let requests = await self.identifyStore.makeBatchPolicyRequests(dstIdentityID: self.identityId)
|
||||||
for request in requests {
|
for request in requests {
|
||||||
await superService.send(type: .policyRequest, data: request)
|
await superServiceProxy.send(type: .policyRequest, data: request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -109,3 +109,32 @@ actor SDLSuperService {
|
|||||||
SDLLogger.log("[SDLSuperService] cleanup")
|
SDLLogger.log("[SDLSuperService] cleanup")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actor SDLSuperServiceProxy {
|
||||||
|
private var superService: SDLSuperService?
|
||||||
|
private var generation: UInt64 = 0
|
||||||
|
|
||||||
|
func replace(_ superService: SDLSuperService?) async {
|
||||||
|
self.generation &+= 1
|
||||||
|
|
||||||
|
let oldSuperService = self.superService
|
||||||
|
self.superService = superService
|
||||||
|
|
||||||
|
if oldSuperService !== superService {
|
||||||
|
await oldSuperService?.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stop() async {
|
||||||
|
self.generation &+= 1
|
||||||
|
|
||||||
|
let superService = self.superService
|
||||||
|
self.superService = nil
|
||||||
|
|
||||||
|
await superService?.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func send(type: SDLPacketType, data: Data) async {
|
||||||
|
await self.superService?.send(type: type, data: data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user