Skip to content

Commit

Permalink
Add support for updateRouteOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jan 11, 2025
1 parent 8b2883c commit 78c520a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions Library/Network/ExtensionPlatformInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
}

private func openTun0(_ options: LibboxTunOptionsProtocol?, _ ret0_: UnsafeMutablePointer<Int32>?) async throws {
guard let options else {
throw NSError(domain: "nil options", code: 0)
}
guard let ret0_ else {
throw NSError(domain: "nil return pointer", code: 0)
}

try await updateRouteOptions0(options)

if let tunFd = tunnel.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32 {
ret0_.pointee = tunFd
return
}

let tunFdFromLoop = LibboxGetTunnelFileDescriptor()
if tunFdFromLoop != -1 {
ret0_.pointee = tunFdFromLoop
} else {
throw NSError(domain: "missing file descriptor", code: 0)
}
}

public func updateRouteOptions(_ options: (any LibboxTunOptionsProtocol)?) throws {
try runBlocking { [self] in
try await updateRouteOptions0(options)
}
}

private func updateRouteOptions0(_ options: (any LibboxTunOptionsProtocol)?) async throws {
guard let options else {
throw NSError(domain: "nil options", code: 0)
}

let autoRouteUseSubRangesByDefault = await SharedPreferences.autoRouteUseSubRangesByDefault.get()
let excludeAPNs = await SharedPreferences.excludeAPNsRoute.get()

Expand Down Expand Up @@ -176,18 +199,6 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc

networkSettings = settings
try await tunnel.setTunnelNetworkSettings(settings)

if let tunFd = tunnel.packetFlow.value(forKeyPath: "socket.fileDescriptor") as? Int32 {
ret0_.pointee = tunFd
return
}

let tunFdFromLoop = LibboxGetTunnelFileDescriptor()
if tunFdFromLoop != -1 {
ret0_.pointee = tunFdFromLoop
} else {
throw NSError(domain: "missing file descriptor", code: 0)
}
}

public func usePlatformAutoDetectControl() -> Bool {
Expand Down

0 comments on commit 78c520a

Please sign in to comment.