Minimal TCP challenge-response server that uses Proof of Work (PoW) to defend against DDoS attacks. After successful PoW validation, the server responds with a quote of wisdom.
-
The server sends a random challenge (16-byte hex) and a difficulty value.
-
The client brute-forces an 8-byte nonce so that:
SHA256(SHA256(challenge || nonce))starts with a number of zero hex nibbles equal to the difficulty.
-
Once verified, the server replies with a quote. Otherwise, an error.
The algorithm is double SHA-256 (like Bitcoin), chosen for its simplicity and speed. Difficulty is defined by the number of leading zero hex nibbles.
make run-server
make run-clientmake docker-build-server
make docker-build-client
make docker-run-server PORT=5050 DIFFICULTY=6
make docker-run-client PORT=5050