To prevent a DDOS attack, we use the Hashcash algorithm for confirming the work of the client. The client will not be able to make a DDoS attack, since for each request it needs to calculate the hash, which takes time.
- Client generates a message
- Client appends a sequence to the message and hashes it using SHA256 until the first 20 bits of the hash are zero. This takes about a second. Because it is necessary to sort out several million hashes
- When the hash is solved, the client sends a message to the server.
- The server calculates a hash from the message. If the hash has the first 20 bits set to zero, then the message is considered valid.
- The server writes the hash from the message to the store so that the client cannot use it a second time
- The server returns a response to the client
docker-compose -f docker-compose.server.yml build
docker-compose -f docker-compose.server.yml up
docker-compose -f docker-compose.client.yml build
docker-compose -f docker-compose.client.yml up