aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-06-15 17:39:58 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-06-15 17:39:58 +0200
commit7b861f4398407d289ece997715f3ffa828850130 (patch)
tree96f91848399496bfd2029cb4cb267d4972e7b76a /src
parent34a4a113854550e258b8fd8be914505507a9c3c7 (diff)
download0tdns-7b861f4398407d289ece997715f3ffa828850130.tar.gz
0tdns-7b861f4398407d289ece997715f3ffa828850130.zip
preform dns queries in threads, throttle requests to the same dns
Diffstat (limited to 'src')
-rwxr-xr-xsrc/perform_queries.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/perform_queries.py b/src/perform_queries.py
index 2ce7742..0d77355 100755
--- a/src/perform_queries.py
+++ b/src/perform_queries.py
@@ -1,6 +1,8 @@
#!/bin/python3
from sys import argv
+from threading import Thread
+from time import sleep
import unbound
# our own module used by several scripts in the project
@@ -85,8 +87,7 @@ config = get_ztdns_config()
connection = start_db_connection(config)
cursor = connection.cursor()
-contexts = []
-for dns_queries in query_planned_queries(cursor, hour, vpn_id):
+def query_dns(dns_queries):
ctx = unbound.ub_ctx()
ctx.set_fwd(dns_queries.dns_IP)
for service_id, service_name in dns_queries.services:
@@ -96,10 +97,18 @@ for dns_queries in query_planned_queries(cursor, hour, vpn_id):
ctx.resolve_async(service_name, query, resolve_call_back,
unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
- contexts.append(ctx)
+ sleep(0.4)
-for ctx in contexts:
ctx.wait()
+threads = []
+for dns_queries in query_planned_queries(cursor, hour, vpn_id):
+ thread = Thread(target = query_dns, args = (dns_queries,))
+ thread.start()
+ threads.append(thread)
+
+for thread in threads:
+ thread.join()
+
cursor.close()
connection.close()