refactor core modules, integrate network stats
This commit is contained in:
17
dbs.py
17
dbs.py
@@ -46,6 +46,16 @@ def _migrate_content_hash_column(sqlite):
|
||||
sqlite.commit()
|
||||
|
||||
|
||||
def _migrate_geolocation_columns(sqlite):
|
||||
"""Add latitude/longitude columns for precise proxy mapping."""
|
||||
try:
|
||||
sqlite.execute('SELECT latitude FROM proxylist LIMIT 1')
|
||||
except Exception:
|
||||
sqlite.execute('ALTER TABLE proxylist ADD COLUMN latitude REAL')
|
||||
sqlite.execute('ALTER TABLE proxylist ADD COLUMN longitude REAL')
|
||||
sqlite.commit()
|
||||
|
||||
|
||||
def compute_proxy_list_hash(proxies):
|
||||
"""Compute MD5 hash of sorted proxy list for change detection.
|
||||
|
||||
@@ -267,11 +277,14 @@ def create_table_if_not_exists(sqlite, dbname):
|
||||
latency_samples INT DEFAULT 0,
|
||||
anonymity TEXT,
|
||||
exit_ip TEXT,
|
||||
asn INT)""")
|
||||
asn INT,
|
||||
latitude REAL,
|
||||
longitude REAL)""")
|
||||
# Migration: add columns to existing databases (must run before creating indexes)
|
||||
_migrate_latency_columns(sqlite)
|
||||
_migrate_anonymity_columns(sqlite)
|
||||
_migrate_asn_column(sqlite)
|
||||
_migrate_geolocation_columns(sqlite)
|
||||
# Indexes for common query patterns
|
||||
sqlite.execute('CREATE INDEX IF NOT EXISTS idx_proxylist_failed ON proxylist(failed)')
|
||||
sqlite.execute('CREATE INDEX IF NOT EXISTS idx_proxylist_tested ON proxylist(tested)')
|
||||
@@ -360,7 +373,7 @@ def insert_proxies(proxydb, proxies, url):
|
||||
else:
|
||||
addr, proto = p, None
|
||||
ip, port = addr.split(':')
|
||||
rows.append((timestamp, addr, ip, port, proto, 3, 0, 0, 0, 0, 0))
|
||||
rows.append((timestamp, addr, ip, port, proto, 1, 0, 0, 0, 0, 0))
|
||||
proxydb.executemany(
|
||||
'INSERT OR IGNORE INTO proxylist '
|
||||
'(added,proxy,ip,port,proto,failed,tested,success_count,total_duration,mitm,consecutive_success) '
|
||||
|
||||
Reference in New Issue
Block a user