pull/1688/head
jeff 3 years ago committed by Jeff Becker
parent 1272a4fbe1
commit deb0a982be
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -22,6 +22,9 @@ class LokinetMain: NSObject, NSApplicationDelegate {
NSLog("setting up dns settings")
let dns = NEDNSSettingsManager.shared()
let settings = NEDNSSettings(servers: ["172.16.0.1"])
settings.matchDomains = ["*.loki", "*.snode"]
settings.matchDomainsNoSearch = true
settings.domainName = "localhost.loki"
dns.dnsSettings = settings
dns.loadFromPreferences { [self] (error: Error?) -> Void in
if let error = error {
@ -94,6 +97,7 @@ class LokinetMain: NSObject, NSApplicationDelegate {
providerProtocol.serverAddress = "loki.loki" // Needs to be set to some non-null dummy value
providerProtocol.username = "anonymous"
providerProtocol.providerBundleIdentifier = self.lokinetComponent
providerProtocol.enforceRoutes = true
// macos seems to have trouble when this is true, and reports are that this breaks and
// doesn't do what it says on the tin in the first place. Needs more testing.
providerProtocol.includeAllNetworks = false
@ -155,7 +159,6 @@ class LokinetMain: NSObject, NSApplicationDelegate {
NSLog("VPN is disconnecting...")
} else if self.vpnManager.connection.status == .connected {
NSLog("VPN Connected")
self.setupDNSJizz()
}
}
}

@ -1448,13 +1448,13 @@ namespace llarp
#ifdef __APPLE__
std::shared_ptr<Config>
Config::NetworkExtensionConfig()
Config::NetworkExtensionConfig(std::string exit)
{
auto config = std::make_shared<Config>(fs::path{});
config->Load();
config->logging.m_logLevel = eLogInfo;
config->network.m_saveProfiles = false;
config->bootstrap.files.clear();
config->network.m_LNSExitMap.Insert(IPRange{}, exit);
return config;
}
#endif

@ -262,7 +262,7 @@ namespace llarp
#ifdef __APPLE__
static std::shared_ptr<Config>
NetworkExtensionConfig();
NetworkExtensionConfig(std::string exit);
#endif
private:

@ -138,8 +138,8 @@ namespace llarp
if (IsStopping())
return;
if (CallSafe(std::bind(&Context::HandleSignal, this, SIGTERM)))
closeWaiter = std::make_unique<std::promise<void>>();
loop->call([this]() { HandleSignal(SIGTERM); });
closeWaiter = std::make_unique<std::promise<void>>();
}
bool

@ -26,7 +26,7 @@ namespace llarp::apple
makeVPNPlatform() override;
void
Start(std::string_view bootstrap);
Start(std::string_view bootstrap, std::string exit);
private:
NEPacketTunnelProvider* const m_Tunnel;
@ -137,29 +137,30 @@ namespace llarp::apple
{}
void
FrameworkContext::Start(std::string_view bootstrap)
FrameworkContext::Start(std::string_view bootstrap, std::string exit)
{
std::promise<void> result;
m_Runner = std::make_unique<std::thread>([&result, bootstrap = std::string{bootstrap}, this]() {
const RuntimeOptions opts{};
try
{
auto config = llarp::Config::NetworkExtensionConfig();
config->bootstrap.files.emplace_back(bootstrap);
config->dns.m_bind = DefaultDNSBind;
config->dns.m_upstreamDNS.push_back(DefaultUpstreamDNS);
Configure(std::move(config));
Setup(opts);
}
catch (std::exception&)
{
result.set_exception(std::current_exception());
return;
}
result.set_value();
Run(opts);
});
m_Runner =
std::make_unique<std::thread>([&result, bootstrap = std::string{bootstrap}, exit, this]() {
const RuntimeOptions opts{};
try
{
auto config = llarp::Config::NetworkExtensionConfig(exit);
config->bootstrap.files.emplace_back(bootstrap);
config->dns.m_bind = DefaultDNSBind;
config->dns.m_upstreamDNS.push_back(DefaultUpstreamDNS);
Configure(std::move(config));
Setup(opts);
}
catch (std::exception&)
{
result.set_exception(std::current_exception());
return;
}
result.set_value();
Run(opts);
});
auto ftr = result.get_future();
ftr.get();
@ -182,10 +183,10 @@ struct ContextWrapper
{}
void
Start(std::string_view bootstrap)
Start(std::string_view bootstrap, std::string exit)
{
llarp::LogContext::Instance().logStream.reset(new llarp::NSLogStream{});
m_Context->Start(std::move(bootstrap));
m_Context->Start(std::move(bootstrap), std::move(exit));
}
void
@ -210,20 +211,29 @@ struct ContextWrapper
}
NSString* addr = StringToNSString(addr_.ToString());
NSString* mask = StringToNSString(mask_.ToString());
llarp::huint32_t dnsaddr_{addr_ & mask_};
NSString* dnsaddr = StringToNSString(dnsaddr_.ToString());
NSLog(@"%@", dnsaddr);
NSBundle* main = [NSBundle mainBundle];
NSString* res = [main pathForResource:@"bootstrap" ofType:@"signed"];
NSData* path = [res dataUsingEncoding:NSUTF8StringEncoding];
m_Context = new ContextWrapper{self};
m_Context->Start(DataAsStringView(path));
m_Context->Start(DataAsStringView(path), "exit.loki");
NEPacketTunnelNetworkSettings* settings =
[[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:@"127.0.0.1"];
NEDNSSettings* dns = [[NEDNSSettings alloc] initWithServers:@[addr]];
NEDNSSettings* dns = [[NEDNSSettings alloc] initWithServers:@[dnsaddr]];
dns.domainName = @"localhost.loki";
dns.matchDomains = @[@"*.snode", @"*.loki"];
dns.matchDomainsNoSearch = true;
dns.searchDomains = @[];
// dns.dnsProtocol = NEDNSProtocolCleartext;
NEIPv4Settings* ipv4 = [[NEIPv4Settings alloc] initWithAddresses:@[addr]
subnetMasks:@[@"255.255.255.255"]];
ipv4.includedRoutes = @[[[NEIPv4Route alloc] initWithDestinationAddress:addr subnetMask:mask]];
ipv4.includedRoutes = @[[NEIPv4Route defaultRoute]];
// ipv4.includedRoutes = @[[[NEIPv4Route alloc] initWithDestinationAddress:addr subnetMask:mask]];
settings.IPv4Settings = ipv4;
settings.DNSSettings = dns;
[self setTunnelNetworkSettings:settings completionHandler:completionHandler];

Loading…
Cancel
Save