-
Notifications
You must be signed in to change notification settings - Fork 2
chore: pass session token to network extension #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--selfrequired log,info,error,debug,critical,fault | ||
--exclude **.pb.swift | ||
--condassignment always |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,61 @@ | ||
import NetworkExtension | ||
import os | ||
|
||
// swiftlint:disable:next function_body_length | ||
public func convertNetworkSettingsRequest(_ req: Vpn_NetworkSettingsRequest) -> NEPacketTunnelNetworkSettings { | ||
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: req.tunnelRemoteAddress) | ||
networkSettings.tunnelOverheadBytes = NSNumber(value: req.tunnelOverheadBytes) | ||
networkSettings.mtu = NSNumber(value: req.mtu) | ||
public func convertDnsSettings(_ req: Vpn_NetworkSettingsRequest.DNSSettings) -> NEDNSSettings { | ||
let dnsSettings = NEDNSSettings(servers: req.servers) | ||
dnsSettings.searchDomains = req.searchDomains | ||
dnsSettings.domainName = req.domainName | ||
dnsSettings.matchDomains = req.matchDomains | ||
dnsSettings.matchDomainsNoSearch = req.matchDomainsNoSearch | ||
return dnsSettings | ||
} | ||
|
||
if req.hasDnsSettings { | ||
let dnsSettings = NEDNSSettings(servers: req.dnsSettings.servers) | ||
dnsSettings.searchDomains = req.dnsSettings.searchDomains | ||
dnsSettings.domainName = req.dnsSettings.domainName | ||
dnsSettings.matchDomains = req.dnsSettings.matchDomains | ||
dnsSettings.matchDomainsNoSearch = req.dnsSettings.matchDomainsNoSearch | ||
networkSettings.dnsSettings = dnsSettings | ||
public func convertIPv4Settings(_ req: Vpn_NetworkSettingsRequest.IPv4Settings) -> NEIPv4Settings { | ||
let ipv4Settings = NEIPv4Settings(addresses: req.addrs, subnetMasks: req.subnetMasks) | ||
if !req.router.isEmpty { | ||
ipv4Settings.router = req.router | ||
} | ||
|
||
if req.hasIpv4Settings { | ||
let ipv4Settings = NEIPv4Settings(addresses: req.ipv4Settings.addrs, subnetMasks: req.ipv4Settings.subnetMasks) | ||
ipv4Settings.router = req.ipv4Settings.router | ||
ipv4Settings.includedRoutes = req.ipv4Settings.includedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
ipv4Settings.includedRoutes = req.includedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
if !$0.router.isEmpty { | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
ipv4Settings.excludedRoutes = req.ipv4Settings.excludedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
return route | ||
} | ||
ipv4Settings.excludedRoutes = req.excludedRoutes.map { | ||
let route = NEIPv4Route(destinationAddress: $0.destination, subnetMask: $0.mask) | ||
if !$0.router.isEmpty { | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
networkSettings.ipv4Settings = ipv4Settings | ||
return route | ||
} | ||
return ipv4Settings | ||
} | ||
|
||
if req.hasIpv6Settings { | ||
let ipv6Settings = NEIPv6Settings( | ||
addresses: req.ipv6Settings.addrs, | ||
networkPrefixLengths: req.ipv6Settings.prefixLengths.map { NSNumber(value: $0) | ||
} | ||
public func convertIPv6Settings(_ req: Vpn_NetworkSettingsRequest.IPv6Settings) -> NEIPv6Settings { | ||
let ipv6Settings = NEIPv6Settings( | ||
addresses: req.addrs, | ||
networkPrefixLengths: req.prefixLengths.map { NSNumber(value: $0) } | ||
) | ||
ipv6Settings.includedRoutes = req.includedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
ipv6Settings.includedRoutes = req.ipv6Settings.includedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
if !$0.router.isEmpty { | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
ipv6Settings.excludedRoutes = req.ipv6Settings.excludedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
return route | ||
} | ||
ipv6Settings.excludedRoutes = req.excludedRoutes.map { | ||
let route = NEIPv6Route( | ||
destinationAddress: $0.destination, | ||
networkPrefixLength: NSNumber(value: $0.prefixLength) | ||
) | ||
if !$0.router.isEmpty { | ||
route.gatewayAddress = $0.router | ||
return route | ||
} | ||
networkSettings.ipv6Settings = ipv6Settings | ||
return route | ||
} | ||
return networkSettings | ||
return ipv6Settings | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import SwiftProtobuf | |
actor Receiver<RecvMsg: Message> { | ||
private let dispatch: DispatchIO | ||
private let queue: DispatchQueue | ||
private var running = false | ||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "proto") | ||
|
||
/// Creates an instance using the given `DispatchIO` channel and queue. | ||
|
@@ -58,11 +57,7 @@ actor Receiver<RecvMsg: Message> { | |
/// Starts reading protocol messages from the `DispatchIO` channel and returns them as an `AsyncStream` of messages. | ||
/// On read or decoding error, it logs and closes the stream. | ||
func messages() throws(ReceiveError) -> AsyncStream<RecvMsg> { | ||
if running { | ||
throw .alreadyRunning | ||
} | ||
running = true | ||
return AsyncStream( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Even if it were possible, I don't think this check is of any value. Isn't it usually the case (in general) that iterating over the same (mutating) stream multiple times is just an incorrect use of an API? I think actor re-entrancy means it's possible to do so here. If we do want to keep the check, I'm open to suggestions on how best to do that. |
||
AsyncStream( | ||
unfolding: { | ||
do { | ||
let length = try await self.readLen() | ||
|
@@ -83,7 +78,6 @@ actor Receiver<RecvMsg: Message> { | |
enum ReceiveError: Error { | ||
case readError(String) | ||
case invalidLength | ||
case alreadyRunning | ||
} | ||
|
||
func deserializeLen(_ data: Data) throws -> UInt32 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the docs: