From 13ac9c44a73314ec5cfa10f19b3aa86fe803b6b5 Mon Sep 17 00:00:00 2001 From: Benjamin Arntzen Date: Mon, 4 Mar 2024 04:35:53 +0000 Subject: [PATCH] Add accelerated deployment initial script --- accelerated_deployment/docker/Dockerfile | 13 ++++++ accelerated_deployment/docker/getenr.sh | 50 ++++++++++++++++++++++++ debug_image/dns_loop.py | 7 ++-- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 accelerated_deployment/docker/Dockerfile create mode 100644 accelerated_deployment/docker/getenr.sh diff --git a/accelerated_deployment/docker/Dockerfile b/accelerated_deployment/docker/Dockerfile new file mode 100644 index 0000000..5a1eefa --- /dev/null +++ b/accelerated_deployment/docker/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:latest + +# Update the package repository and install bind-tools and wget +RUN apk update && \ + apk add bind-tools wget bash && \ + # Create /app directory + mkdir /app + +ADD getenr.sh /app/getenr.sh + +RUN chmod +x /app/getenr.sh + +ENTRYPOINT ["/app/getenr.sh"] diff --git a/accelerated_deployment/docker/getenr.sh b/accelerated_deployment/docker/getenr.sh new file mode 100644 index 0000000..4d784bb --- /dev/null +++ b/accelerated_deployment/docker/getenr.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Find the IPv4 IPs of "zerotesting-service.zerotesting" using nslookup +readarray -t pod_ips < <(nslookup zerotesting-service.zerotesting | awk '/^Address: / { print $2 }' | head -n 3) + +# Prepare the directory for ENR data +mkdir -p /etc/enr +enr_file="/etc/enr/enr.env" +> "$enr_file" # Clear the file to start fresh + +# Function to validate ENR +validate_enr() { + if [[ $1 =~ ^enr:- ]]; then + return 0 # Valid + else + return 1 # Invalid + fi +} + +# Counter for valid ENRs +valid_enr_count=0 + +# Get and validate the ENR data from up to three IPs +for pod_ip in "${pod_ips[@]}"; do + echo "Querying IP: $pod_ip" + enr=$(wget -O - --post-data='{"jsonrpc":"2.0","method":"get_waku_v2_debug_v1_info","params":[],"id":1}' --header='Content-Type:application/json' "$pod_ip:8545" 2>/dev/null | sed -n 's/.*"enrUri":"\([^"]*\)".*/\1/p') + + # Validate the ENR + validate_enr "$enr" + if [ $? -eq 0 ]; then + # Save the valid ENR to the file + ((valid_enr_count++)) + echo "export ENR$valid_enr_count='$enr'" >> "$enr_file" + if [ $valid_enr_count -eq 3 ]; then + break # Exit loop after 3 valid ENRs + fi + else + echo "Invalid ENR data received from IP $pod_ip" + fi +done + +# Check if we got at least one valid ENR +if [ $valid_enr_count -eq 0 ]; then + echo "No valid ENR data received from any IPs" + exit 1 +fi + +# Output for debugging +echo "ENR data saved successfully:" +cat "$enr_file" diff --git a/debug_image/dns_loop.py b/debug_image/dns_loop.py index 798b714..ef46b9e 100644 --- a/debug_image/dns_loop.py +++ b/debug_image/dns_loop.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import socket +import time import argparse from itertools import cycle @@ -39,15 +40,14 @@ def main(dns_servers): # Print counts every iteration to show progress print(f"Processed {i + 1}/{args.nodes} hostnames, Success: {success_count}, Failures: {fail_count}") - - # Print totals after every N attempts - print(f"Round completed. Total successful DNS lookups: {success_count}, Total failed DNS lookups: {fail_count}") + time.sleep(args.delay) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Perform DNS lookups with specified target DNS server or system default") parser.add_argument("--target", help="IP address of the target DNS server", nargs='*', default=[]) parser.add_argument("--accept-input", action="store_true", help="Accept a list of IP addresses from user input") parser.add_argument("--nodes", help="Number of nodes to resolve", type=int, default=1000) + parser.add_argument("--delay", help="Delay in seconds", type=float, default=0.4) args = parser.parse_args() dns_servers = args.target @@ -60,3 +60,4 @@ if __name__ == "__main__": print("No specific DNS servers provided; using system default DNS settings.") main(dns_servers) +