Skip to main content

Zero-config DDoS protection for Bittensor miners via Cloudflare Tunnel

Project description

djinn-tunnel-shield

Zero-config DDoS protection for Bittensor miners via Cloudflare Tunnel.

Install

pip install djinn-tunnel-shield

Miner (3 lines)

from djinn_tunnel_shield import MinerShield

shield = MinerShield(wallet, subtensor, netuid, port=8422)
asyncio.create_task(shield.run())

# In your health endpoint, include: {"tunnel_url": shield.tunnel_url}

Without CLOUDFLARE_TOKEN: emergency quick tunnel activates only when DDoS is detected (validator pings go silent). Logs a warning to set up a permanent tunnel.

With CLOUDFLARE_TOKEN: permanent named tunnel, stable URL, fully TOS-compliant.

Validator (3 lines)

from djinn_tunnel_shield import ShieldResolver

resolver = ShieldResolver(wallet=wallet)

# In health check, after parsing response:
resolver.cache_from_health(uid, health_data)

# When connecting to a miner:
for url in resolver.urls(uid, ip, port, "/health"):
    try:
        resp = await client.get(url)
        resolver.record_success(uid)
        break
    except Exception:
        resolver.record_failure(uid)

The resolver tries direct IP first. After consecutive failures, it switches to the cached tunnel URL. Periodically probes direct IP to detect recovery.

How it works

  1. Miner starts a Cloudflare Tunnel (quick or named)
  2. Tunnel URL is encrypted per-validator (ECIES) and committed on-chain
  3. Validators decrypt the URL and cache it
  4. On direct-IP failure (DDoS), validators route through the tunnel
  5. Cloudflare absorbs the volumetric attack; miner stays reachable

Configuration

from djinn_tunnel_shield import ShieldConfig

config = ShieldConfig(
    expected_ping_interval=12.0,  # seconds between validator pings
    min_missed_pings=5,           # consecutive misses before DDoS detection
    recovery_cooldown=300.0,      # seconds of stable pings before deactivating
    recommit_interval=3600.0,     # re-commit URL on-chain every hour
    direct_failure_threshold=2,   # switch to tunnel after N direct-IP failures
    direct_probe_interval=300.0,  # probe direct IP every 5 min while in tunnel mode
)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djinn_tunnel_shield-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djinn_tunnel_shield-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file djinn_tunnel_shield-0.1.0.tar.gz.

File metadata

  • Download URL: djinn_tunnel_shield-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for djinn_tunnel_shield-0.1.0.tar.gz
Algorithm Hash digest
SHA256 709ba53855209fd88de3f3c1be4d57a9571a145dcffdc4b14df58e1dc924a04f
MD5 de689d1d4cff5c83c3b282ebd881e4d4
BLAKE2b-256 c3236a50d1cde19139be3630de26164a2dc85d5e6984ae409a7b7f32cdb98c95

See more details on using hashes here.

File details

Details for the file djinn_tunnel_shield-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djinn_tunnel_shield-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3acb357336b0264814ccc1e8ece5165433b7c6a2a7efaac394273d0e82684c65
MD5 f9885d6db8f8651ad9459bf74c1316d0
BLAKE2b-256 464b0fe1db3a362f6725932538d3c86bd21c3b1820d62096770fb5785aa31fcf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page