diff --git a/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/project.pbxproj b/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/project.pbxproj index 3697f46..afcafeb 100644 --- a/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/project.pbxproj +++ b/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/project.pbxproj @@ -378,7 +378,7 @@ DEVELOPMENT_TEAM = W5364U7YZB; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; - FRAMEWORK_SEARCH_PATHS = ../../build/Build; + FRAMEWORK_SEARCH_PATHS = "../../build/Build/**"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HelloFromTailscale/Info.plist; INFOPLIST_KEY_NSHumanReadableCopyright = ""; @@ -407,7 +407,7 @@ DEVELOPMENT_TEAM = W5364U7YZB; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; - FRAMEWORK_SEARCH_PATHS = ../../build/Build; + FRAMEWORK_SEARCH_PATHS = "../../build/Build/**"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = HelloFromTailscale/Info.plist; INFOPLIST_KEY_NSHumanReadableCopyright = ""; diff --git a/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/xcshareddata/xcschemes/HelloFromTailscale_macOS.xcscheme b/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/xcshareddata/xcschemes/HelloFromTailscale_macOS.xcscheme new file mode 100644 index 0000000..98ffa64 --- /dev/null +++ b/swift/Examples/TailscaleKitHello/TailscaleKitHello.xcodeproj/xcshareddata/xcschemes/HelloFromTailscale_macOS.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/swift/TailscaleKit/LocalAPI/MessageProcessor.swift b/swift/TailscaleKit/LocalAPI/MessageProcessor.swift index 7d680db..a851378 100644 --- a/swift/TailscaleKit/LocalAPI/MessageProcessor.swift +++ b/swift/TailscaleKit/LocalAPI/MessageProcessor.swift @@ -91,7 +91,7 @@ public class MessageProcessor: @unchecked Sendable { await consumer.notify(notify) } } catch { - logger?.log("Failed to decode message: \(String(data: line, encoding: .utf8) ?? "nil")") + logger?.log("Failed to decode message: \(error.localizedDescription)") } } } diff --git a/swift/TailscaleKit/LocalAPI/Types.swift b/swift/TailscaleKit/LocalAPI/Types.swift index 707b630..76132e6 100644 --- a/swift/TailscaleKit/LocalAPI/Types.swift +++ b/swift/TailscaleKit/LocalAPI/Types.swift @@ -237,6 +237,7 @@ public struct IpnState: Sendable { public var Addrs: [String]? public var CurAddr: String? public var Relay: String? + public var PeerRelay: String? public var Online: Bool public var ExitNode: Bool public var ExitNodeOption: Bool @@ -296,7 +297,7 @@ public struct IpnState: Sendable { public var MagicDNSEnabled: Bool } - struct PingResult: Codable, Sendable { + struct PingResult: Codable, Sendable { public var IP: IP.Addr public var Err: String public var LatencySeconds: TimeInterval @@ -308,7 +309,6 @@ public struct Netmap: Sendable { public var SelfNode: Tailcfg.Node public var NodeKey: Key.NodePublic public var Peers: [Tailcfg.Node]? - public var Expiry: Time.Time public var Domain: String public var UserProfiles: [String: Tailcfg.UserProfile] // Keys are tailcfg.UserIDs thet get stringified public var DNS: Tailcfg.DNSConfig? @@ -321,18 +321,10 @@ public struct Netmap: Sendable { return UserProfiles[String(id)] } - public func isExpired() -> Bool { - if let expiryDate = Expiry.iso8601Date() { - return (expiryDate as NSDate).earlierDate(Date()) == expiryDate - } - return false - } - public static func == (lhs: Netmap.NetworkMap, rhs: Netmap.NetworkMap) -> Bool { lhs.SelfNode == rhs.SelfNode && lhs.NodeKey == rhs.NodeKey && lhs.Peers == rhs.Peers && - lhs.Expiry == rhs.Expiry && lhs.Domain == rhs.Domain && lhs.UserProfiles == rhs.UserProfiles && lhs.DNS == rhs.DNS @@ -362,8 +354,7 @@ public struct Tailcfg: Sendable { public var User: Tailcfg.UserID public var Sharer: Tailcfg.UserID? public var Key: Key.NodePublic - public var KeyExpiry: Time.Time - public var Machine: Tailcfg.MachineKey + public var KeyExpiry: Time.Time? public var Addresses: [IP.Prefix]? public var AllowedIPs: [IP.Prefix]? public var Hostinfo: Hostinfo @@ -408,7 +399,7 @@ public struct Tailcfg: Sendable { return false } - if let expiryDate = KeyExpiry.iso8601Date() { + if let expiryDate = KeyExpiry?.iso8601Date() { return (expiryDate as NSDate).earlierDate(Date()) == expiryDate && !KeyDoesNotExpire } @@ -452,6 +443,7 @@ public struct Tailcfg: Sendable { public struct NetworkProfile: Codable, Equatable, Sendable { public var MagicDNSName: String? public var DomainName: String? + public var DisplayName: String? } public struct DNSRecord: Codable, Sendable, Equatable { @@ -504,3 +496,4 @@ struct GoError: Codable, Sendable, LocalizedError { return Error } } + diff --git a/swift/TailscaleKit/URLSession+Tailscale.swift b/swift/TailscaleKit/URLSession+Tailscale.swift index 36bcc3d..e0afbc2 100644 --- a/swift/TailscaleKit/URLSession+Tailscale.swift +++ b/swift/TailscaleKit/URLSession+Tailscale.swift @@ -5,9 +5,11 @@ import UIKit #endif +import Network + public extension URLSessionConfiguration { - /// Adds the a connectionProxyDictionary to a URLSessionConfiguration to + /// Adds the a ProxyConfiguration to a URLSessionConfiguration to /// proxy all requests through the given TailscaleNode. /// /// This can also be use to make requests to LocalAPI. See LocalAPIClient @@ -19,17 +21,15 @@ public extension URLSessionConfiguration { throw TailscaleError.invalidProxyAddress } + let endpoint = NWEndpoint.hostPort(host: NWEndpoint.Host(ip), + port: NWEndpoint.Port(rawValue: UInt16(port))!) + + let sessionProxyConfig = ProxyConfiguration(socksv5Proxy: endpoint) + sessionProxyConfig.applyCredential(username: "tsnet", password: + proxyConfig.proxyCredential) - let config: [CFString: Any] = [ - kCFProxyTypeKey: kCFProxyTypeSOCKS, - kCFProxyUsernameKey: "tsnet", - kCFProxyPasswordKey: proxyConfig.proxyCredential, - kCFProxyHostNameKey: ip, - kCFProxyPortNumberKey: port - ] + self.proxyConfigurations = [sessionProxyConfig] - self.connectionProxyDictionary = config - return proxyConfig }