A TCP server implementation protected from DDoS attacks using a Proof of Work (PoW) challenge-response protocol. After successfully solving the PoW challenge, the server sends a random quote from a collection.
-
Client-Server Interaction:
- Client connects and requests a quote
- Server sends a PoW challenge
- Client solves the challenge (finds a nonce that produces a hash with required leading zeros)
- Server verifies the solution and sends a quote if valid
-
Proof of Work Implementation:
- Uses SHA-256 hashing algorithm
- Challenge includes random data and timestamp
- Solution requires finding a nonce that produces a hash with N leading zeros
- Current difficulty is set to 6 leading zeros (can be adjusted in
internal/pow/pow.go) - Higher difficulty values require more computational work:
// internal/pow/pow.go const ( Difficulty = 6 // Increase this value for harder challenges )
-
DDoS Protection:
- Each quote request requires significant computational work
- Timestamp in challenge prevents replay attacks
- CPU-intensive but memory-efficient
- Easy to verify but time-consuming to solve
- Go 1.23 or higher
- Make
- Download and install Go
- Download and install Make
- Use
make buildto build the project - Use
make run-allto run the server and client
- Install Go 1.23 or higher
- Use
make buildto build the project - Use
make run-allto run the server and client