Added better keepalive

This commit is contained in:
Dionysus 2025-03-26 01:21:20 -04:00
parent 656bd50e47
commit 9e76ed0684
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
6 changed files with 26 additions and 18 deletions

View File

@ -39,8 +39,6 @@ czds [-h] [-u USERNAME] [-p PASSWORD] [-z] [-c CONCURRENCY] [-d] [-k] [-r] [-s]
###### Zone Options
| `-z`, `--zones` | Download zone files | |
| `-c`, `--concurrency` | Number of concurrent downloads | `3` |
| `-d`, `--decompress` | Decompress zone files after download | |
| `-k`, `--keep` | Keep original gzip files after decompression | |
###### Report Options
| `-r`, `--report` | Download the zone stats report | |

View File

@ -2,10 +2,7 @@
# ICANN API for the Centralized Zones Data Service - developed by acidvegas (https://git.acid.vegas/czds)
# czds/__init__.py
from .client import CZDS
__version__ = '1.3.3'
__version__ = '1.3.4'
__author__ = 'acidvegas'
__email__ = 'acid.vegas@acid.vegas'
__github__ = 'https://github.com/acidvegas/czds'

View File

@ -10,11 +10,6 @@ import os
from .client import CZDS
from dotenv import load_dotenv
load_dotenv()
async def main():
'''Entry point for the command line interface'''

View File

@ -44,8 +44,21 @@ class CZDS:
self.username = username
self.password = password
# Set the session with longer timeouts
self.session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=None, connect=60, sock_connect=60, sock_read=60))
# Configure TCP keepalive
connector = aiohttp.TCPConnector(
keepalive_timeout=300, # Keep connections alive for 5 minutes
force_close=False, # Don't force close connections
enable_cleanup_closed=True, # Cleanup closed connections
ttl_dns_cache=300, # Cache DNS results for 5 minutes
)
# Set the session with longer timeouts and keepalive
self.session = aiohttp.ClientSession(
connector=connector,
timeout=aiohttp.ClientTimeout(total=None, connect=60, sock_connect=60, sock_read=None),
headers={'Connection': 'keep-alive'},
raise_for_status=True
)
# Placeholder for the headers after authentication
self.headers = None
@ -171,15 +184,22 @@ class CZDS:
tld_name = url.split('/')[-1].split('.')[0] # Extract TLD from URL
max_retries = 10 # Maximum number of retries for failed downloads
retry_delay = 5 # Delay between retries in seconds
timeout = aiohttp.ClientTimeout(total=None, connect=60, sock_connect=60, sock_read=None)
# Headers for better connection stability
download_headers = {
**self.headers,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=600', # 10 minutes
'Accept-Encoding': 'gzip'
}
# Start the attempt loop
for attempt in range(max_retries):
try:
logging.info(f'Starting download of {tld_name} zone file{" (attempt " + str(attempt + 1) + ")" if attempt > 0 else ""}')
# Send the request to the API
async with self.session.get(url, headers=self.headers, timeout=timeout) as response:
async with self.session.get(url, headers=download_headers) as response:
# Check if the request was successful
if response.status != 200:
logging.error(f'Failed to download {tld_name}: {response.status} {await response.text()}')

View File

@ -51,8 +51,6 @@ async def gzip_decompress(filepath: str, cleanup: bool = True):
# Write the chunk to the output file
await f_out.write(chunk)
# Update the progress bar
pbar.update(len(chunk))
# Get the decompressed size of the file

View File

@ -11,7 +11,7 @@ with open('README.md', 'r', encoding='utf-8') as fh:
setup(
name='czds-api',
version='1.3.3',
version='1.3.4',
author='acidvegas',
author_email='acid.vegas@acid.vegas',
description='ICANN API for the Centralized Zones Data Service',