Linux maintainer tooling and workflows
 help / color / Atom feed
* [PATCH b4] Delay dns.resolver.get_default_resolver call
@ 2021-02-08  4:07 Kyle Meyer
  0 siblings, 0 replies; only message in thread
From: Kyle Meyer @ 2021-02-08  4:07 UTC (permalink / raw)
  To: tools

When b4.attestation-policy is 'off', calling `b4 am` with
--use-local-mbox is conceptually an offline operation, but it still
requires being online because get_default_resolver() is called at the
top-level of b4/

Support offline operation by delaying the call to
get_default_resolver() until it's needed.  Note that
get_default_resolver() already caches the result, so there's no need
for b4 to store the result as a global variable on its end.

Signed-off-by: Kyle Meyer <>
 b4/ | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/b4/ b/b4/
index 17fae0e..49304fd 100644
--- a/b4/
+++ b/b4/
@@ -33,10 +33,8 @@
     import dkim
     can_dkim_verify = True
-    _resolver = dns.resolver.get_default_resolver()
 except ModuleNotFoundError:
     can_dkim_verify = False
-    _resolver = None
 __VERSION__ = '0.6.3-dev'
@@ -1703,7 +1701,8 @@ def __init__(self, msg):
             ddata = get_parts_from_header(dks)
             self.attestor = LoreAttestorDKIM(ddata['d'])
             # Do we have a resolve method?
-            if _resolver and hasattr(_resolver, 'resolve'):
+            resolver = get_resolver()
+            if resolver and hasattr(resolver, 'resolve'):
                 res = dkim.verify(self.msg.as_bytes(), dnsfunc=dkim_get_txt)
                 res = dkim.verify(self.msg.as_bytes())
@@ -2448,13 +2447,19 @@ def validate_gpg_signature(output, trustmodel):
     return good, valid, trusted, attestor, sigdate, errors
+def get_resolver():
+    if can_dkim_verify:
+        return dns.resolver.get_default_resolver()
 def dkim_get_txt(name: bytes, timeout: int = 5):
     global _DKIM_DNS_CACHE
     if name not in _DKIM_DNS_CACHE:
         lookup = name.decode()
         logger.debug('DNS-lookup: %s', lookup)
+        resolver = get_resolver()
-            a = _resolver.resolve(lookup, dns.rdatatype.TXT, raise_on_no_answer=False, lifetime=timeout, search=True)
+            a = resolver.resolve(lookup, dns.rdatatype.TXT, raise_on_no_answer=False, lifetime=timeout, search=True)
             for r in a.response.answer:
                 if r.rdtype == dns.rdatatype.TXT:
                     for item in r.items:

base-commit: f93bbd3e50b1fb4507aa537f4004da545af9d890

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08  4:07 [PATCH b4] Delay dns.resolver.get_default_resolver call Kyle Meyer

Linux maintainer tooling and workflows

Archives are clonable:
	git clone --mirror tools/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tools tools/ \
	public-inbox-index tools

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone