Update library
- Make userInfo AnyHashable - Prepare for profile processing in tunnel
This commit is contained in:
parent
dfae6afcb4
commit
e663f48bc3
|
@ -41,7 +41,7 @@
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "d033e4431a24c7a7559464ef27036af9994647f2"
|
"revision" : "ee6d15d4776bb1f7cf13aa22c07ef98abb9d6c12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "d033e4431a24c7a7559464ef27036af9994647f2"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "ee6d15d4776bb1f7cf13aa22c07ef98abb9d6c12"),
|
||||||
// .package(path: "../../passepartoutkit-source"),
|
// .package(path: "../../passepartoutkit-source"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
||||||
|
|
|
@ -37,7 +37,7 @@ public struct EditableProfile: MutableProfileType {
|
||||||
|
|
||||||
public var modulesMetadata: [UUID: ModuleMetadata]?
|
public var modulesMetadata: [UUID: ModuleMetadata]?
|
||||||
|
|
||||||
public var userInfo: [String: AnyHashable]?
|
public var userInfo: AnyHashable?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
id: UUID = UUID(),
|
id: UUID = UUID(),
|
||||||
|
@ -45,7 +45,7 @@ public struct EditableProfile: MutableProfileType {
|
||||||
modules: [any ModuleBuilder] = [],
|
modules: [any ModuleBuilder] = [],
|
||||||
activeModulesIds: Set<UUID> = [],
|
activeModulesIds: Set<UUID> = [],
|
||||||
modulesMetadata: [UUID: ModuleMetadata]? = nil,
|
modulesMetadata: [UUID: ModuleMetadata]? = nil,
|
||||||
userInfo: [String: AnyHashable]? = nil
|
userInfo: AnyHashable? = nil
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
|
@ -69,17 +69,7 @@ extension ProfileAttributes: CustomDebugStringConvertible {
|
||||||
// MARK: - UserInfoCodable
|
// MARK: - UserInfoCodable
|
||||||
|
|
||||||
extension ProfileAttributes: UserInfoCodable {
|
extension ProfileAttributes: UserInfoCodable {
|
||||||
public var userInfo: [String: AnyHashable]? {
|
public init?(userInfo: AnyHashable?) {
|
||||||
do {
|
|
||||||
let data = try JSONEncoder().encode(self)
|
|
||||||
return try JSONSerialization.jsonObject(with: data) as? [String: AnyHashable] ?? [:]
|
|
||||||
} catch {
|
|
||||||
pp_log(.App.profiles, .error, "Unable to encode ProfileAttributes to dictionary: \(error)")
|
|
||||||
return [:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public init?(userInfo: [String: AnyHashable]?) {
|
|
||||||
do {
|
do {
|
||||||
let data = try JSONSerialization.data(withJSONObject: userInfo ?? [:])
|
let data = try JSONSerialization.data(withJSONObject: userInfo ?? [:])
|
||||||
self = try JSONDecoder().decode(ProfileAttributes.self, from: data)
|
self = try JSONDecoder().decode(ProfileAttributes.self, from: data)
|
||||||
|
@ -88,6 +78,16 @@ extension ProfileAttributes: UserInfoCodable {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var userInfo: AnyHashable? {
|
||||||
|
do {
|
||||||
|
let data = try JSONEncoder().encode(self)
|
||||||
|
return try JSONSerialization.jsonObject(with: data) as? AnyHashable
|
||||||
|
} catch {
|
||||||
|
pp_log(.App.profiles, .error, "Unable to encode ProfileAttributes to dictionary: \(error)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Profile {
|
extension Profile {
|
||||||
|
|
|
@ -41,10 +41,16 @@ final class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
|
||||||
provider: self,
|
provider: self,
|
||||||
decoder: Registry.sharedProtocolCoder,
|
decoder: Registry.sharedProtocolCoder,
|
||||||
registry: .shared,
|
registry: .shared,
|
||||||
environment: .shared
|
environment: .shared,
|
||||||
|
profileBlock: {
|
||||||
|
$0
|
||||||
|
}
|
||||||
)
|
)
|
||||||
try await checkEligibility(of: fwd!.profile, environment: .shared)
|
guard let fwd else {
|
||||||
try await fwd?.startTunnel(options: options)
|
fatalError("NEPTPForwarder nil without throwing error?")
|
||||||
|
}
|
||||||
|
try await checkEligibility(of: fwd.profile, environment: .shared)
|
||||||
|
try await fwd.startTunnel(options: options)
|
||||||
} catch {
|
} catch {
|
||||||
pp_log(.app, .fault, "Unable to start tunnel: \(error)")
|
pp_log(.app, .fault, "Unable to start tunnel: \(error)")
|
||||||
PassepartoutConfiguration.shared.flushLog()
|
PassepartoutConfiguration.shared.flushLog()
|
||||||
|
|
Loading…
Reference in New Issue