- Proof of Work challenge using random quotes
- Configurable difficulty levels
- Rate limiting and connection limiting
- Worker pool for controlled concurrency
- Proper connection handling
- Timeouts to prevent hanging connections
- Nonce tracking with window expiration
- Graceful shutdown
- Comprehensive test coverage
- Docker support
- Prometheus metrics for monitoring
- Using SHA256 with a nonce-based challenge
- The server generates a random quote and a target (currently set to 2)
- The client must find a nonce that, when combined with the quote and timestamp, produces a hash starting with the target
- This is computationally intensive but verifiable quickly
- The difficulty can be adjusted by changing the number of zeros in the target
.
├── cmd/ # Main application entry points
│ ├── client/ # Client application
│ └── server/ # Server application
├── internal/ # Private application code
│ ├── client/ # Client implementation
│ └── server/ # Server implementation
│ ├── service/ # Server services
│ │ ├── connection_manager.go # Connection handling and timeouts
│ │ ├── pow_service.go # Proof of Work service
│ │ └── quote_service.go # Quote service
│ └── handler.go # Main server handler
├── pkg/ # Public libraries
│ ├── backoff/ # Backoff queue implementation
│ ├── config/ # Configuration handling
│ ├── connlimit/ # Connection limiting
│ ├── metrics/ # Prometheus metrics
│ ├── nonce/ # Nonce tracking
│ ├── pow/ # Proof of Work implementation
│ ├── quotes/ # Quotes storage and retrieval
│ ├── ratelimit/ # Rate limiting
│ └── workerpool/ # Worker pool implementation
├── config/ # Configuration files
├── vendor/ # Dependencies
├── docker-compose.yml # Docker Compose configuration
├── client.Dockerfile # Client Dockerfile
└── server.Dockerfile # Server Dockerfile
The server exposes the following Prometheus metrics:
server_active_connections
- Number of active connectionsserver_total_connections
- Total number of connections
server_pow_challenges_generated
- Number of PoW challenges generatedserver_pow_challenges_verified
- Number of PoW challenges verifiedserver_pow_verification_failures
- Number of PoW verification failures
server_rate_limit_hits
- Number of rate limit hits
server_worker_pool_size
- Current size of the worker poolserver_worker_pool_queue_size
- Current size of the worker pool queue
server_response_time_seconds
- Response time in seconds (histogram)
git clone https://github.com/clevertechru/server_pow.git
cd server_pow
docker compose up --build
go test ./...
golangci-lint run ./...
# Adjust difficulty by changing number of zeros
CHALLENGE_DIFFICULTY=2
# default server host and port
HOST=0.0.0.0
PORT=8080
# quotes configuration file path
QUOTES_CONFIG_PATH=/path/to/quotes.yml
#default pow server host and port
SERVER_HOST=server
SERVER_PORT=8080
# default delay of requests
REQUESTS_DELAY_MS=100
The server uses a YAML file to store quotes. Example format:
quotes:
- "Quote 1"
- "Quote 2"
- "Quote 3"
- Go 1.24 or later required
- Docker and Docker Compose for containerized deployment
- golangci-lint for code quality checks