https://github.com/robotomize/powwy
A toy implementation of a tcp server with its own simple text protocol with content protection from ddos attacks using proof of work.
https://github.com/robotomize/powwy
ddos golang hashcash hashcash-algorithm proof-of-work tcp
Last synced: about 1 month ago
JSON representation
A toy implementation of a tcp server with its own simple text protocol with content protection from ddos attacks using proof of work.
- Host: GitHub
- URL: https://github.com/robotomize/powwy
- Owner: robotomize
- License: mit
- Created: 2022-05-28T22:52:49.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-23T09:05:29.000Z (about 2 years ago)
- Last Synced: 2025-03-30T03:22:36.309Z (about 2 months ago)
- Topics: ddos, golang, hashcash, hashcash-algorithm, proof-of-work, tcp
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Powwy
[](https://codebeat.co/projects/github-com-robotomize-powwy-main)
[](https://github.com/robotomize/powwy/actions)
[](https://github.com/robotomize/powwy/blob/master/LICENSE)A toy implementation of a tcp server with its own simple text protocol with content protection from ddos attacks using
proof of work.The project consists of a tcp server and a tcp client.
The server offers to solve the proof of work problem to the client in order to access the content.
The client receives the problem, solves it, and receives a quote from Words of wisdom.## Requirements
* go1.18
* golangci-lint## Usage
Install from local go toolkit [Go 1.18](https://go.dev/dl/)
### Go install
```sh
go install ./cmd/powwy-srv
go install ./cmd/powwy-cli
```### Make build
```sh
make build
```### Docker install
```sh
sudo docker build -it powwy-cli -f ./docker/client.Dockerfile .
sudo docker build -it powwy -f ./docker/server.Dockerfile .sudo docker run powwy --net=host -p 3333:3333
sudo docker run powwy-cli -a localhost:3333 -d // infinite loopsudo docker run powwy-cli compute
```From docker hub
```sh
docker pull robotomize/powwy-cli:latest
docker pull robotomize/powwy-srv:latest
```### Docker compose
```sh
sudo docker-compose up
```## CLI powwy
Find a solution to the HashCash header problem
```sh
powwy-cli compute
``````sh
Usage: powwy-cli computeUsage:
compute [flags]
Flags:
-h, --help help for computeGlobal Flags:
-d, --duration duration -d 10s (default -1ns)
-i, --iterations int -i 1000000 (default -1)
-w, --workers int -w 4 (default 2)
```Connect to powwy server and fetch quotes
```sh
powwly-cli -a localhost:3333
``````sh
Usage:Available Commands:
completion Generate the autocompletion script for the specified shell
compute Usage: powwy-cli compute
help Help about any commandFlags:
-a, --addr string -a localhost:3333 (default "localhost:3333")
-s, --dos -s true
-d, --duration duration -d 10s (default -1ns)
-h, --help help for this command
-i, --iterations int -i 1000000 (default -1)
-n, --network string -n tcp4 (default "tcp")
-w, --workers int -w 4 (default 2)Use " [command] --help" for more information about a command.
```## Proof of work
### HashCash
The [http://www.hashcash.org/](HashCash) algorithm was chosen to implement the proof of work mechanism
Pros:
* Easy to find description
* Easy to implementCons:
* Difficult to adjust the difficulty of the task### Implementing the header
*HashCashHeader: version:difficult:expiredAt:subject:alg:nonce:counter*
* version - version of the header, represented by an int
* difficult - the complexity of the useful work, expressed in the number of first zeros of the hash
* expiredAt - the lifetime of the task, after which it is considered invalid
* subject - defines the name of the resource or other identifying information, such as a user ID or its ip address
* alg - determines what type of hash to use
* nonce - is a randomly generated set of bytes
* counter - Current counter value*Example 1:20:1665396610:localhost:sha-512:hVscDCMZcS1WYg==:BQAAAAAAAAA=*
### Merkle tree
[Merkle in ethereum](https://blog.ethereum.org/2015/11/15/merkling-in-ethereum/)
Pros:
Works great for decentralized applicationsCons:
Not very suitable for the implementation of client-server applications## Protocol
powwy uses a simple command text protocol
List of available commands
```go
// Proto specification tags
const (
REQ = "REQ" // REQ - request challenge
RES = "RES" // RES - request resource
RSV = "RSV" // RSV - response with payload
OK = "OK" // OK - command accepted
ERR = "ERR" // ERR - command err
DISC = "DISC" // DISC - initialize close connection
)```
Format:
` |`
or
``Example:
```sh
---------------------------------------------------------------------------------------------------------------
UNKNOWN_COMMAND
ERR 18 |command wrong
---------------------------------------------------------------------------------------------------------------
REQ
ERR 21 |internal server error
---------------------------------------------------------------------------------------------------------------
REQ
RSR 62 |
1:5:1665396610:localhost:sha-256:vZOxuoIgixP+hw==:AAAAAAAAAAA=
---------------------------------------------------------------------------------------------------------------
RES 62 |
1:5:1665396610:localhost:sha-256:vZOxuoIgixP+hw==:FxUQAAAAAAA=
RST 139 |Voice is not just the sound that comes from your throat, but the feelings that come from your words.
― Jennifer Donnelly, A Northern Light
---------------------------------------------------------------------------------------------------------------
DISC
OK
---------------------------------------------------------------------------------------------------------------
```