sequenceDiagram
Client->>Server: ask\n
Server->>Client: uuid\n
loop nonce calc
Client->>Client:
end
Client->>Server: answer:uuid:nonce\n
Server->>Client: random quote\n
- The client wants to get a quote. It sends an "ask" message
- The server generates a uuid, stores it in the internal storage with a timestamp and sends it to the client.
- The client tries to find a nonce for this uuid which is suitable for pow algorithm.
- The client sends answer to the server with uuid and nonce
- The server checks:
- if this uuid exists in internal storage;
- if it has already been used;
- if it has expired;
- if it a suitable nonce,
- If all is ok server sends quote to the client.
For this task I took a Hashcash algorithm used by Bitcoin.
The main reason: it was interesting for me personally)
-
Run tests:
make test -
Start client - server interaction in docker:
docker-runand loot at you terminal.
- This example uses hardcoded 24 target bits for Hashcash algorithm.
- If client can't find a proper nonce it fails in 10 seconds
- Every task expires on 2 seconds
- For this task I used a habr article