Skip to content

Commit

Permalink
Provide DNS on WASM via dnsHttpResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Nov 2, 2024
1 parent 19348d5 commit 5ddde48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions soup/dnsHttpResolver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "dnsHttpResolver.hpp"

#if !SOUP_WASM

#include "base64.hpp"
#include "DelayedCtor.hpp"
#include "HttpRequest.hpp"
Expand All @@ -12,6 +10,9 @@ NAMESPACE_SOUP
{
Optional<std::vector<UniquePtr<dnsRecord>>> dnsHttpResolver::lookup(dnsType qtype, const std::string& name) const
{
#if SOUP_WASM
SOUP_ASSERT(false, "Blocking lookup is not supported under WASM");
#else
std::vector<UniquePtr<dnsRecord>> res;
if (checkBuiltinResult(res, qtype, name))
{
Expand All @@ -25,6 +26,7 @@ NAMESPACE_SOUP
auto hres = hr.execute(keep_alive_sched);

return parseResponse(std::move(hres->body));
#endif
}

struct dnsHttpLookupTask : public dnsLookupTask
Expand Down Expand Up @@ -75,5 +77,3 @@ NAMESPACE_SOUP
return soup::make_unique<dnsHttpLookupTask>(std::move(server), qtype, name);
}
}

#endif
5 changes: 0 additions & 5 deletions soup/dnsHttpResolver.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#include "base.hpp"
#if !SOUP_WASM

#include "dnsRawResolver.hpp"

NAMESPACE_SOUP
Expand All @@ -16,5 +13,3 @@ NAMESPACE_SOUP
[[nodiscard]] UniquePtr<dnsLookupTask> makeLookupTask(dnsType qtype, const std::string& name) const final;
};
}

#endif
13 changes: 10 additions & 3 deletions soup/netConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "netConfig.hpp"
#if !SOUP_WASM

#if SOUP_WASM
#include "dnsHttpResolver.hpp"
#else
#include "dnsSmartResolver.hpp"
#endif
#include "Socket.hpp"

NAMESPACE_SOUP
Expand All @@ -17,18 +20,22 @@ NAMESPACE_SOUP
{
if (!dns_resolver)
{
#if SOUP_WASM
dns_resolver = soup::make_unique<dnsHttpResolver>();
#else
// Reasons for not defaulting to dnsOsResolver:
// - Android doesn't have libresolv
// - Many ISPs provide disingenuous DNS servers, even blocking sites like pastebin.com
dns_resolver = soup::make_unique<dnsSmartResolver>();
#endif
}
return *dns_resolver;
}

netConfig::netConfig()
#if !SOUP_WASM
: certchain_validator(&Socket::certchain_validator_default)
#endif
{
}
}

#endif
8 changes: 4 additions & 4 deletions soup/netConfig.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include "base.hpp"
#if !SOUP_WASM

#include "type.hpp"

#include "dnsResolver.hpp"
Expand All @@ -14,14 +12,16 @@ NAMESPACE_SOUP
{
[[nodiscard]] static netConfig& get(); // returns the netConfig instance for this thread

#if !SOUP_WASM
int connect_timeout_ms = 3000;
#endif
UniquePtr<dnsResolver> dns_resolver;
#if !SOUP_WASM
certchain_validator_t certchain_validator;
#endif

[[nodiscard]] dnsResolver& getDnsResolver() SOUP_EXCAL;

netConfig();
};
}

#endif

0 comments on commit 5ddde48

Please sign in to comment.